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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
maysam
Posts: 1
Joined: Tue Apr 07, 2015 4:27 am

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

Post 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;
}
Post Reply