PDT Cloning
PDT Cloning
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
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.
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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: PDT Cloning
It does, but why "when you are in the kernel"? Do you mean when I clone a task unmap the pages?
-
- 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:
Re: PDT Cloning
Hi,
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
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.Do you mean when I clone a task unmap the pages?
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!It does, but why "when you are in the kernel"
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
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
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
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
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.
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
I will unmap after I setup the heap, and I'll just remap the first 1MB of memory to 0x80100000 or 0x80200000.