Browse Source

Adjust SysInstance so that it is correctly handled with the indirect entry information on Win32

win/sysosh.inc, TEntryInformationOS:
  + new field SysInstance that will hold the address to the main program's SysInstance variable
win32/system.pp:
  * rename SysInstance to FPCSysInstance and make it a PLongInt
  * OsSetupEntryInformation: setup FPCSysInstance
  * adjust initialization of SysInstance to use FPCSysInstance instead
win32/sysinit.inc:
  * SysInstance is no longer an external
  * initialize the OS.SysInstance field of EntryInformation
win64/system.pp:
  * add a FPCSysInstance that's a pointer to SysInstance
win/winres.inc:
  * SysInstance is now a pointer and has the same name on both Win32 and Win64

git-svn-id: trunk@33107 -
svenbarth 9 years ago
parent
commit
af53fcb48c
5 changed files with 12 additions and 7 deletions
  1. 1 0
      rtl/win/sysosh.inc
  2. 2 2
      rtl/win/winres.inc
  3. 3 1
      rtl/win32/sysinit.inc
  4. 4 3
      rtl/win32/system.pp
  5. 2 1
      rtl/win64/system.pp

+ 1 - 0
rtl/win/sysosh.inc

@@ -54,6 +54,7 @@ type
   TEntryInformationOS = record
   TEntryInformationOS = record
     asm_exit : Procedure;stdcall;
     asm_exit : Procedure;stdcall;
     TlsKeyAddr : PDWord;
     TlsKeyAddr : PDWord;
+    SysInstance: PLongInt;
   end;
   end;
 {$endif Win32}
 {$endif Win32}
 
 

+ 2 - 2
rtl/win/winres.inc

@@ -9,11 +9,11 @@ function SysLockResource(hResData:TFPResourceHGLOBAL):Pointer; stdcall; external
 function SysFreeResource(hResData:TFPResourceHGLOBAL):Longbool; stdcall; external 'kernel32' name 'FreeResource';
 function SysFreeResource(hResData:TFPResourceHGLOBAL):Longbool; stdcall; external 'kernel32' name 'FreeResource';
 
 
 var
 var
-  SysInstance : PtrUInt;external name {$ifdef win64} 'SysInstance' {$else} '_FPC_SysInstance' {$endif} ;
+  SysInstance : PPtrUInt;external name '_FPC_SysInstance';
 
 
 Function IntHINSTANCE : TFPResourceHMODULE;
 Function IntHINSTANCE : TFPResourceHMODULE;
 begin
 begin
-  IntHINSTANCE:=sysinstance;
+  IntHINSTANCE:=sysinstance^;
 end;
 end;
 
 
 Function IntEnumResourceTypes(ModuleHandle : TFPResourceHMODULE; EnumFunc : EnumResTypeProc; lParam : PtrInt) : LongBool;
 Function IntEnumResourceTypes(ModuleHandle : TFPResourceHMODULE; EnumFunc : EnumResTypeProc; lParam : PtrInt) : LongBool;

+ 3 - 1
rtl/win32/sysinit.inc

@@ -15,7 +15,7 @@
  **********************************************************************}
  **********************************************************************}
 
 
    var
    var
-      SysInstance : Longint;external name '_FPC_SysInstance';
+      SysInstance : LongInt;
       TlsKeyVar: DWord = $ffffffff;
       TlsKeyVar: DWord = $ffffffff;
 
 
       InitFinalTable : record end; external name 'INITFINAL';
       InitFinalTable : record end; external name 'INITFINAL';
@@ -67,6 +67,7 @@
         OS : (
         OS : (
           asm_exit : @asm_exit;
           asm_exit : @asm_exit;
           TlsKeyAddr : @TlsKeyVar;
           TlsKeyAddr : @TlsKeyVar;
+          SysInstance : @SysInstance;
           );
           );
         );
         );
 
 
@@ -81,6 +82,7 @@
         EntryInformation.WideInitTables:=@WideInitTables;
         EntryInformation.WideInitTables:=@WideInitTables;
         EntryInformation.OS.asm_exit:=@asm_exit;
         EntryInformation.OS.asm_exit:=@asm_exit;
         EntryInformation.OS.TlsKeyAddr:=@TlsKeyVar;
         EntryInformation.OS.TlsKeyAddr:=@TlsKeyVar;
+        EntryInformation.OS.SysInstance:=@SysInstance;
         EntryInformation.PascalMain:=@PascalMain;}
         EntryInformation.PascalMain:=@PascalMain;}
         SysInitEntryInformation.valgrind_used:=valgrind_used;
         SysInitEntryInformation.valgrind_used:=valgrind_used;
       end;
       end;

+ 4 - 3
rtl/win32/system.pp

@@ -111,7 +111,7 @@ Const
 implementation
 implementation
 
 
 var
 var
-  SysInstance : Longint;public name '_FPC_SysInstance';
+  FPCSysInstance : PLongint;public name '_FPC_SysInstance';
 
 
 {$define FPC_SYSTEM_HAS_OSSETUPENTRYINFORMATION}
 {$define FPC_SYSTEM_HAS_OSSETUPENTRYINFORMATION}
 procedure OsSetupEntryInformation(const info: TEntryInformation); forward;
 procedure OsSetupEntryInformation(const info: TEntryInformation); forward;
@@ -136,6 +136,7 @@ end;
 procedure OsSetupEntryInformation(const info: TEntryInformation);
 procedure OsSetupEntryInformation(const info: TEntryInformation);
 begin
 begin
   TlsKey := info.OS.TlsKeyAddr;
   TlsKey := info.OS.TlsKeyAddr;
+  FPCSysInstance := info.OS.SysInstance;
 end;
 end;
 
 
 {*****************************************************************************
 {*****************************************************************************
@@ -650,9 +651,9 @@ begin
   GetStartupInfo(@startupinfo);
   GetStartupInfo(@startupinfo);
   { some misc Win32 stuff }
   { some misc Win32 stuff }
   if not IsLibrary then
   if not IsLibrary then
-    SysInstance:=getmodulehandle(nil);
+    FPCSysInstance^:=getmodulehandle(nil);
 
 
-  MainInstance:=SysInstance;
+  MainInstance:=FPCSysInstance^;
 
 
   { pass dummy value }
   { pass dummy value }
   StackLength := CheckInitialStkLen($1000000);
   StackLength := CheckInitialStkLen($1000000);

+ 2 - 1
rtl/win64/system.pp

@@ -106,7 +106,8 @@ implementation
 {$asmmode att}
 {$asmmode att}
 
 
 var
 var
-  SysInstance : qword;public;
+  SysInstance : qword;
+  FPCSysInstance: PQWord = @SysInstance; public name '_FPC_SysInstance';
 
 
 {$ifdef FPC_USE_WIN64_SEH}
 {$ifdef FPC_USE_WIN64_SEH}
 function main_wrapper(arg: Pointer; proc: Pointer): ptrint; assembler; nostackframe;
 function main_wrapper(arg: Pointer; proc: Pointer): ptrint; assembler; nostackframe;