I'm trying to manage a (theoretical) simple task: allocate memory at an address specified by me. However, I don't get it to work for some reason.
I simply use
VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
If
lpAddress is set to NULL, Windows will allocate the memory at an address it selects by itself. This works without any problems.
However, if I specify any memory location, the function will fail with
ERROR_INVALID_ADDRESS from
GetLastError. I traced a bit in the Windows kernel, but I found only one error check: If
lpAddress is below 0x00010000,
GetLastError will return
ERROR_INVALID_PARAMETER.
The function even fails if I'm trying to force allocation of the memory region which Windows will give me if I set
lpAddress to NULL.
Example:
Code:
VirtualAlloc(0x00830000, 0x4000, MEM_COMMIT, PAGE_READWRITE) -> function fails with ERROR_INVALID_ADDRESS
VirtualAlloc(NULL, 0x4000, MEM_COMMIT, PAGE_READWRITE) -> function allocates 0x4000 bytes at address 0x00830000
Did I miss something special or why doesn't the allocation of a specific memory region work?