问题
I'm working on a project that will require me to load some data into memory at memory addresses determined at runtime and then load an ELF binary into the same address space. I know I can compile the ELF as position-independent, but how can I allocate my memory block and then load and run the binary without overwriting the memory block or moving into a different address space?
回答1:
Exec replaces the entire memory space and I don't think there's much you can do about that. But maybe you could use shared memory to share the data between your old and new processes?
回答2:
Can you compile the ELF binary as a shared library and then dynamically link it into your original process? The dynamic linker should respect exisiting malloc/mmap memory allocations and not step on them.
来源:https://stackoverflow.com/questions/13107143/load-elf-binary-around-an-arbitrary-initialized-memory-block