Allocate pages in another address space

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
AndreaOrru
Member
Member
Posts: 50
Joined: Fri Apr 25, 2008 2:50 pm
Location: New York

Allocate pages in another address space

Post 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?
Close the world, txEn eht nepO
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Allocate pages in another address space

Post by Combuster »

How about temporarily "fractal mapping" the other PML4 in the current address space?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndreaOrru
Member
Member
Posts: 50
Joined: Fri Apr 25, 2008 2:50 pm
Location: New York

Re: Allocate pages in another address space

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Allocate pages in another address space

Post by Combuster »

I dont fork(), so the situation doesn't apply to me :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndreaOrru
Member
Member
Posts: 50
Joined: Fri Apr 25, 2008 2:50 pm
Location: New York

Re: Allocate pages in another address space

Post 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?
Close the world, txEn eht nepO
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Allocate pages in another address space

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
AndreaOrru
Member
Member
Posts: 50
Joined: Fri Apr 25, 2008 2:50 pm
Location: New York

Re: Allocate pages in another address space

Post by AndreaOrru »

It seems good to me. Obviously you have to make sure not to be interrupted during the process. Thanks.
Close the world, txEn eht nepO
Post Reply