01-18-06 10:55 PM
50295@web.de wrote:
> Hi -
>
> I've been stracing loads of stuff lately, trying to and I'm wondering
> how mmap actually words/is implemented on *NIX systems. I suspect
> mmaping the executable (elf binary) to the process' address space would
> be a good idea. Is this how mmap is implemented? I know shared
> libraries are are implemented with mmap (and quite possibly shared
> memory i.e. shmget etc), but I'm not sure how exec() is implemented.
> Hints anyone?
The best way, IMHO is to look upon it is in terms of hardware/MMU.
mmap makes clever use of the hardware, by setting up pagetable-entries,
which point to the address space and the appropriate diskpages.
The first access to a mmapped page wil cause a (page not present)
pagefault, and the page will be read in by the pagefault handler.
("faulted in")
Copy-on-write is just a useful extension to this scheme.
Execution of pages is basically the same, except for relocations,
which have to be fixed up by the loader. Don't know how that works,
I suggest you need to read the sources for that ;-]
> Please dont ask me to take a look at the source. I have, but it made my
> head spin.
>
It is supposed to make the disks spin, not your head.
> Thanks,
>
> - Olumide
>
HTH,
AvK
[ Post a follow-up to this message ]
|