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?
|
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.
|
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. |
Quote:
address-8 = hunk size in bytes address-4 = bcpl pointer to next hunk (0 if none) |
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.
|
I ended up finishing the dynamic linking library, now it's up on GitHub:
https://github.com/BSzili/libdl-hunk/ |
|
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.