[fpc-devel] ifdef'd ThreadVar code in win/systhrd.inc

Sven Barth pascaldragon at googlemail.com
Sun Oct 3 11:37:18 CEST 2010


Hello together!

While I looked for a solution for the bug report about external threads 
on Windows ( http://bugs.freepascal.org/view.php?id=17300 ), I found the 
following code in SysRelocateThreadVar in rtl/win/systhrd.inc:

==== begin ====

{$ifdef dummy}
         { it least in the on windows 7 x64, this still doesn't not 
work, fs:(0x2c) is
           self referencing on this system (FK)
           MVC: It also does not work on Windows Vista 32-bit, Home 
Premium, SP 1. Results in a crash}
         asm
           movl TLSKey,%edx
           movl %fs:(0x2c),%eax
           orl  %eax,%eax
           jnz  .LAddressInEAX
           { this works on Windows 7, but I don't know if it works on 
other OSes (FK) }
           movl %fs:(0x18),%eax
           movl 0xe10(%eax,%edx,4),%eax
           jmp  .LToDataIndex
           .LAddressInEAX:
            movl (%eax,%edx,4),%eax
           .LToDataIndex:
           movl %eax,dataindex
         end;
         if DataIndex=nil then
           begin
             errorsave:=GetLastError;
             SysAllocateThreadVars;
             DataIndex:=TlsGetValue(tlskey);
             SetLastError(errorsave);
           end;
{$else win32}

==== end ====

According to http://en.wikipedia.org/wiki/X86-64#Windows 64-bit Windows 
uses GS instead of FS for the TIB. This might be the reason that the 
code doesn't work on 64-bit Windows.

Regards,
Sven



More information about the fpc-devel mailing list