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
     InitFinalTable : Pointer;
     ThreadvarTablesTable : Pointer;
+    ResourceStringTables : Pointer;
+    ResStrInitTables : Pointer;
+{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+    WideInitTables : Pointer;
+{$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
     asm_exit : Procedure;stdcall;
     PascalMain : Procedure;stdcall;
     valgrind_used : boolean;

+ 45 - 24
rtl/objpas/objpas.pp

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

+ 22 - 20
rtl/win/syswin.inc

@@ -350,6 +350,23 @@ 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
@@ -360,6 +377,9 @@ function Dll_entry{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}(const info : TEntry
   begin
 {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
      EntryInformation:=info;
+     FPCResStrInitTables:=info.ResStrInitTables;
+     FPCResourceStringTables:=info.ResourceStringTables;
+     WStrInitTablesTable:=info.WideInitTables;
 {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
      IsLibrary:=true;
      DllInitState:=DLLreason;
@@ -640,24 +660,6 @@ function Win32WideLower(const s : WideString) : WideString;
       CharLowerBuff(LPWSTR(result),length(result));
   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 GetConsoleCP:UINT; stdcall; external 'kernel32' name 'GetConsoleCP';
 
@@ -680,9 +682,9 @@ procedure InitWin32Widestrings;
   begin
 {$if not(defined(VER2_2) or defined(VER2_4))}
     { assign initial values to global Widestring typed consts }
-    for i:=1 to WStrInitTablesTable.count do
+    for i:=1 to WStrInitTablesTable^.count do
       begin
-        ptable:=WStrInitTablesTable.tables[i];
+        ptable:=WStrInitTablesTable^.tables[i];
         while Assigned(ptable^.addr) do
           begin
             fpc_widestr_assign(ptable^.addr^, ptable^.data);

+ 13 - 0
rtl/win32/sysinit.inc

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

+ 14 - 8
rtl/win32/system.pp

@@ -110,16 +110,19 @@ implementation
 
 var
   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
   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;
     );
 
@@ -197,6 +200,9 @@ procedure Exe_entry(const info : TEntryInformation);[public,alias:'_FPC_EXE_Entr
     xframe: TEXCEPTION_FRAME;
   begin
      EntryInformation:=info;
+     FPCResStrInitTables:=info.ResStrInitTables;
+     FPCResourceStringTables:=info.ResourceStringTables;
+     WStrInitTablesTable:=info.WideInitTables;
      IsLibrary:=false;
      { install the handlers for exe only ?
        or should we install them for DLL also ? (PM) }