Browse Source

Adjust non-Windows resources to work with indirect main information as well.

rtl/inc/systemh.inc, TEntryInformation:
  + new cross platform field ResLocation which stores the pointer to the resources
rtl/inc/intres.inc:
  * change the type of ResHeader from PResHdr to PPResHdr (and adjust code that uses it accordingly; Note: the first dereferencing is assumed to be always valid!)
  * adjust declaration of ResHeader depending on whether indirect main information is used or not
rtl/darwin/sysinit.pas & rtl/linux/si_impl.inc:
  * pass the location of the resources through SysInitEntryInformation
rtl/bsd/system.pp & rtl/linux/system.pp:
  + new public variable FPCResLocation which is setup by SysEntry
rtl/win32/sysinit.inc:
  * initialize ResLocation of SysInitEntryInformation as Nil
rtl/win32/system.pp:
  * initialize ResLocation of EntryInformation as Nil

git-svn-id: branches/svenbarth/packages@32491 -
svenbarth 9 years ago
parent
commit
5a4a36158c

+ 2 - 0
rtl/bsd/system.pp

@@ -306,6 +306,7 @@ end;
 var
   FPCResStrInitTables : Pointer;public name '_FPC_ResStrInitTables';
   FPCResourceStringTables : Pointer;public name '_FPC_ResourceStringTables';
+  FPCResLocation : Pointer;public name '_FPC_ResLocation';
 
 procedure SysEntry(constref info: TEntryInformation);[public,alias:'FPC_SysEntry'];
 begin
@@ -316,6 +317,7 @@ begin
   initialstklen := EntryInformation.Platform.stklen;
   FPCResStrInitTables := EntryInformation.ResStrInitTables;
   FPCResourceStringTables := EntryInformation.ResourceStringTables;
+  FPCResLocation := EntryInformation.ResLocation;
 {$ifdef cpui386}
   Set8087CW(Default8087CW);
 {$endif cpui386}

+ 2 - 0
rtl/darwin/sysinit.pas

@@ -32,6 +32,7 @@ var
   {$ifdef FPC_HAS_RESSTRINITS}
   ResStrInitTables : record end; external name 'FPC_RESSTRINITTABLES';
   {$endif}
+  ResLocation: record end; external name 'FPC_RESLOCATION';
   ResourceStringTables : record end; external name 'FPC_RESOURCESTRINGTABLES';
   StkLen: SizeUInt; external name '__stklen';
 
@@ -48,6 +49,7 @@ const
 {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
     WideInitTables : @WideInitTables;
 {$endif}
+    ResLocation : @ResLocation;
     asm_exit : nil;
     PascalMain : @PascalMain;
     valgrind_used : false;

+ 35 - 24
rtl/inc/intres.inc

@@ -28,12 +28,23 @@ type
     handles     : PPtrUint;     //pointer to handles
   end;
   PResHdr = ^TResHdr;
+  PPResHdr = ^PResHdr;
+
+{$if defined(win32) or (defined(darwin) and not defined(ver2_6))}
+{$define FPC_HAS_INDIRECT_MAIN_INFORMATION}
+{$endif}
 
 var
 {$ifdef FPC_HAS_WINLIKERESOURCES}
-  ResHeader : PResHdr; external name 'FPC_RESLOCATION';
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+  ResHeader : PPResHdr; external name '_FPC_ResLocation';
+{$else}
+  ResHeaderVar : PResHdr; external name 'FPC_RESLOCATION';
+  ResHeader : PPResHdr = @ResHeaderVar;
+{$endif}
 {$else}
-  ResHeader : PResHdr= nil;
+  ResHeaderVar : PResHdr = nil;
+  ResHeader : PPResHdr= @ResHeaderVar;
 {$endif}
 
 (*****************************************************************************
@@ -139,8 +150,8 @@ function InternalFindResource(ResourceName, ResourceType: PChar):
  PResInfoNode;
 begin
   InternalFindResource:=nil;
-  if ResHeader=nil then exit;
-  InternalFindResource:=ResHeader^.rootptr;
+  if ResHeader^=nil then exit;
+  InternalFindResource:=ResHeader^^.rootptr;
 
   InternalFindResource:=BinSearchRes(InternalFindResource,ResourceType);
   if InternalFindResource<>nil then
@@ -179,9 +190,9 @@ var ptr : PResInfoNode;
     tot, i : integer;
 begin
   IntEnumResourceTypes:=False;
-  if ResHeader=nil then exit;
-  tot:=ResHeader^.rootptr^.ncounthandle+ResHeader^.rootptr^.idcountsize;
-  ptr:=ResHeader^.rootptr^.subptr;
+  if ResHeader^=nil then exit;
+  tot:=ResHeader^^.rootptr^.ncounthandle+ResHeader^^.rootptr^.idcountsize;
+  ptr:=ResHeader^^.rootptr^.subptr;
   IntEnumResourceTypes:=true;
   i:=0;
   while i<tot do
@@ -196,8 +207,8 @@ var ptr : PResInfoNode;
     tot, i : integer;
 begin
   IntEnumResourceNames:=False;
-  if ResHeader=nil then exit;
-  ptr:=ResHeader^.rootptr;
+  if ResHeader^=nil then exit;
+  ptr:=ResHeader^^.rootptr;
 
   ptr:=BinSearchRes(ptr,ResourceType);
   if ptr=nil then exit;
@@ -244,9 +255,9 @@ begin
   ptr:=ptr^.subptr;
   if ptr^.ncounthandle=0 then
   begin
-    ResHeader^.handles[ResHeader^.usedhandles]:=PtrUint(ptr);
-    inc(ResHeader^.usedhandles);
-    ptr^.ncounthandle:=ResHeader^.usedhandles;
+    ResHeader^^.handles[ResHeader^^.usedhandles]:=PtrUint(ptr);
+    inc(ResHeader^^.usedhandles);
+    ptr^.ncounthandle:=ResHeader^^.usedhandles;
   end;
   IntFindResource:=ptr^.ncounthandle;
 end;
@@ -278,9 +289,9 @@ begin
 
   if ptr^.ncounthandle=0 then
   begin
-    ResHeader^.handles[ResHeader^.usedhandles]:=PtrUint(ptr);
-    inc(ResHeader^.usedhandles);
-    ptr^.ncounthandle:=ResHeader^.usedhandles;
+    ResHeader^^.handles[ResHeader^^.usedhandles]:=PtrUint(ptr);
+    inc(ResHeader^^.usedhandles);
+    ptr^.ncounthandle:=ResHeader^^.usedhandles;
   end;
   IntFindResourceEx:=ptr^.ncounthandle;
 end;
@@ -288,34 +299,34 @@ end;
 Function IntLoadResource(ModuleHandle: TFPResourceHMODULE; ResHandle: TFPResourceHandle): TFPResourceHGLOBAL;
 begin
   IntLoadResource:=0;
-  if ResHeader=nil then exit;
-  if (ResHandle<=0) or (ResHandle>ResHeader^.usedhandles) then exit;
-  IntLoadResource:=TFPResourceHGLOBAL(PResInfoNode(ResHeader^.handles[ResHandle-1])^.subptr);
+  if ResHeader^=nil then exit;
+  if (ResHandle<=0) or (ResHandle>ResHeader^^.usedhandles) then exit;
+  IntLoadResource:=TFPResourceHGLOBAL(PResInfoNode(ResHeader^^.handles[ResHandle-1])^.subptr);
 end;
 
 Function IntSizeofResource(ModuleHandle: TFPResourceHMODULE; ResHandle: TFPResourceHandle): LongWord;
 begin
   IntSizeofResource:=0;
-  if ResHeader=nil then exit;
-  if (ResHandle<=0) or (ResHandle>ResHeader^.usedhandles) then exit;
-  IntSizeofResource:=PResInfoNode(ResHeader^.handles[ResHandle-1])^.idcountsize;
+  if ResHeader^=nil then exit;
+  if (ResHandle<=0) or (ResHandle>ResHeader^^.usedhandles) then exit;
+  IntSizeofResource:=PResInfoNode(ResHeader^^.handles[ResHandle-1])^.idcountsize;
 end;
 
 Function IntLockResource(ResData: TFPResourceHGLOBAL): Pointer;
 begin
   IntLockResource:=Nil;
-  if ResHeader=nil then exit;
+  if ResHeader^=nil then exit;
   IntLockResource:=Pointer(ResData);
 end;
 
 Function IntUnlockResource(ResData: TFPResourceHGLOBAL): LongBool;
 begin
-  IntUnlockResource:=(ResHeader<>nil);
+  IntUnlockResource:=(ResHeader^<>nil);
 end;
 
 Function IntFreeResource(ResData: TFPResourceHGLOBAL): LongBool;
 begin
-  IntFreeResource:=(ResHeader<>nil);
+  IntFreeResource:=(ResHeader^<>nil);
 end;
 
 const

+ 1 - 0
rtl/inc/systemh.inc

@@ -562,6 +562,7 @@ type
 {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
     WideInitTables : Pointer;
 {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
+    ResLocation: Pointer;
     asm_exit : Procedure;stdcall;
     PascalMain : Procedure;
     valgrind_used : boolean;

+ 2 - 0
rtl/linux/si_impl.inc

@@ -27,6 +27,7 @@ var
   ResStrInitTables : record end; external name 'FPC_RESSTRINITTABLES';
   {$endif}
   ResourceStringTables : record end; external name 'FPC_RESOURCESTRINGTABLES';
+  ResLocation : Pointer; external name 'FPC_RESLOCATION';
 
 const
   SysInitEntryInformation : TEntryInformation = (
@@ -41,6 +42,7 @@ const
 {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
     WideInitTables : @WideInitTables;
 {$endif}
+    ResLocation : @ResLocation;
     asm_exit : nil;
     PascalMain : @PascalMain;
     valgrind_used : false;

+ 2 - 0
rtl/linux/system.pp

@@ -90,6 +90,7 @@ var
 var
   FPCResStrInitTables : Pointer;public name '_FPC_ResStrInitTables';
   FPCResourceStringTables : Pointer;public name '_FPC_ResourceStringTables';
+  FPCResLocation : Pointer;public name '_FPC_ResLocation';
   initialstkptr : Pointer;
 
 procedure SysEntry(constref info: TEntryInformation);[public,alias:'FPC_SysEntry'];
@@ -101,6 +102,7 @@ begin
   initialstkptr := EntryInformation.Platform.stkptr;
   FPCResStrInitTables := EntryInformation.ResStrInitTables;
   FPCResourceStringTables := EntryInformation.ResourceStringTables;
+  FPCResLocation := EntryInformation.ResLocation;
 {$ifdef cpui386}
   Set8087CW(Default8087CW);
 {$endif cpui386}

+ 1 - 0
rtl/win32/sysinit.inc

@@ -63,6 +63,7 @@
 {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
         WideInitTables : @WideInitTables;
 {$endif}
+        ResLocation : nil;
         asm_exit : @asm_exit;
         PascalMain : @PascalMain;
         valgrind_used : false;

+ 1 - 0
rtl/win32/system.pp

@@ -121,6 +121,7 @@ const
 {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
     WideInitTables : nil;
 {$endif}
+    ResLocation : nil;
     asm_exit : nil;
     PascalMain : nil;
     valgrind_used : false;