当变量值被另一个进程更改时不更新?

时间:2019-10-29 05:45:13

标签: c++ memory kernel interpreter

因此,我有一个用户模式进程,该进程将通过在用户模式进程的内存中设置一个变量来向内核驱动程序发送“请求”。看到pid不为null时,内核驱动程序将设置该句柄。

long SendHandleByProcessIDRequest(int pid)
{
    _KeHandleByProcessIDRequest._pid = pid;
    while (_KeHandleByProcessIDRequest._Handle == 0) {}; // wait until the kernel driver has set the handle output
    long handle = _KeHandleByProcessIDRequest._Handle;

    // Request is complete
    _KeHandleByProcessIDRequest._pid = NULL;
    _KeHandleByProcessIDRequest._Handle = NULL;

    return handle;
}

问题在于,即使我知道内核驱动程序正确设置了_handle,但我放置时,while循环也永远不会停止

std::cout << _KeHandleByProcessIDRequest._Handle << std::endl;
在while循环内的

。我认为这是因为该程序假定该值是相同的,因为自上次检查以来在该程序中尚未对其进行修改,因此它认为该句柄一遍又一遍是相同的值,而cout调用正在“更新”该值。

预先感谢

0 个答案:

没有答案