使用我們的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異常。 –