Page 1 of 1
Allocate pages in another address space
Posted: Tue May 12, 2009 8:45 am
by AndreaOrru
Hi all,
I'm developing a 64-bit kernel, and I'm currently rewriting my paging mechanism, after having coded a multithread scheduler that works pretty well.
I'm using the fractal method of pointing the last PML4 entry to the PML4 itself.
My question is: when I have to clone the current address space, how can I access the paging structures of the new address space from within the current address space?
Re: Allocate pages in another address space
Posted: Tue May 12, 2009 10:15 am
by Combuster
How about temporarily "fractal mapping" the other PML4 in the current address space?
Re: Allocate pages in another address space
Posted: Tue May 12, 2009 10:21 am
by AndreaOrru
Pointing the next-to-last current PML4's entry to the PML4 of the new address space? That's an idea. But it is how you do it?
Re: Allocate pages in another address space
Posted: Tue May 12, 2009 10:22 am
by Combuster
I dont fork(), so the situation doesn't apply to me
Re: Allocate pages in another address space
Posted: Tue May 12, 2009 10:27 am
by AndreaOrru
I don't fork() too, but I map the kernel in every address space, and I create a new kernel stack for each process. Even if you don't fork, you still need some way of accessing external address spaces, doesn't you?
Re: Allocate pages in another address space
Posted: Wed May 13, 2009 2:50 am
by xenos
When my kernel creates a new address space, it just takes an unused page, maps it to some temporary location, zeroes the first half of that page (which is the user part in my OS), copies the upper half from the current PML4 (which is the kernel part, that is mapped into every address space), unmaps the page again and enters the physical address of the page into the CR3 field of my process structure, which keeps track of address spaces. To fill the user part with, for example, some user space, which holds an executable, the kernel switches to the new address space, allocates user space, loads the executable and switches back to the old address space. That's it - the new address space is ready to use on the next thread switch.
Re: Allocate pages in another address space
Posted: Wed May 13, 2009 6:48 am
by AndreaOrru
It seems good to me. Obviously you have to make sure not to be interrupted during the process. Thanks.