Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-10

ifdef'd ThreadVar code in win/systhrd.inc

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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.

Regards,
Sven

Reply by email

Florian Klämpfl
to Sven Barth
Sven Barth wrote 43 lines
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.

Reply by email

Sven Barth
to Florian Klämpfl
Florian Klämpfl wrote 46 lines
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.

No, not for 32 bit programs. -.-

Note to self: Study foreign code more intensively.

Regards,
Sven

Reply by email