Browse Source

Adjust the Windows RTL for correct startup with packages.

inc/systemh.inc:
  + TEntryInformation: also store the reference to the resource string, resource string init and WideString init tables
win32/system.pp:
  * export the pointers to the resource string table and the resource string init table from the system unit instead of importing the record references
  - remove externals to PascalMain, ThreadvarTablesTable and asm_exit
  * initialize EntryInformation with Nils
  * Exe_entry: initialize the exported references
win/syswin.inc:
  * move the structures for the WideString init tables further up and change WStrInitTablesTable from an external record to a public pointer
  * Dll_entry: initialize the exported references
win32/sysinit.inc:
  * fill in the entry information for the resource string table, the resource string init table and the wide string init table
objpas/objpas.pp:
  * change the resource string table and resource string init table to correctly import the pointers provided by the system unit (only on systems with indirect entry information (only Win32 currently) for now)

git-svn-id: branches/svenbarth/packages@28857 -
svenbarth 10 years ago
parent
commit
767ebbf627
5 changed files with 99 additions and 52 deletions
  1. 5 0
      rtl/inc/systemh.inc
  2. 45 24
      rtl/objpas/objpas.pp
  3. 22 20
      rtl/win/syswin.inc
  4. 13 0
      rtl/win32/sysinit.inc
  5. 14 8
      rtl/win32/system.pp

+ 5 - 0
rtl/inc/systemh.inc

@@ -557,6 +557,11 @@ type
   TEntryInformation = record
   TEntryInformation = record
     InitFinalTable : Pointer;
     InitFinalTable : Pointer;
     ThreadvarTablesTable : Pointer;
     ThreadvarTablesTable : Pointer;
+    ResourceStringTables : Pointer;
+    ResStrInitTables : Pointer;
+{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+    WideInitTables : Pointer;
+{$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
     asm_exit : Procedure;stdcall;
     asm_exit : Procedure;stdcall;
     PascalMain : Procedure;stdcall;
     PascalMain : Procedure;stdcall;
     valgrind_used : boolean;
     valgrind_used : boolean;

+ 45 - 24
rtl/objpas/objpas.pp

@@ -309,6 +309,11 @@ Type
        TableEnd   : PResourceStringRecord;
        TableEnd   : PResourceStringRecord;
      end;
      end;
    end;
    end;
+   PResourceStringTableList = ^TResourceStringTableList;
+
+{$ifdef win32}
+  {$define FPC_HAS_INDIRECT_MAIN_INFORMATION}
+{$endif}
 
 
 { Support for string constants initialized with resourcestrings }
 { Support for string constants initialized with resourcestrings }
 {$ifdef FPC_HAS_RESSTRINITS}
 {$ifdef FPC_HAS_RESSTRINITS}
@@ -322,18 +327,24 @@ Type
      Count: {$ifdef VER2_6}longint{$else}sizeint{$endif};
      Count: {$ifdef VER2_6}longint{$else}sizeint{$endif};
      Tables: packed array[1..{$ifdef cpu16}8191{$else cpu16}32767{$endif cpu16}] of PResStrInitEntry;
      Tables: packed array[1..{$ifdef cpu16}8191{$else cpu16}32767{$endif cpu16}] of PResStrInitEntry;
    end;
    end;
+   PResStrInitTable = ^TResStrInitTable;
 
 
 var
 var
-  ResStrInitTable : TResStrInitTable; external name 'FPC_RESSTRINITTABLES';
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+  ResStrInitTable : PResStrInitTable; external name '_FPC_ResStrInitTables';
+{$else}
+  ResStrInitTableVar : TResStrInitTable; external name 'FPC_RESSTRINITTABLES';
+  ResStrInitTable : PResStrInitTable = @ResStrInitTableVar;
+{$endif}
 
 
 procedure UpdateResourceStringRefs;
 procedure UpdateResourceStringRefs;
 var
 var
   i: integer;
   i: integer;
   ptable: PResStrInitEntry;
   ptable: PResStrInitEntry;
 begin
 begin
-  for i:=1 to ResStrInitTable.Count do
+  for i:=1 to ResStrInitTable^.Count do
     begin
     begin
-      ptable:=ResStrInitTable.Tables[i];
+      ptable:=ResStrInitTable^.Tables[i];
       while Assigned(ptable^.Addr) do
       while Assigned(ptable^.Addr) do
         begin
         begin
           AnsiString(ptable^.Addr^):=ptable^.Data^.CurrentValue;
           AnsiString(ptable^.Addr^):=ptable^.Data^.CurrentValue;
@@ -343,8 +354,13 @@ begin
 end;
 end;
 {$endif FPC_HAS_RESSTRINITS}
 {$endif FPC_HAS_RESSTRINITS}
 
 
-Var
-  ResourceStringTable : TResourceStringTableList; External Name 'FPC_RESOURCESTRINGTABLES';
+var
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+  ResourceStringTable : PResourceStringTableList; external name '_FPC_ResourceStringTables';
+{$else}
+  ResourceStringTableVar : TResourceStringTableList; External Name 'FPC_RESOURCESTRINGTABLES';
+  ResourceStringTable : PResourceStringTableList = @ResourceStringTable;
+{$endif}
 
 
 Procedure SetResourceStrings (SetFunction :  TResourceIterator;arg:pointer);
 Procedure SetResourceStrings (SetFunction :  TResourceIterator;arg:pointer);
 Var
 Var
@@ -352,7 +368,7 @@ Var
   i      : integer;
   i      : integer;
   s      : AnsiString;
   s      : AnsiString;
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
     begin
     begin
       For i:=0 to Count-1 do
       For i:=0 to Count-1 do
         begin
         begin
@@ -381,7 +397,7 @@ Var
   s,
   s,
   UpUnitName : AnsiString;
   UpUnitName : AnsiString;
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
     begin
     begin
       UpUnitName:=UpCase(UnitName);
       UpUnitName:=UpCase(UnitName);
       For i:=0 to Count-1 do
       For i:=0 to Count-1 do
@@ -413,7 +429,7 @@ Var
   ResStr : PResourceStringRecord;
   ResStr : PResourceStringRecord;
   i      : integer;
   i      : integer;
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
     begin
     begin
       For i:=0 to Count-1 do
       For i:=0 to Count-1 do
         begin
         begin
@@ -435,7 +451,7 @@ Var
   ResStr : PResourceStringRecord;
   ResStr : PResourceStringRecord;
   i      : integer;
   i      : integer;
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
     begin
     begin
       For i:=0 to Count-1 do
       For i:=0 to Count-1 do
         begin
         begin
@@ -473,8 +489,13 @@ Type
      Tables : Array[Word] of PResourceStringTable;
      Tables : Array[Word] of PResourceStringTable;
      end;
      end;
 
 
-Var
-  ResourceStringTable : TResourceTablelist; External Name 'FPC_RESOURCESTRINGTABLES';
+var
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+  ResourceStringTable : PResourceTableList; external name '_FPC_ResourceStringTables';
+{$else}
+  ResourceStringTableVar : TResourceTablelist; External Name 'FPC_RESOURCESTRINGTABLES';
+  ResourceStringTable : PResourceTableList = @ResourceStringTableVar;
+{$endif}
 
 
 Function GetResourceString(Const TheTable: TResourceStringTable;Index : longint) : AnsiString;[Public,Alias : 'FPC_GETRESOURCESTRING'];
 Function GetResourceString(Const TheTable: TResourceStringTable;Index : longint) : AnsiString;[Public,Alias : 'FPC_GETRESOURCESTRING'];
 begin
 begin
@@ -490,7 +511,7 @@ Procedure SetResourceStrings (SetFunction :  TResourceIterator;arg:pointer);
 Var I,J : longint;
 Var I,J : longint;
 
 
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
     For I:=0 to Count-1 do
     For I:=0 to Count-1 do
       With Tables[I]^ do
       With Tables[I]^ do
          For J:=0 to Count-1 do
          For J:=0 to Count-1 do
@@ -510,7 +531,7 @@ Procedure ResetResourceTables;
 Var I,J : longint;
 Var I,J : longint;
 
 
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
   For I:=0 to Count-1 do
   For I:=0 to Count-1 do
     With Tables[I]^ do
     With Tables[I]^ do
         For J:=0 to Count-1 do
         For J:=0 to Count-1 do
@@ -523,7 +544,7 @@ Procedure FinalizeResourceTables;
 Var I,J : longint;
 Var I,J : longint;
 
 
 begin
 begin
-  With ResourceStringTable do
+  With ResourceStringTable^ do
   For I:=0 to Count-1 do
   For I:=0 to Count-1 do
     With Tables[I]^ do
     With Tables[I]^ do
         For J:=0 to Count-1 do
         For J:=0 to Count-1 do
@@ -534,18 +555,18 @@ end;
 Function ResourceStringTableCount : Longint;
 Function ResourceStringTableCount : Longint;
 
 
 begin
 begin
-  Result:=ResourceStringTable.Count;
+  Result:=ResourceStringTable^.Count;
 end;
 end;
 
 
 Function CheckTableIndex (Index: longint) : Boolean;
 Function CheckTableIndex (Index: longint) : Boolean;
 begin
 begin
-  Result:=(Index<ResourceStringTable.Count) and (Index>=0)
+  Result:=(Index<ResourceStringTable^.Count) and (Index>=0)
 end;
 end;
 
 
 Function CheckStringIndex (TableIndex,Index: longint) : Boolean;
 Function CheckStringIndex (TableIndex,Index: longint) : Boolean;
 begin
 begin
-  Result:=(TableIndex<ResourceStringTable.Count) and (TableIndex>=0) and
-          (Index<ResourceStringTable.Tables[TableIndex]^.Count) and (Index>=0)
+  Result:=(TableIndex<ResourceStringTable^.Count) and (TableIndex>=0) and
+          (Index<ResourceStringTable^.Tables[TableIndex]^.Count) and (Index>=0)
 end;
 end;
 
 
 Function ResourceStringCount(TableIndex : longint) : longint;
 Function ResourceStringCount(TableIndex : longint) : longint;
@@ -554,7 +575,7 @@ begin
   If not CheckTableIndex(TableIndex) then
   If not CheckTableIndex(TableIndex) then
      Result:=-1
      Result:=-1
   else
   else
-    Result:=ResourceStringTable.Tables[TableIndex]^.Count;
+    Result:=ResourceStringTable^.Tables[TableIndex]^.Count;
 end;
 end;
 
 
 Function GetResourceStringName(TableIndex,StringIndex : Longint) : Ansistring;
 Function GetResourceStringName(TableIndex,StringIndex : Longint) : Ansistring;
@@ -563,7 +584,7 @@ begin
   If not CheckStringIndex(Tableindex,StringIndex) then
   If not CheckStringIndex(Tableindex,StringIndex) then
     Result:=''
     Result:=''
   else
   else
-    result:=ResourceStringTable.Tables[TableIndex]^.ResRec[StringIndex].Name;
+    result:=ResourceStringTable^.Tables[TableIndex]^.ResRec[StringIndex].Name;
 end;
 end;
 
 
 Function GetResourceStringHash(TableIndex,StringIndex : Longint) : Longint;
 Function GetResourceStringHash(TableIndex,StringIndex : Longint) : Longint;
@@ -572,7 +593,7 @@ begin
   If not CheckStringIndex(Tableindex,StringIndex) then
   If not CheckStringIndex(Tableindex,StringIndex) then
     Result:=0
     Result:=0
   else
   else
-    result:=ResourceStringTable.Tables[TableIndex]^.ResRec[StringIndex].HashValue;
+    result:=ResourceStringTable^.Tables[TableIndex]^.ResRec[StringIndex].HashValue;
 end;
 end;
 
 
 Function GetResourceStringDefaultValue(TableIndex,StringIndex : Longint) : AnsiString;
 Function GetResourceStringDefaultValue(TableIndex,StringIndex : Longint) : AnsiString;
@@ -581,7 +602,7 @@ begin
   If not CheckStringIndex(Tableindex,StringIndex) then
   If not CheckStringIndex(Tableindex,StringIndex) then
     Result:=''
     Result:=''
   else
   else
-    result:=ResourceStringTable.Tables[TableIndex]^.ResRec[StringIndex].DefaultValue;
+    result:=ResourceStringTable^.Tables[TableIndex]^.ResRec[StringIndex].DefaultValue;
 end;
 end;
 
 
 Function GetResourceStringCurrentValue(TableIndex,StringIndex : Longint) : AnsiString;
 Function GetResourceStringCurrentValue(TableIndex,StringIndex : Longint) : AnsiString;
@@ -590,7 +611,7 @@ begin
   If not CheckStringIndex(Tableindex,StringIndex) then
   If not CheckStringIndex(Tableindex,StringIndex) then
     Result:=''
     Result:=''
   else
   else
-    result:=ResourceStringTable.Tables[TableIndex]^.ResRec[StringIndex].CurrentValue;
+    result:=ResourceStringTable^.Tables[TableIndex]^.ResRec[StringIndex].CurrentValue;
 end;
 end;
 
 
 Function SetResourceStringValue(TableIndex,StringIndex : longint; Value : Ansistring) : Boolean;
 Function SetResourceStringValue(TableIndex,StringIndex : longint; Value : Ansistring) : Boolean;
@@ -598,7 +619,7 @@ Function SetResourceStringValue(TableIndex,StringIndex : longint; Value : Ansist
 begin
 begin
   Result:=CheckStringIndex(Tableindex,StringIndex);
   Result:=CheckStringIndex(Tableindex,StringIndex);
   If Result then
   If Result then
-   ResourceStringTable.Tables[TableIndex]^.ResRec[StringIndex].CurrentValue:=Value;
+   ResourceStringTable^.Tables[TableIndex]^.ResRec[StringIndex].CurrentValue:=Value;
 end;
 end;
 
 
 {$endif RESSTRSECTIONS}
 {$endif RESSTRSECTIONS}

+ 22 - 20
rtl/win/syswin.inc

@@ -350,6 +350,23 @@ end;
   end;
   end;
 
 
 
 
+type
+  PWStrInitEntry = ^TWStrInitEntry;
+  TWStrInitEntry = record
+    addr: PPointer;
+    data: Pointer;
+  end;
+
+  PWStrInitTablesTable = ^TWStrInitTablesTable;
+  TWStrInitTablesTable = packed record
+    count  : {$ifdef VER2_6}longint{$else}sizeint{$endif};
+    tables : packed array [1..32767] of PWStrInitEntry;
+  end;
+
+{$if not(defined(VER2_2) or defined(VER2_4))}
+var
+  WStrInitTablesTable: PWStrInitTablesTable;
+{$endif}
 
 
 
 
 Var
 Var
@@ -360,6 +377,9 @@ function Dll_entry{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}(const info : TEntry
   begin
   begin
 {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
 {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
      EntryInformation:=info;
      EntryInformation:=info;
+     FPCResStrInitTables:=info.ResStrInitTables;
+     FPCResourceStringTables:=info.ResourceStringTables;
+     WStrInitTablesTable:=info.WideInitTables;
 {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
 {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
      IsLibrary:=true;
      IsLibrary:=true;
      DllInitState:=DLLreason;
      DllInitState:=DLLreason;
@@ -640,24 +660,6 @@ function Win32WideLower(const s : WideString) : WideString;
       CharLowerBuff(LPWSTR(result),length(result));
       CharLowerBuff(LPWSTR(result),length(result));
   end;
   end;
 
 
-type
-  PWStrInitEntry = ^TWStrInitEntry;
-  TWStrInitEntry = record
-    addr: PPointer;
-    data: Pointer;
-  end;
-
-  PWStrInitTablesTable = ^TWStrInitTablesTable;
-  TWStrInitTablesTable = packed record
-    count  : {$ifdef VER2_6}longint{$else}sizeint{$endif};
-    tables : packed array [1..32767] of PWStrInitEntry;
-  end;
-
-{$if not(defined(VER2_2) or defined(VER2_4))}
-var
-  WStrInitTablesTable: TWStrInitTablesTable; external name 'FPC_WIDEINITTABLES';
-{$endif}
-
 function GetACP:UINT; stdcall; external 'kernel32' name 'GetACP';
 function GetACP:UINT; stdcall; external 'kernel32' name 'GetACP';
 function GetConsoleCP:UINT; stdcall; external 'kernel32' name 'GetConsoleCP';
 function GetConsoleCP:UINT; stdcall; external 'kernel32' name 'GetConsoleCP';
 
 
@@ -680,9 +682,9 @@ procedure InitWin32Widestrings;
   begin
   begin
 {$if not(defined(VER2_2) or defined(VER2_4))}
 {$if not(defined(VER2_2) or defined(VER2_4))}
     { assign initial values to global Widestring typed consts }
     { assign initial values to global Widestring typed consts }
-    for i:=1 to WStrInitTablesTable.count do
+    for i:=1 to WStrInitTablesTable^.count do
       begin
       begin
-        ptable:=WStrInitTablesTable.tables[i];
+        ptable:=WStrInitTablesTable^.tables[i];
         while Assigned(ptable^.addr) do
         while Assigned(ptable^.addr) do
           begin
           begin
             fpc_widestr_assign(ptable^.addr^, ptable^.data);
             fpc_widestr_assign(ptable^.addr^, ptable^.data);

+ 13 - 0
rtl/win32/sysinit.inc

@@ -19,6 +19,9 @@
 
 
       InitFinalTable : record end; external name 'INITFINAL';
       InitFinalTable : record end; external name 'INITFINAL';
       ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
       ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
+      WideInitTables : record end; external name 'FPC_WIDEINITTABLES';
+      ResStrInitTables : record end; external name 'FPC_RESSTRINITTABLES';
+      ResourceStringTables : record end; external name 'FPC_RESOURCESTRINGTABLES';
       valgrind_used : boolean;external name '__fpc_valgrind';
       valgrind_used : boolean;external name '__fpc_valgrind';
 
 
 {$if defined(FPC_USE_TLS_DIRECTORY) or defined(FPC_SECTION_THREADVARS)}
 {$if defined(FPC_USE_TLS_DIRECTORY) or defined(FPC_SECTION_THREADVARS)}
@@ -48,6 +51,11 @@
       SysInitEntryInformation : TEntryInformation = (
       SysInitEntryInformation : TEntryInformation = (
         InitFinalTable : @InitFinalTable;
         InitFinalTable : @InitFinalTable;
         ThreadvarTablesTable : @ThreadvarTablesTable;
         ThreadvarTablesTable : @ThreadvarTablesTable;
+        ResourceStringTables : @ResourceStringTables;
+        ResStrInitTables : @ResStrInitTables;
+{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+        WideInitTables : @WideInitTables;
+{$endif}
         asm_exit : @asm_exit;
         asm_exit : @asm_exit;
         PascalMain : @PascalMain;
         PascalMain : @PascalMain;
         valgrind_used : false;
         valgrind_used : false;
@@ -59,6 +67,11 @@
         { valgind_used is the only thng that can change at startup
         { valgind_used is the only thng that can change at startup
         EntryInformation.InitFinalTable:=@InitFinalTable;
         EntryInformation.InitFinalTable:=@InitFinalTable;
         EntryInformation.ThreadvarTablesTable:=@ThreadvarTablesTable;
         EntryInformation.ThreadvarTablesTable:=@ThreadvarTablesTable;
+        ResourceStringTables:=@ResourceStringTables;
+        ResStrInitTables:=@ResStrInitTables;
+{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+        WideInitTables:=@WideInitTables;
+{$endif}
         EntryInformation.asm_exit:=@asm_exit;
         EntryInformation.asm_exit:=@asm_exit;
         EntryInformation.PascalMain:=@PascalMain;}
         EntryInformation.PascalMain:=@PascalMain;}
         SysInitEntryInformation.valgrind_used:=valgrind_used;
         SysInitEntryInformation.valgrind_used:=valgrind_used;

+ 14 - 8
rtl/win32/system.pp

@@ -110,16 +110,19 @@ implementation
 
 
 var
 var
   SysInstance : Longint;public name '_FPC_SysInstance';
   SysInstance : Longint;public name '_FPC_SysInstance';
-  InitFinalTable : record end; external name 'INITFINAL';
-  ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
-  procedure PascalMain;stdcall;external name 'PASCALMAIN';
-  procedure asm_exit;stdcall;external name 'asm_exit';
+  FPCResStrInitTables : Pointer;public name '_FPC_ResStrInitTables';
+  FPCResourceStringTables : Pointer;public name '_FPC_ResourceStringTables';
 const
 const
   EntryInformation : TEntryInformation = (
   EntryInformation : TEntryInformation = (
-    InitFinalTable : @InitFinalTable;
-    ThreadvarTablesTable : @ThreadvarTablesTable;
-    asm_exit : @asm_exit;
-    PascalMain : @PascalMain;
+    InitFinalTable : nil;
+    ThreadvarTablesTable : nil;
+    ResourceStringTables : nil;
+    ResStrInitTables : nil;
+{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+    WideInitTables : nil;
+{$endif}
+    asm_exit : nil;
+    PascalMain : nil;
     valgrind_used : false;
     valgrind_used : false;
     );
     );
 
 
@@ -197,6 +200,9 @@ procedure Exe_entry(const info : TEntryInformation);[public,alias:'_FPC_EXE_Entr
     xframe: TEXCEPTION_FRAME;
     xframe: TEXCEPTION_FRAME;
   begin
   begin
      EntryInformation:=info;
      EntryInformation:=info;
+     FPCResStrInitTables:=info.ResStrInitTables;
+     FPCResourceStringTables:=info.ResourceStringTables;
+     WStrInitTablesTable:=info.WideInitTables;
      IsLibrary:=false;
      IsLibrary:=false;
      { install the handlers for exe only ?
      { install the handlers for exe only ?
        or should we install them for DLL also ? (PM) }
        or should we install them for DLL also ? (PM) }