Page 1 of 1

how self-reference PML4 work ( get address of PT)

Posted: Tue Apr 07, 2015 4:34 am
by maysam
hi
how can get address of PT form virtual address ?
this method is self-reference trick but i dont know what is behind it

i used google and read some article but cant find it
this code work in windows x64 but i cant know how it works

Code: Select all

UINT64 getPTfromVA(UINT64 vaddr)
{
	vaddr >>= 9;
	vaddr >>= 3;
	vaddr <<= 3;
	vaddr &= 0xfffff6ffffffffff;
	vaddr |= 0xfffff68000000000;
	return vaddr;
}

UINT64 getPDfromVA(UINT64 vaddr)
{
	vaddr >>= 18;
	vaddr >>= 3;
	vaddr <<= 3;
	vaddr &= 0xfffff6fb7fffffff;
	vaddr |= 0xfffff6fb40000000;
	return vaddr;
}

UINT64 getPDPTfromVA(UINT64 vaddr)
{
	vaddr >>= 27;
	vaddr >>= 3;
	vaddr <<= 3;
	vaddr &= 0xfffff6fb7dbfffff;
	vaddr |= 0xfffff6fb7da00000;
	return vaddr;
}

UINT64 getPML4fromVA(UINT64 vaddr)
{
	vaddr >>= 36;
	vaddr >>= 3;
	vaddr <<= 3;
	vaddr &= 0xfffff6fb7dbedfff;
	vaddr |= 0xfffff6fb7dbed000;
	return vaddr;
}