[SOLVED] Page tables exploration on Linux
Posted: Thu Jan 30, 2014 5:33 pm
Hi guys,
I wrote a code like that (linux kernel module) in order to explore page tables on Linux x86_64, but it seems that it's not getting the right PDPTE, maybe even the right PML4, do you see something odd.
Any help would would be appreciated.
I get inspired by this method: http://lists.xen.org/archives/html/xen- ... 1xYc8b.txt
I wrote a code like that (linux kernel module) in order to explore page tables on Linux x86_64, but it seems that it's not getting the right PDPTE, maybe even the right PML4, do you see something odd.
Any help would would be appreciated.
I get inspired by this method: http://lists.xen.org/archives/html/xen- ... 1xYc8b.txt
Code: Select all
// See Table 4-14.
#define PRESENT (1ULL << 0)
#define PAGE_GRANULARITY (1ULL << 7)
#define PML4_INDEX(address) ((address >> 39) & 0x1ff)
#define PDPT_INDEX(address) ((address >> 30) & 0x1ff)
unsigned long paging_entry(unsigned long address)
{
unsigned long cr3;
unsigned long pml4, pml4e;
unsigned long pdpt, pdpte;
unsigned long pd, pde;
asm volatile("movq %%cr3, %0\n\t"
:"=r" (cr3));
pml4 = __va(cr3 & 0xfffffffffffff000);
pml4e = pml4 + PML4_INDEX(address) * 0x8;
if ((pml4e & PRESENT) == 0)
return -EINVAL;
pdpt = pml4e & ~0xfff;
pdpte = pdpt + PDPT_INDEX(address) * 0x8;
if ((pdpte & PRESENT) == 0)
return -EINVAL;
}