3 comments

[ 2.9 ms ] story [ 18.4 ms ] thread
This mmaps (with PROT_EXEC) the file then returns an offset void pointer from the mmap. You then cast the pointer to a function pointer.
I wonder if this would even be possible to do with non-relocatable code. You'd probably have to use a child process that was smart about where it was executing in memory, then manually load the various code and data segments. Could be an interesting project.
Yeah, I think something like dlopen/dlsym, but stand-alone, and supporting ELF/PE32+/Mach-O binaries (both objects and binaries, shared objects, PIC and non-PIE) on any OS/architecture could be very useful. Even foreign support (i.e. load x86 obj on MIPS), as it could be used by emulation engines.