So I have a user mode process which will send 'requests' to a kernel driver by setting a variable in the usermode processes's memory. The kernel driver sets the handle once it sees that the pid is not 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;
}
The issue is that the while loop will never stop, even when I know the kernel driver is setting the _handle correctly except for when I put
std::cout << _KeHandleByProcessIDRequest._Handle << std::endl;
inside of the while loop. I assume this is because the program assumes the value is the same because it hasn't been modified in this program since the last check so it thinks the handle is the same value over and over and the cout call is 'updating' the value.
Thanks in advance