保护页异常-如何引发
Guard Page Exception - how to raise
使用我们的API的客户会得到一个保护页异常。他使用VirtualAlloc和VirtualProtect。
当我以他为榜样时,一切都很好。
我从Microsoft尝试了这个例子,但即使我已经在"Debug"下的异常菜单中打开了它,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()"中的某个位置,会抛出上述异常。但我不能帮助那个客户,因为我没有例外。
若要引发代码为0x80000001的异常,您需要尝试访问使用PAGE_GUARD
标志分配和保护的内存。写一些类似的东西
MyStruct foo = my_struct[0];
并且将引发异常。
就MSDN中的示例而言,您可以在该帖子的评论中看到它的解释是不正确的,因为VirtualLock
没有引发异常。
相关文章:
- 孤立代码块在结构中引发异常
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 尝试使用智能指针时引发异常
- 如果分配数组引发异常,是否应该释放该数组
- 引发异常的方法的命名约定 (C++)?
- 读取文件时引发异常
- 在类 12.exe 中0x7B37FF80 (ucrtbased.dll) 引发异常: 0xC0000005:访问冲突读
- 从 C++ 中异常的构造函数引发异常
- 尝试将数字写入二进制文件时引发异常
- 在基于英语的系统上将 UTF-8 路径转换为宽字符会引发异常
- zeromq 在 I/O 线程中引发异常
- 发生此错误:在0x0F2BFB7C(基于.dll)时引发异常 尝试更改大小是问题吗?
- 添加新行时工作代码引发异常.调试技巧?
- 重新引发异常保留回溯
- 引发异常:写访问冲突. temp 为 nullptr
- 删除无效地址时C++引发异常
- 从二进制文件中读取元素时引发异常(引发异常:读取访问冲突. _Pnext 0xB414D4)
- 引发异常
- 是否允许分配器构造和销毁成员函数从内部逻辑引发异常?
- 引发异常:读取访问冲突.**此**0x40错误