Click here to Skip to main content
15,886,731 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
/*      
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 );
                }
        }
}
/* ---------------------------------------------------------- */
Posted
Comments
Duncan Edwards Jones 22-Jan-16 11:18am    
is this actually a question? Maybe add some explanation of why you do this and post it up as a tip?
rgayoso 22-Jan-16 17:11pm    
Sybase SQL Anywhere database runtime engine crashes every few hours on Win64. Running with Windbg, they use a usual (old) way of moving a string, using the es and fs segments. Of course on Win32 both point to the same flat 32 bit space. This is ok and runs fine on all Windows 32 bit (XP, 7 and 10). But on 64-bit (under Microsoft's wow64 layer), the fs gets modified from time to time. If I increase the CPU load with other applications, the frequency raises a lot. I believe this is a Microsoft bug. If an interrupt or task switch pauses my thread, when resuming all my CPU registers should be the same. Note that I am not calling any Win32 API, that may modify a register if docs say so.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900