When passing 0x000'00000000
(NULL
) as the first parameter of VirtualAlloc
the system determines where to allocate the region, or if the function fails, the return value is NULL
(0x000'00000000
).
For a 64-bit process on 64-bit Windows, the virtual address space ranges from 0x000'00000000
through 0x7FFF'FFFFFFFF
.
So how do I reserve a page starting at 0x000'00000000
without the function failing and system determining where to allocate the region?
Taking your question literally, you asked to reserve a page and not commit it. That's easy; the operating system already does it for you on process startup to prevent that page being committed by accident and causing havoc with all the functions that use those 65536 addresses as special values, like the NULL pointer or integers disguised as string pointers like MAKEINTRESOURCE, or, as Hans Passant has mentioned in the comments, breaking the CLR's null pointer detection by treating every access violation in that page as a null pointer exception.
However, starting with Windows 8, you cannot unreserve that page anymore.