What is the trick in pAddress & ~(PAGE_SIZE - 1) to get the page's base address
Posted
by Dbger
on Stack Overflow
See other posts from Stack Overflow
or by Dbger
Published on 2010-06-11T15:06:21Z
Indexed on
2010/06/11
16:52 UTC
Read the original article
Hit count: 179
Following function is used to get the page's base address of an address which is inside this page:
void* GetPageAddress(void* pAddress)
{
return (void*)((ULONG_PTR)pAddress & ~(PAGE_SIZE - 1));
}
But I couldn't quite get it, what is the trick it plays here?
Conclusion:
Personally, I think Amardeep's explanation plus Alex B's example are best answers. As Alex B's answer has already been voted up, I would like to accept Amardeep's answer as the official one to highlight it! Thanks you all.
© Stack Overflow or respective owner