开发者

Memory mapping of binary to VAS

When a new process is created the Address space is created using fork() i.e new page table entries are created for the new process which are exactly same as the parent process. After fork() the exec() is called. What happens during the exec() system call?

I read in the book "Operating system concepts " that when a new program is executed, the process is given a new empty VAS. Does that mean that the page table entries created during fork() would get deleted/modifeid ? What is the meaning of empty VAS?

How does the memory mapping of binary to VAS is performed? How does the loader knows that what addres开发者_StackOverflow社区ses of the VAS should be mapped to the corresponding binary file?

I am really confused here.


when you call exec the kernel will load the binary and set up a whole new set of page tables (replacing the old ones).

The loader gets the address to load the binary at from the binary itself (basically it does read() to get the headers and stuff that's not code, then mmap() to actually load the code/data stuff in the binary)

so it looks at the binary and figures out how it should be loaded, the does mmap(), passing in an address to do the map at for each part of the binary that needs to be in a different place (ie code and data sections are probably two different calls to mmap() also the .bss section would be mapped from /dev/zero)

Note that depending on the OS and the binary being loaded some of this stuff may be handled by the kernel directly or by a userspace loader (on UNIXish systems ld would be the loader, it handles shared object loading)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜