Page 1 of 1
PDT Cloning
Posted: Sun Oct 18, 2009 7:07 pm
by oib111
This is something that's been bothering me for a while. So when I initialize my Virtual Memory Manager I have to setup an initial PDT, and it has 0-1MB and 2-4MB in memory identity mapped, and the kernel is remapped to 0x80000000. So when I clone a directory each task has the kernel mapped at 0x80000000 which is good, but they would also have 0-1MB and 2-4MB of memory being identity mapped which causes obvious problems. Now see, I need that to be identity mapped in the beginning. So my question is how do I get around this? Should I setup a separate PDT that has the kernel remapped and a heap, but nothing identity mapped, and when a process is started I clone that directory?
Re: PDT Cloning
Posted: Sun Oct 18, 2009 7:20 pm
by neon
Hello,
Why not just unmap that region of the virtual address space when you are in the kernel? I have to assume that your Memory Manager provides method for unmapping and freeing frames for reuse.
Re: PDT Cloning
Posted: Sun Oct 18, 2009 7:31 pm
by oib111
It does, but why "when you are in the kernel"? Do you mean when I clone a task unmap the pages?
Re: PDT Cloning
Posted: Sun Oct 18, 2009 8:16 pm
by pcmattman
Hi,
Do you mean when I clone a task unmap the pages?
Technically when you clone a task you keep the pages from the previous task in the address space. This is the general concept of "forking" a task (of course, there's more to clone than just the address space, but you get the idea). When you create a new executable image (in POSIX, "exec" functions) you clean out the old address space - all the pages below 0x80000000 in your case - and map in the new image into the now-clean address space.
It does, but why "when you are in the kernel"
When you actually kick off your first userspace application from within the kernel, you would clone the kernel address space and use a similar method to your "executable image creation" (ala POSIX "exec") as mentioned above. This way the regions below 0x80000000 get cleaned out
and you load an executable image in one fell swoop!
Note: When I talk about POSIX "exec" and "fork" I'm merely using them as a descriptive example as they're functions you should already be familiar with. There is no obligation for you to call these functions "exec*" and "fork" in your kernel, nor do you
have to follow POSIX guidelines if you don't want to. It all depends on how your kernel is designed. Referencing the functions is simply the easiest way to show the two different operations that occur.
Cheers,
Matt
Re: PDT Cloning
Posted: Sun Oct 18, 2009 9:01 pm
by oib111
Sorry, I phrased that wrong. I meant when I start a new task, I would unmap the identity mapped pages in the kernel PDT and then clone that PDT.
Re: PDT Cloning
Posted: Sun Oct 18, 2009 9:20 pm
by Hangin10
Why not just unmap it when you're done with it in initialization (ie after your EIP is in the higher half kernel) ?
Re: PDT Cloning
Posted: Sun Oct 18, 2009 10:34 pm
by oib111
I don't unmap it after initialization of the VMM because I need it for working with the screen as well as dynamic memory allocation until I setup a heap.
Re: PDT Cloning
Posted: Sun Oct 18, 2009 11:15 pm
by Hangin10
Then after you've set up your heap why not unmap it.
Ultimately it boils down to why not just unmap it before you get to creating any tasks, then you don't have to worry about it. If you have to create tasks before unmapping the identity-mapped kernel, that would seem to indicate that you are doing things in a wrong (or at least difficult to organize) manner.
Re: PDT Cloning
Posted: Mon Oct 19, 2009 8:11 am
by oib111
I will unmap after I setup the heap, and I'll just remap the first 1MB of memory to 0x80100000 or 0x80200000.