English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. System (https://eab.abime.net/forumdisplay.php?f=113)
-   -   Turning HUNK_SYMBOL offsets into pointers (https://eab.abime.net/showthread.php?t=110133)

BSzili 19 March 2022 07:28

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?

hooverphonique 19 March 2022 11:36

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.

BSzili 19 March 2022 12:04

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.

a/b 19 March 2022 12:11

Quote:

Originally Posted by hooverphonique (Post 1536841)
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.

Pedantic correction: bcpl pointer. So, for each hunk:
address-8 = hunk size in bytes
address-4 = bcpl pointer to next hunk (0 if none)

BSzili 19 March 2022 12:15

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.

BSzili 30 July 2022 19:00

I ended up finishing the dynamic linking library, now it's up on GitHub:
https://github.com/BSzili/libdl-hunk/

bebbo 31 July 2022 11:33

There are libraries and there is https://aminet.net/dev/gg/a2ixlibrary-2.1.lha

/shrug

BSzili 31 July 2022 14:25

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.


All times are GMT +2. The time now is 01:55.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.06146 seconds with 11 queries