VirtualQuery 给出非法结果。这是一个错误吗?

发布于 2024-08-06 14:19:11 字数 660 浏览 1 评论 0原文

我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

西瓜 2024-08-13 14:19:11

这不是一个错误。 VirtualQuery() 文档 指出:

返回值是信息缓冲区中实际返回的字节数。

如果函数失败,返回值为零。要获取扩展错误信息,请调用 GetLastError。可能的错误值包括 ERROR_INVALID_PARAMETER。

在使用结构中的数据之前,检查函数结果是否等于 sizeof(meminf),或者使用使后面的代码执行正确操作的值来初始化结构。如果函数返回 0,则没有数据被复制到结构中,因此它仍将包含先前包含在其中的任何数据。如果没有初始化,这将是堆栈上的随机字节。

This is not a bug. The documentation of VirtualQuery() states:

The return value is the actual number of bytes returned in the information buffer.

If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible error values include ERROR_INVALID_PARAMETER.

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.

沧笙踏歌 2024-08-13 14:19:11

将内核模式指针传递给此函数可能会导致不返回任何信息。
检查返回值。

Passing a kernel-mode pointer to this function can result in no information being returned.
Check the return value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文