Let’s say I have allocated several pages of continuous memory using VirtualAlloc() from 0x06000000 to 0x06010000 (That’s 16 4KB pages) with PAGE_READWRITE protection. But after a while, I want to make a single page in that region of memory executable. After reading the msdn documentation for VirtualProtect(), I’m confused if this is possible or not. In linux, it is with mprotect.
Visual example of what I’m trying to do:
+-------------------------------------------------------+
| Commited memory with a single VirtualAlloc call (RW-) |
+-------------------------------------------------------+
↑ ↑
0x06000000 0x06010000
And I want to change the protection to this (Not to scale):
+------------------+-----------+------------------------+
| (RW-) | (RWX) | (RW-) |
+------------------+-----------+------------------------+
↑ ↑ ↑ ↑
0x06000000 0x06003000 0x06004000 0x06010000
Would I be allowed to this with a VirtualProtect() call like this?
VirtualProtect(0x06003000, 0x1000, PAGE_EXECUTE_READWRITE, &oldProtection);
I currently don’t have access to a Windows system to test this, that’s why I’m asking it on SO
VirtualProtect(0x06003000, 0x1000, PAGE_EXECUTE_READWRITE, &oldProtection);is correct for an already allocated/committed block of memory of 0x1000 bytes starting at 0x06003000.