/* When the WoW64 scheduler does a context switch and then returns control to this test program, modifies the fs segment register. The frequency of this modification depends on the CPU load. I usually start 4 cmd prompts running on each any program that uses CPU. I start 4 of them to use the 4 cores on an i3 CPU. Win7_64 and Win10_64 have this problem. WinXP_32, Win7_32 and Win10_32 work ok. On this test program I copy ds to fs, and then read back the fs. If it is not the same as ds, I print an error. Every 10^7 loops I print the loop count. cl test_fs_seg.cpp */ #include <stdio.h> #include <windows.h> /* ---------------------------------------------------------- */ void main() { unsigned dds, ffs, i; // If I add this line, the bug frequency reduces a lot //SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL ); _asm { xor eax, eax mov ax, ds mov dds, eax }; for ( i = 0; i < 2000000000; ++i ) { _asm { push fs xor eax, eax mov ax, ds mov fs,ax mov ax, fs mov ffs, eax pop fs }; if ( ffs != dds ) { printf( "fs:%x ds:%x\n", ffs, dds ); } if ( (i % 10000000) == 0 ) { printf( "%d\n", i ); } } } /* ---------------------------------------------------------- */
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)