VirtualQuery 给出非法结果。这是一个错误吗?
我的代码:
MEMORY_BASIC_INFORMATION meminf;
::VirtualQuery(box.pBits, &meminf, sizeof(meminf));
结果:
meminf: BaseAddress 0x40001000 void * AllocationBase 0x00000000 void * AllocationProtect 0x00000000 unsigned long RegionSize 0x0de0f000 unsigned long State 0x00010000 unsigned long Protect 0x00000001 unsigned long Type 0x00000000 unsigned long
注意:
(1) AllocationBase is NULL while BaseAddress is not NULL
(2)AllocationProtect为0(不是保护值)
是VirtualQuery的bug吗?
My code:
MEMORY_BASIC_INFORMATION meminf;
::VirtualQuery(box.pBits, &meminf, sizeof(meminf));
The results:
meminf: BaseAddress 0x40001000 void * AllocationBase 0x00000000 void * AllocationProtect 0x00000000 unsigned long RegionSize 0x0de0f000 unsigned long State 0x00010000 unsigned long Protect 0x00000001 unsigned long Type 0x00000000 unsigned long
Notes:
(1) AllocationBase is NULL while BaseAddress is not NULL
(2) AllocationProtect is 0 (not a protection value)
Is it a bug of VirtualQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是一个错误。
VirtualQuery() 文档
指出:在使用结构中的数据之前,检查函数结果是否等于
sizeof(meminf)
,或者使用使后面的代码执行正确操作的值来初始化结构。如果函数返回 0,则没有数据被复制到结构中,因此它仍将包含先前包含在其中的任何数据。如果没有初始化,这将是堆栈上的随机字节。This is not a bug. The documentation of
VirtualQuery()
states:Check the function result to be equal to
sizeof(meminf)
before using the data in the structure, or initialize the structure with values that will make the code that follows do the right thing. If the function returned 0 no data was copied to the structure, so it will still contain whatever data was previously in it. Without initialization this will be random bytes on the stack.将内核模式指针传递给此函数可能会导致不返回任何信息。
检查返回值。
Passing a kernel-mode pointer to this function can result in no information being returned.
Check the return value.