yfractal / blog

10 stars 0 forks source link

How linux `mmap` works #4

Open yfractal opened 3 years ago

yfractal commented 3 years ago

Need explain:

  1. process
    1. page table
    2. VMA
    3. fork
  2. trap and page fault handler

For page table or virtual addressing may need write another blog.

yfractal commented 3 years ago

The instructions are using virtual address, hardware will help us to do the virtual address to physical address translation.

For os, we need get the physical address, eg: read/write some physical address content.

That means os wants to use physical address but the hardware doesn't support that directly.

How could we achieve that?

xv6 maps some virtual address to physical address directly by:

kvmmap(kpgtbl, (uint64)etext, (uint64)etext, PHYSTOP-(uint64)etext, PTE_R | PTE_W);

the kvmmap's signature is kvmmap(pagetable_t kpgtbl, uint64 va, uint64 pa, uint64 sz, int perm).

Yeah, that's how xv6 gets physical address, so fucking amazing !!!