Let us assume that I have two applications running on an x86 system and both applications access the virtual memory at the same virtual address. If the virtual to physical mapping consists of the bits being used to index into the page directory and the page table, how would the page tables be able to map two instances of the same virtual address (e.g. 400000h) to different physical addresses? Would they not end up indexing to the same entry in the page table because the virtual addresses are the same?
Asked
Active
Viewed 40 times
1
-
1The OS ensures that every process gets its own page table. – Chuck Adams Nov 14 '19 at 15:05
-
1On the x86/x86-64 when an OS does a context switch between processes (applications) it generally changes the CR3 register that contains the address to the root of the paging structures for the process. Using this method each process can be given different virtual to physical address mappings. It is also possible for different processes to have a virtual address mapped to the same physical address as other process(es) resulting in the concept of shared memory between processes. – Michael Petch Nov 14 '19 at 15:28
-
https://stackoverflow.com/questions/26583919/linux-kernel-page-table-update mentions as part of the premise of the question that every process has its own page tables, but not a perfect duplicate because the answers aren't about that. https://stackoverflow.com/questions/10671147/how-do-x86-page-tables-work has a comment from the OP that context switches need to change CR3. Ah, finally found a Q&A about choosing page-tables on a per-process basis where the *answer* is to set CR3. That's a duplicate, linked this question to that. – Peter Cordes Nov 14 '19 at 16:19
-
1Also note that each logical core has its own CR3 register (and other architectural state) so multi-core systems can run different processes on different cores, even with hyperthreading on the same physical core. – Peter Cordes Nov 14 '19 at 16:23