19 March 2022, 07:28 | #1 |
old chunk of coal
Join Date: Nov 2011
Location: Hungary
Posts: 1,289
|
Turning HUNK_SYMBOL offsets into pointers
I'd like to create a simple DLL/SO-like dynamic linking system to aid some future ports. There are existing implementations (Quake2 DLLs from Hyperion, FPSE plugins, etc.), but they are inconvenient as you have to manually create a symbol table with every exported symbol. I decided to use the HUNK_SYMBOL in unstripped executables to avoid doing double work. The "DLL" files will be regular executables started from shell, so in case of HUNK_CODE I was able to add the offsets to BADDR(cli_Module)+4 of the CommandLineInterface struct to get the address of functions. Is there a way to do the same for HUNK_DATA and HUNK_BSS the get the addresses of global variables?
|
19 March 2022, 11:36 | #2 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Did you try traversing the hunk list? Each hunk (when loaded through LoadSeg, et.al.) has a size and pointer to next hunk placed just before the actual hunk data.
|
19 March 2022, 12:04 | #3 |
old chunk of coal
Join Date: Nov 2011
Location: Hungary
Posts: 1,289
|
I see, so the first longword I skipped was the size of the hunk. I forgot to mention, but the global variables seem to have a lower memory address than BADDR(cli_Module), so going forward in the list wouldn't help in this case.
edit: I missed the part about the pointer, I'll check this out. |
19 March 2022, 12:11 | #4 | |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Quote:
address-8 = hunk size in bytes address-4 = bcpl pointer to next hunk (0 if none) |
|
19 March 2022, 12:15 | #5 |
old chunk of coal
Join Date: Nov 2011
Location: Hungary
Posts: 1,289
|
Thanks for the help! It seems like the first longword stored at BADDR(cli_Module) is indeed a BPTR to the next hunk which is lower than the address of the global variables. Now I just have to figure out which ones comes after which and I'm set.
|
30 July 2022, 19:00 | #6 |
old chunk of coal
Join Date: Nov 2011
Location: Hungary
Posts: 1,289
|
I ended up finishing the dynamic linking library, now it's up on GitHub:
https://github.com/BSzili/libdl-hunk/ |
31 July 2022, 11:33 | #7 |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
|
31 July 2022, 14:25 | #8 |
old chunk of coal
Join Date: Nov 2011
Location: Hungary
Posts: 1,289
|
I saw this, but it's for ixemul.library only. My solution is independent from the C library and only uses exec and dos functions. The program and libraries can be linked different C-libraries as long as they don't pass incompatible stdio handles, or try to free memory allocated by the other.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Loading base address of custom hw registers and using offsets | burma-shave | Coders. Asm / Hardware | 9 | 29 May 2021 01:29 |
Structures offsets | kamelito | Coders. System | 16 | 24 January 2021 07:26 |
Library offsets | BippyM | Coders. General | 17 | 29 April 2020 03:32 |
turning laptop to an Amiga | Arkas | New to Emulation or Amiga scene | 3 | 25 December 2017 22:10 |
Dat File Offsets? | Brakus | Coders. General | 2 | 29 June 2008 00:51 |
|
|