OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 9:13 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 1:37 pm 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
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.


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 3:31 pm 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
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.

_________________
If a trainstation is where trains stop, what is a workstation ?


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 3:40 pm 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
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.


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 3:49 pm 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
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 ?


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 4:08 pm 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
gerryg400 wrote:
For me basically mmap does 2 separate things. Having 2 separate APIs would seem to make sense.

In what way does it do 2 separate things?


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 4:35 pm 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
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 ?


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Wed May 04, 2016 10:46 pm 
Offline
Member
Member

Joined: Fri May 01, 2015 2:23 am
Posts: 63
mariuszp wrote:
.. a non-standard system call ..

There are standards for system calls?

_________________
Hellbender OS at github.


Top
 Profile  
 
 Post subject: Re: POSIX mapping of executables/libs into memory
PostPosted: Thu May 05, 2016 11:01 am 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
Hellbender wrote:
mariuszp wrote:
.. a non-standard system call ..

There are standards for system calls?


I consider to be a "system call" a function which does nothing other than:

Code:
function:
  mov %rcx, %r10
  mov $5, %rax
  syscall
  ret


So by "non-standard system call" I meant such a function which is not part of POSIX, and my mmap() will be a function which then calls this "non-standard system call".


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 53 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group