Loading processes in (new) virtual address space
Posted: Wed Dec 12, 2007 12:30 pm
Hi all,
I have been thinking for some time now about a problem. To say it melodramatically: I am facing a wall and I can't see trough it, nor can I turn around. I guess I am developing some kind of tunnel-vision, and I can't get my head straight about this so-called problem.
Ok, here is the situation: until now, I developed a kernel that supports protected mode, using a gdt with 5 entries (null, kernel code, kernel data, user code, user data), all spanning the full memory range. The IDT has been implemented, the pic and pit have been initialized. A made my own version of the buddy system for physical page management (yes, I use paging and this works, that is, my kernel doesn't crash on page allocation and page mapping). Kernel memory (kernel heap) is being managed using a variation on Dougs Lea allocator.
The next thing for me to do is task management. I can grasp anything that has to do with tasks except for one thing: How to start a new f*cking task, or process. Here is how I think about it: as soon as a process makes a system call to startup a new task, a new address space has to be created. That is something I can code, no problem. But somehow I think that the way I create the basic environment for the new task is bothering me now in how to continue.
Here is how I think I should do it (keep in mind that the last pagedir entry always points to itself):
1: Find a free pagedir entry in kernelspace part of the current pagedir
2: Allocate a physical page and put the phys. address in the found entry, this pagetable will be used as the new pagedir of the new process
3: Calculate the virtual address of this new pagedir.
4: Copy at least the kernel pagetables in the new pagedir
5: From this point, I can allocate pagetables for this new process and put them (that is, the physical address) in this new pagedir
And from here, I block totally. What if I want to load the code, data and bss sections of this new process in memory? I can't access the pages behind the allocated pagetables and I guess I can't just overwrite the value in CR3 because I can think of some serious problems this might cause.
Can anybody give me some insights or directions? How did any of you solve this, or, which way did you choose?
Thanks in advance,
Hailstorm!
I have been thinking for some time now about a problem. To say it melodramatically: I am facing a wall and I can't see trough it, nor can I turn around. I guess I am developing some kind of tunnel-vision, and I can't get my head straight about this so-called problem.
Ok, here is the situation: until now, I developed a kernel that supports protected mode, using a gdt with 5 entries (null, kernel code, kernel data, user code, user data), all spanning the full memory range. The IDT has been implemented, the pic and pit have been initialized. A made my own version of the buddy system for physical page management (yes, I use paging and this works, that is, my kernel doesn't crash on page allocation and page mapping). Kernel memory (kernel heap) is being managed using a variation on Dougs Lea allocator.
The next thing for me to do is task management. I can grasp anything that has to do with tasks except for one thing: How to start a new f*cking task, or process. Here is how I think about it: as soon as a process makes a system call to startup a new task, a new address space has to be created. That is something I can code, no problem. But somehow I think that the way I create the basic environment for the new task is bothering me now in how to continue.
Here is how I think I should do it (keep in mind that the last pagedir entry always points to itself):
1: Find a free pagedir entry in kernelspace part of the current pagedir
2: Allocate a physical page and put the phys. address in the found entry, this pagetable will be used as the new pagedir of the new process
3: Calculate the virtual address of this new pagedir.
4: Copy at least the kernel pagetables in the new pagedir
5: From this point, I can allocate pagetables for this new process and put them (that is, the physical address) in this new pagedir
And from here, I block totally. What if I want to load the code, data and bss sections of this new process in memory? I can't access the pages behind the allocated pagetables and I guess I can't just overwrite the value in CR3 because I can think of some serious problems this might cause.
Can anybody give me some insights or directions? How did any of you solve this, or, which way did you choose?
Thanks in advance,
Hailstorm!