浏览代码

Avoid the need to import/export _FPC_SysInstance and _FPC_TlsKey.

inc/systemh.inc, TEntryInformation:
  + add new, optional field Platform which a target can use to provide additional information through the entry information
win/sysosh.inc:
  + new type TPlatformEntryInformation which contains a pointer to the SysInstance and TlsKey variables of the program/library module
win32/sysinit.inc:
  * provide storage for SysInstance instead of importing it
  * provide storage for TlsKey
  * set up SysInstanceAddr and TlsKey of the entry information accordingly
win32/system.pp:
  - don't export SysInstance anymore
  * initialize Platform.SysInstanceAddr and Platform.TlsKeyAddr
  * use Platform.SysInstanceAddr^ instead of SysInstance to store/retrieve the current instance value
win/systhrd.inc:
  + in case of indirect entry information add a new property TlsKey that uses EntryInformation.Platform.TlsKeyAddr
  - disable TLSKey variable if indirect entry information is used
win/systlsdir.inc:
  * in case of indirect entry information we use an absolute to the new TlsKeyVar of sysinit.inc instead of an imported variable

git-svn-id: branches/svenbarth/packages@29009 -
svenbarth 10 年之前
父节点
当前提交
274e43d7e0
共有 6 个文件被更改,包括 42 次插入5 次删除
  1. 3 0
      rtl/inc/systemh.inc
  2. 8 0
      rtl/win/sysosh.inc
  3. 17 0
      rtl/win/systhrd.inc
  4. 1 1
      rtl/win/systlsdir.inc
  5. 6 1
      rtl/win32/sysinit.inc
  6. 7 3
      rtl/win32/system.pp

+ 3 - 0
rtl/inc/systemh.inc

@@ -565,6 +565,9 @@ type
     asm_exit : Procedure;stdcall;
     PascalMain : Procedure;stdcall;
     valgrind_used : boolean;
+{$ifdef HAS_ENTRYINFORMATION_PLATFORM}
+    platform: TPlatformEntryInformation;
+{$endif HAS_ENTRYINFORMATION_PLATFORM}
   end;
 
 

+ 8 - 0
rtl/win/sysosh.inc

@@ -86,6 +86,14 @@ type
     hStdError : THandle;
   end;
 
+  {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+  {$define HAS_ENTRYINFORMATION_PLATFORM}
+  TPlatformEntryInformation = record
+    TlsKeyAddr: PDWord;
+    SysInstanceAddr: PLongInt;
+  end;
+  {$endif}
+
 { package stuff }
 type
   PLibModule = ^TLibModule;

+ 17 - 0
rtl/win/systhrd.inc

@@ -91,10 +91,27 @@ var
                              Threadvar support
 *****************************************************************************}
 
+    {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+    function GetTLSKey: DWord; inline;
+      begin
+        Result:=EntryInformation.Platform.TLSKeyAddr^;
+      end;
+
+    procedure SetTLSKey(value : DWord); inline;
+      begin
+        EntryInformation.Platform.TLSKeyAddr^:=value;
+      end;
+    {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
+
     var
       // public names are used by heaptrc unit
       threadvarblocksize : dword; public name '_FPC_TlsSize';
+      {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+      property TLSKey : DWord read GetTLSKey write SetTLSKey;
+      {$else}
       TLSKey : DWord = $ffffffff; public name '_FPC_TlsKey';
+      {$endif}
+
 
     var
       MainThreadIdWin32 : DWORD;

+ 1 - 1
rtl/win/systlsdir.inc

@@ -28,7 +28,7 @@ Const
   DLL_THREAD_DETACH = 3;
 
 var
-   TlsKey : dword; external name '_FPC_TlsKey';
+   TlsKey : dword {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}absolute TlsKeyVar;{$else}; external name '_FPC_TlsKey';{$endif}
 
 type
   TTlsDirectory=packed record

+ 6 - 1
rtl/win32/sysinit.inc

@@ -15,7 +15,8 @@
  **********************************************************************}
 
    var
-      SysInstance : Longint;external name '_FPC_SysInstance';
+      SysInstance : Longint; public name '_FPC_SysInstance'; //external name '_FPC_SysInstance';
+      TlsKeyVar: DWord = $ffffffff; public name '_FPC_TlsKey';
 
       InitFinalTable : record end; external name 'INITFINAL';
       ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
@@ -65,6 +66,10 @@
         asm_exit : @asm_exit;
         PascalMain : @PascalMain;
         valgrind_used : false;
+        Platform: (
+            TlsKeyAddr : @TlsKeyVar;
+            SysInstanceAddr : @SysInstance;
+          );
         );
 
 

+ 7 - 3
rtl/win32/system.pp

@@ -109,7 +109,7 @@ Const
 implementation
 
 var
-  SysInstance : Longint;public name '_FPC_SysInstance';
+  //SysInstance : Longint;public name '_FPC_SysInstance';
   FPCResStrInitTables : Pointer;public name '_FPC_ResStrInitTables';
   FPCResourceStringTables : Pointer;public name '_FPC_ResourceStringTables';
 const
@@ -124,6 +124,10 @@ const
     asm_exit : nil;
     PascalMain : nil;
     valgrind_used : false;
+    Platform : (
+        TlsKeyAddr : nil;
+        SysInstanceAddr : nil;
+      );
     );
 
 {$ifdef FPC_USE_WIN32_SEH}
@@ -659,9 +663,9 @@ begin
   GetStartupInfo(@startupinfo);
   { some misc Win32 stuff }
   if not IsLibrary then
-    SysInstance:=getmodulehandle(nil);
+    EntryInformation.Platform.SysInstanceAddr^:=getmodulehandle(nil);
 
-  MainInstance:=SysInstance;
+  MainInstance:=EntryInformation.Platform.SysInstanceAddr^;
 
   { pass dummy value }
   StackLength := CheckInitialStkLen($1000000);