POSIX mapping of executables/libs into memory
Posted: Wed May 04, 2016 1:37 pm
I am redesigning my memory manager to properly handle mapping files into memory. In fact, I want everything to technically be a memory-mapped "file", created using mmap() - including anynous memory, which will simply be a "file" filled with zeroes. Other POSIX systems take a similar approach. So basically when I map a read-only file I want it to be read into memory when a page fault occurs etc, hence preserving lots of physical memory.
I have a simple question about how ELF files should be handled. When loading from program headers, I will call mmap() on various parts of the ELF file to map it into memory as a private copy. But, as you know, the segment might be shorter in the file than it is in memory, and the rest is to be filled with zeroes.
I want to try to remain standard-conformant, so I ask, how do other POSIX-based systems do it? Do they just map as much from the file as possible, and then do another mmap() call to map anonymous memory to fill the rest of the segment with zeroes? Or is there some standard function that lets us map a smaller segment in a file to a larger segment of memory?
I hope the question is clear.
I have a simple question about how ELF files should be handled. When loading from program headers, I will call mmap() on various parts of the ELF file to map it into memory as a private copy. But, as you know, the segment might be shorter in the file than it is in memory, and the rest is to be filled with zeroes.
I want to try to remain standard-conformant, so I ask, how do other POSIX-based systems do it? Do they just map as much from the file as possible, and then do another mmap() call to map anonymous memory to fill the rest of the segment with zeroes? Or is there some standard function that lets us map a smaller segment in a file to a larger segment of memory?
I hope the question is clear.