Page 1 of 1

ELF Loading: Page Mapping

Posted: Fri Oct 10, 2008 2:47 am
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!

Re: ELF Loading: Page Mapping

Posted: Fri Oct 10, 2008 6:25 am
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