0

The function virt_to_phys is only valid when addresses directly mapped or allocated via kmalloc. So how can I translate a virtual address that is or not allocated via kmalloc, into a physical address?

cg f
  • 41
  • 1
  • 5
  • If you get no kernel-savvy answers, you can always manually walk the page tables. – lockcmpxchg8b Dec 16 '17 at 02:22
  • Thanks. Can you give me some extra tips or referrence? – cg f Dec 16 '17 at 02:32
  • Presuming Intel, the CR3 register holds the physical base-address of the page tables. This isn't very helpful, because to work with the page tables you need to know where they're mapped into the kernel's virtual address space. (I don't know where off-hand, but the kernel folks will). I only mention it because it's the piece that's missing from being able to use this tutorial: https://www.quora.com/How-is-a-page-walk-implemented. As a summary: portions of the virtual address are used to look up entries in a series of nested tables. The last table holds the physical address of a block. – lockcmpxchg8b Dec 16 '17 at 14:13

0 Answers0