Browse Source

Really fix threadvar handling. The pointer to the threadvar tables needs to be known during InitSystemThreads() thus we need to supply the entry information in Exec_tls_callback().

win32/system.pp:
  + new procedure InitEntryInformation() to only set the EntryInformation variable
win/systlsdir.inc:
  - no need to set TlsKey
  * call InitEntryInformation() with the available entry information

git-svn-id: branches/svenbarth/packages@31913 -
svenbarth 10 years ago
parent
commit
4316175a3e
2 changed files with 15 additions and 5 deletions
  1. 10 5
      rtl/win/systlsdir.inc
  2. 5 0
      rtl/win32/system.pp

+ 10 - 5
rtl/win/systlsdir.inc

@@ -41,8 +41,10 @@ type
 
 function TlsGetValue(dwTlsIndex : DWord) : pointer; stdcall;
   external 'kernel32' name 'TlsGetValue';
-function TlsAlloc : DWord; stdcall;
-  external 'kernel32' name 'TlsAlloc';
+
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+procedure InitEntryInformation(const info: TEntryInformation); external name '_FPC_InitEntryInformation';
+{$endif}
 
 procedure InitSystemThreads; external name '_FPC_InitSystemThreads';
 procedure SysAllocateThreadVars; external name '_FPC_SysAllocateThreadVars';
@@ -69,9 +71,12 @@ procedure Exec_Tls_callback(Handle : pointer; reason : Dword; Reserved : pointer
          and the EntryInformation is a constant which sholud prevent troubles }
        DLL_PROCESS_ATTACH:
          begin
-           {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
-           TlsKey:=TlsAlloc;
-           {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
+           {$if defined(FPC_HAS_INDIRECT_MAIN_INFORMATION) and defined(FPC_INSSIDE_SYSINIT)}
+           { since this procedure is called before SetupEntryInformation and thus
+             before EXE_Entry we need to setup the entry information here so that
+             the threadvar handling can be correctly initialized }
+           InitEntryInformation(SysInitEntryInformation);
+           {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION and FPC_INSSIDE_SYSINIT}
            InitHeap;
            InitSystemThreads;
          end;

+ 5 - 0
rtl/win32/system.pp

@@ -194,6 +194,11 @@ begin
   ExitProcess(exitcode);
 end;
 
+procedure InitEntryInformation(const info : TEntryInformation);[public,alias:'_FPC_InitEntryInformation'];
+begin
+  EntryInformation:=info;
+end;
+
 var
   { value of the stack segment
     to check if the call stack can be written on exceptions }