ELF Loading: Page Mapping

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

ELF Loading: Page Mapping

Post by pcmattman »

Hi everyone,

Just found a little bit of spare time in between assignment and exams and am going back over some ELF code I have trying to make it better. I've noticed a lot of calls like this:

Code: Select all

                    MapPage( newcr3, prghdrs[i].p_vaddr + (0x1000 * z), ((uint32_t) secptr) + (0x1000 * z), pageflags );
                    MapPage( 0xfffff000, 0xf2000000 + (0x1000 * z), ((uint32_t) secptr) + (0x1000 * z), PF_PRESENT | PF_READWRITE | PF_USER | PF_KERNELPAGE );
Basically, mapping in the page into the new address space, and also into the parent space to be able to copy data to the area.

Is it plausible to switch page directories when creating a new task and avoid this mapping mess? I know for sure caches will be a problem with switching the page directories, but is switching a better way than what I'm doing now? Thanks in advance!
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: ELF Loading: Page Mapping

Post by AJ »

Hi,

My personal thought processes for getting around this are:

1) New PCB created along with PD.
2) Switch to new task, ring 0, running a kernel procedure like start_task() or whatever.
3) You can now create what will be the new process' ring 3 stack in the current memory space (because of switching to the new task in step 2).
4) Relocate the page from your ELF file which contains the program entry point.
5) Relegate this task to ring 3, and ensure that the next loaded EIP is the program's entry point.
6) Each time a PFE happens, your kernel can perform "lazy-loading" of that portion of the ELF file.

In all the above, you avoid remaps between PD's as you are always doing paging within the context of the current task.

Sorry to ramble - it's one of those days :)

Cheers,
Adam
Post Reply