How to convert virtual address to physical address and reverse?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



冰河Hi all,

I have problems about converting virtual address into physical address and
reverse. I supply a kernel function  to grab cr3 value, but how do I READ
the content from the address located by cr3 to load the GDT and access the
entry in it ?

is it the thing like following (I see this snippet from somewhere by
googling...)

static unsigned long v2p(unsigned long va)
{
    pgd_t *pgd;
    pmd_t *pmd;
    pte_t *ptep, pte;
    struct page *page;
    unsigned long pa;

    pgd = pgd_offset(tsk->mm, va); /* what is tsk->mm */
    pmd = pmd_offset(pgd,va);
    pte = pte_offset(pte,va);

    pte = *ptep;
    page = pte_page(pte);  /* aha, we have the pa of the page  */

    pa = (pte_val(*ptep) & PTE_PHYS_MASK) | (va&(PAGE_SIZE-1);
    return pa;
}

the second problem is how do I do the reverse job? vir -> phys ?




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux