使用我们的API的客户得到警戒页异常。 他使用VirtualAlloc和VirtualProtect。警卫页例外 - 如何提高
当我运行他的例子时,一切正常。
我试图this例如微软的VisualStudio,但没有抛出0x80000001异常,即使我已经把它在根据“调试”例外菜单。 但这个例子中明确指出:
锁定该内存块中的第一次尝试失败,养STATUS_GUARD_PAGE_VIOLATION例外。
我需要做些什么才能获得该异常?
编辑:
客户做这样的事情:
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
DWORD dwPageSize = systemInfo.dwPageSize;
size_t size = width * height * sizeof(MyStruct);
while(size % dwPageSize)
{
height--;
size = width * height * sizeof(MyStruct);
}
size_t dataSize = size + dwPageSize;
MyStruct * my_struct = (MyStruct*)VirtualAlloc(NULL, dataSize, MEM_COMMIT | MEM_RESERVE , PAGE_READWRITE);
if (!my_struct) return;
LPVOID beginGuard = (char*)my_struct + size;
DWORD oldProtection;
BOOL b = VirtualProtect(beginGuard, dwPageSize, PAGE_READWRITE | PAGE_GUARD, &oldProtection);
if(!b) MessageBox(NULL, "Can't set guard page", "", 0);
doSomething(); // some API function
某处 'DoSomething的()' 中提到的异常被抛出。但我无法帮助那个客户,因为我没有得到这个例外。
你能否给我们提供更多的细节,以了解客户如何看守页面异常。向我们展示他的例子。就来自MSDN的示例而言,您可以在注释中看到其解释不正确,因为'VirtualLock'不会引发异常。其实很明显。我的意思是,在整个代码段中没有处理异常的代码。 –
我编辑了我的帖子以供澄清。 –
那么你在说什么,doSomething代表客户为了提出这个异常而做的一些动作,你不知道它们是什么?你有没有试过访问'my_struct'?用'MyStruct foo = my_struct [0];'替换'doSomething',你应该得到0x80000001异常。 –