[Resolved] Replacing process image in Linux
Posted: Tue Jun 22, 2010 11:49 pm
Hello all,
What I'm attempting to do is prototype my OS in a hosted environment, and Linux seems the obvious choice.
The problem I'm having is that, although I can load arbitrary PIC code and execute it, I haven't been able to
find a way to replace the current process image. Obviously, exec does this, but it only works on files. What
I need is a way to replace the image with code I already have in memory. Does anyone know a way to do this?
I have been scouring manpages for a few days, and have tried googling the topic. I know WINE does this, but
honestly, I just can't parse its source, with all its lovely Win32-isms. If you know the answer and would just like
to teach me to fish rather than give me a fish, I would definitely appreciate just a pointer to where to start in
the WINE source or the source of another project, or whatever you think will help.
Thanks in advance.
EDIT: I grew a brain and actually read ALL of the mmap() manpage rather than nerd ADD skimming. Although I
resolved my own issue, making this post pointless, I figured I'd leave it up in case someone tries to search the
same thing. mmap() with the MAP_FIXED flag is the way to do it in Linux.
What I'm attempting to do is prototype my OS in a hosted environment, and Linux seems the obvious choice.
The problem I'm having is that, although I can load arbitrary PIC code and execute it, I haven't been able to
find a way to replace the current process image. Obviously, exec does this, but it only works on files. What
I need is a way to replace the image with code I already have in memory. Does anyone know a way to do this?
I have been scouring manpages for a few days, and have tried googling the topic. I know WINE does this, but
honestly, I just can't parse its source, with all its lovely Win32-isms. If you know the answer and would just like
to teach me to fish rather than give me a fish, I would definitely appreciate just a pointer to where to start in
the WINE source or the source of another project, or whatever you think will help.
Thanks in advance.
EDIT: I grew a brain and actually read ALL of the mmap() manpage rather than nerd ADD skimming. Although I
resolved my own issue, making this post pointless, I figured I'd leave it up in case someone tries to search the
same thing. mmap() with the MAP_FIXED flag is the way to do it in Linux.