4 ms·
On a modern POSIX environment, you can hack together an approximation of an overlay by loading some code to an area of memory, mprotect( ptr, len, PROT_EXEC) th
by basementcat 8y ago
On a modern POSIX environment, you can hack together an approximation of an overlay by loading some code to an area of memory, mprotect( ptr, len, PROT_EXEC) the segment, ((int(*)())ptr)() to call the function and if you did everything right, you don't segfault too hard. Later, you can overwrite that area of memory with other code and repeat.
This is similar to what actually goes on under the hood of the dynamic loader.
http://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html http://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.htm...
- burfog 8y agoThat is a different sort of overlay, a code overlay. The other example was data, with the compiler assisting by changing local variables to have fixed addresses that get carefully reused for different variables at different times.