Page Tables

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
Dav

Page Tables

Post by Dav »

This is kind of a design question that I am a bit confused about.

My design is to switch the CR3 register each time a process switch occurs hence giving each process a clean address space.

Should i set a space in memory aside in the kernel that will contain the page tables for all processes or when a process is created should a new set of page tables be created in that processes memory?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Page Tables

Post by Solar »

Placing the page table in the process memory is a bad idea, since it would allow that process to arbitrarily change entries to that table.

The kernel should set up a new page table for every new process, either on-demand or pre-spawned (creating a couple of process environments beforehand so they are already created when required).

IMHO, and I haven't written that part of my OS yet, so take with a grain of salt.
Every good solution is obvious once you've found it.
Dav

Re:Page Tables

Post by Dav »

At the moment in my assembler stub I have set aside space for 4GB worth of page tables for the kernel. I am unsure where I would put the page tables for usermode processes. Maybe I should have a space of unmapped memory and have a pointer to it stored in the process structure. Hence on a process switch I can just load this pointer out of the structure.

What do are your thoughts on this idea?

I was writing this as I was thinking it, sorry its a bit all over the place.
Tim

Re:Page Tables

Post by Tim »

You can put page tables and the page directory in process memory, but it doesn't have to be accessible from user mode.

What I do is use the self mapping trick, where the top PDE is set to point to the PD itself. That way, the page tables appear in the top 4MB of the address space, and the page directory appears in the top 4KB of the address space. You don't have to explicitly map the PD or PTs into memory because you can manipulate them by poking values into the range FFC0_0000 to FFFF_F000 (for the page tables) and FFFF_F000 to FFFF_FFFF (for the page directory). Read my memory management tutorials; hopefully they explain it better.
Post Reply