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.
POSIX mapping of executables/libs into memory
Re: POSIX mapping of executables/libs into memory
In this case my loader will call mmap twice for the segment. Once to mmap part of the ELF file and a second time to mmap additional anonymous pages. So these segments result in 2 mappings in the mm. It probably doesn't matter but my ELF loader is in userspace.
I have not implemented mmaped files yet but have thought a lot about how I will do it.
I have not implemented mmaped files yet but have thought a lot about how I will do it.
If a trainstation is where trains stop, what is a workstation ?
Re: POSIX mapping of executables/libs into memory
In this case i'll probably add a non-standard system call for this purpose and have an mmap() function which wraps around it, in the C library. This will let me use the full potential of my kernel and minimize the number of mappings that must be kept track of.
Re: POSIX mapping of executables/libs into memory
For me basically mmap does 2 separate things. Having 2 separate APIs would seem to make sense.
If a trainstation is where trains stop, what is a workstation ?
Re: POSIX mapping of executables/libs into memory
In what way does it do 2 separate things?gerryg400 wrote:For me basically mmap does 2 separate things. Having 2 separate APIs would seem to make sense.
Re: POSIX mapping of executables/libs into memory
Mapping files and mapping anonymous memory may be quite different depending on your design.
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 63
- Joined: Fri May 01, 2015 2:23 am
- Libera.chat IRC: Hellbender
Re: POSIX mapping of executables/libs into memory
There are standards for system calls?mariuszp wrote:.. a non-standard system call ..
Hellbender OS at github.
Re: POSIX mapping of executables/libs into memory
I consider to be a "system call" a function which does nothing other than:Hellbender wrote:There are standards for system calls?mariuszp wrote:.. a non-standard system call ..
Code: Select all
function:
mov %rcx, %r10
mov $5, %rax
syscall
ret