paging and process mapping

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
icecoder
Posts: 16
Joined: Tue Jun 15, 2010 3:28 am

paging and process mapping

Post by icecoder »

Hi guys, I've searched everywhere and read the intel ASD manual vol 3A before posting, but didn't find answers to this question (assuming 32bit paging with no PAE):

Assuming 32bit paging is enabled, how can I isolate a process from the other ones?
Should I create a page directory for every process I run?

A linear address points simultaneously to the PDE, PTE and offset, so if I load "prog1.bin" to virtual address 0x00004000, and then want to load "prog2.bin" and map it to the same virtual address, EIP (let's say they're both plain binary files) will point for both to 0x00004000! This means that when the processor wants to find the physical address, it loads PDE 0, PTE 1, and offset 0 for both, and will point to the same physical location.. What am I missing?
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: paging and process mapping

Post by Combuster »

What you are missing is that the linear-to-physical mappings for each process is by design required to be different. So two processes can't use the exact same set of page tables or page directories - if it would it would be the same process.
"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
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: paging and process mapping

Post by Velko »

Yes, you create a separate page directory for every process. And also separate page tables.

You work with your processes one-at-a-time. Load CR3 with address of prog1.bin's PD, let it run for a some time. Then reload CR3 with address of prog2.bin's PD. Since this is different PD along with different PTs, now the same virtual addresses points to different physical addresses.

Physical addresses are about what is in your PDs and PTs, virtual addresses - where it is in your paging structures.
If something looks overcomplicated, most likely it is.
icecoder
Posts: 16
Joined: Tue Jun 15, 2010 3:28 am

Re: paging and process mapping

Post by icecoder »

Combuster wrote:What you are missing is that the linear-to-physical mappings for each process is by design required to be different. So two processes can't use the exact same set of page tables or page directories - if it would it would be the same process.
Thank you, now it makes really more sense. I've just realized I searched the wrong places.. cr3 must also be saved during context switches.
icecoder
Posts: 16
Joined: Tue Jun 15, 2010 3:28 am

Re: paging and process mapping

Post by icecoder »

Velko wrote:Yes, you create a separate page directory for every process. And also separate page tables.

You work with your processes one-at-a-time. Load CR3 with address of prog1.bin's PD, let it run for a some time. Then reload CR3 with address of prog2.bin's PD. Since this is different PD along with different PTs, now the same virtual addresses points to different physical addresses.

Physical addresses are about what is in your PDs and PTs, virtual addresses - where it is in your paging structures.
Yes, that's what I was missing. Thank you so much for your help.
Post Reply