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

Florian Klämpfl florian at freepascal.org
Sun Oct 3 13:59:17 CEST 2010


Am 03.10.2010 11:37, schrieb Sven Barth:
> 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.

Also for 32 bit programs? The code above is only used by 32 bit programs.



More information about the fpc-devel mailing list