Re: Allocating, writing to, and loading from specific memory locations

Jordan Hubbard <[email protected]>
Newsgroups gmane.os.opendarwin.general
Message-ID <[email protected]>
On Feb 4, 2005, at 8:48 PM, Michael Richards wrote:

> Hi!
>
> This is going to sound stupid; it's a hard question to phrase. Does 
> anyone know if it is possible to dump file contents to a specific 
> memory location and have the system load from that location as a 
> process?

Sort of.   It's not anything as simple as writing stuff out to a random 
file and then saying "go exec this file", of course.  You have to do a 
lot more work than that.

See emacs's unexec.c as a relatively simple[1] example.  What it 
basically does is create a Mach-o executable header from scratch, using 
its pre-existing executable as a template, and then writes out its own 
text and initialized data sections in order to "undump" the currently 
running emacs instance (which, during emacs's bootstrap process, has 
read in all the compiled elisp files).

This is very much advanced-class material, however, and you shouldn't 
even THINK about diving into this kind of task unless you're ready and 
able to learn far more about Mach-o than you ever wanted to.  Most of 
the "documentation" you'll need also comes in the form of header files 
and the source - you won't find an ADC guide on creating executables 
from scratch.  That said, yes, it IS possible.   If your name is Rob 
Pike, it might even be easy. ;-)

- Jordan

[1] I say "simple" because even in this case, emacs has a pre-existing 
executable to work from in coming up with some initial size 
calculations - it's not just creating the new executable from whole 
cloth.  If that's what you have in mind, you'll have even more work 
ahead of you.

>
> Told you it was hard to phrase... that probably didn't make much 
> sense, perhaps this will illustrate it more clearly: If you have a 
> dump of a process' memory space from vmmap or MallocDebug, and you 
> quit the process, would it be possible to insert the contents into 
> memory at a later time, and effectively spawn the process that way (in 
> the same state as the dumped contents)?
>
> How does vmmap even work?
>
> I realize this could potentially be dangerous. It doesn't have to be 
> easy. I'd just like to know if it is possible, and what it would take.
>
> Thanks!
>
> Mike
>
> _______________________________________________
> Discuss mailing list
> [email protected]
> http://www.opendarwin.org/mailman/listinfo/discuss
>
--
Jordan K. Hubbard
Engineering Manager, BSD technology group
Apple Computer
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.