Reputation: 23
Suppose I have a buffer of say 100 bytes as in char *pBuffer = new char[100];
and I want to pass this to a third party function with specific instruction that it write into only the top half and that the bottom half is out of limits. How can I enforce that with Win32 API?
Thanks.
PS: This particular example might not be perfect but I am clear about my question.
Upvotes: 0
Views: 1712
Reputation: 91270
You'll need to use VirtualProtect to mark the last half as readonly. Since VirtualProtect works with pages, not bytes, you will in your example need to VirtualAlloc PAGE_SIZE
+ 50 bytes, and adjust pBuffer
so it matches your requirements.
Upvotes: 3