[idd] win32: use wait result constants

Use the documented Win32 wait constants throughout the pipe, clipboard,
and input workers instead of local numeric aliases.

Select the WDK NT-status definitions before including Windows headers.
Include wudfwdm.h privately in the affected translation units so UMDF 2
provides NTSTATUS without exposing WDF headers through LGCommon's public
interface to the desktop Helper.
This commit is contained in:
Geoffrey McRae
2026-08-15 14:54:29 +10:00
parent cecd4b6f48
commit 6a590e343a
8 changed files with 46 additions and 30 deletions

View File

@@ -18,13 +18,16 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ntstatus.h>
#include "CClipboardChannel.h"
#include <wudfwdm.h>
#include "CClipboardRing.h"
#include "CDebug.h"
#include <new>
#include <ntstatus.h>
#include <string.h>
#include <utility>
#include <vector>
@@ -562,9 +565,9 @@ void CClipboardChannel::Thread()
{
const DWORD result = WaitForMultipleObjects(
ARRAYSIZE(events), events, FALSE, POLL_MS);
if (result == WAIT_FIRST_OBJECT_VALUE)
if (result == WAIT_OBJECT_0)
break;
if (result != WAIT_FIRST_OBJECT_VALUE + 1 && result != WAIT_TIMEOUT)
if (result != WAIT_OBJECT_0 + 1 && result != WAIT_TIMEOUT)
{
const DWORD error = GetLastError();
DEBUG_ERROR_HR(error,

View File

@@ -18,8 +18,12 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ntstatus.h>
#include "CPipeEndpoint.h"
#include <wudfwdm.h>
#include "CDebug.h"
#include <algorithm>
@@ -32,7 +36,6 @@ const DWORD CPipeEndpoint::SERVER_RETRY_MS = 1000;
const DWORD CPipeEndpoint::AUTHENTICATION_TIMEOUT_MS = 2000;
const DWORD CPipeEndpoint::AUTHORIZATION_POLL_MS = 1000;
const DWORD CPipeEndpoint::WRITE_TIMEOUT_MS = 250;
const DWORD CPipeEndpoint::WAIT_FIRST_OBJECT_VALUE = 0;
bool CPipeEndpoint::IsDisconnectedError(DWORD error)
{
@@ -66,14 +69,14 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::WaitForOverlapped(
return PipeIoResult::Error;
}
if (waitResult == WAIT_FIRST_OBJECT_VALUE + 1)
if (waitResult == WAIT_OBJECT_0 + 1)
{
CancelIoEx(pipe, overlapped);
GetOverlappedResult(pipe, overlapped, transferred, TRUE);
return PipeIoResult::Stopped;
}
if (waitResult != WAIT_FIRST_OBJECT_VALUE)
if (waitResult != WAIT_OBJECT_0)
{
DEBUG_ERROR_HR(GetLastError(), "Failed to wait for named pipe I/O");
CancelIoEx(pipe, overlapped);
@@ -86,7 +89,7 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::WaitForOverlapped(
const DWORD error = GetLastError();
if (error == ERROR_OPERATION_ABORTED &&
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0)
return PipeIoResult::Stopped;
if (IsDisconnectedError(error))
@@ -117,7 +120,7 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::ReadMessage(
pipe, ioEvent, &overlapped, bytesRead, timeoutMs);
if (error == ERROR_OPERATION_ABORTED &&
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0)
return PipeIoResult::Stopped;
if (IsDisconnectedError(error))
@@ -158,7 +161,7 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::WriteMessage(
result = PipeIoResult::Disconnected;
else if (error == ERROR_OPERATION_ABORTED &&
WaitForSingleObject(m_stopEvent, 0) ==
WAIT_FIRST_OBJECT_VALUE)
WAIT_OBJECT_0)
result = PipeIoResult::Stopped;
else
{
@@ -457,7 +460,7 @@ void CPipeEndpoint::RunServer()
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0)
break;
bool authenticated = false;
@@ -508,7 +511,7 @@ void CPipeEndpoint::RunServer()
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0 ||
(m_handler && !m_handler->PipeClientStillAuthorized(pipe)))
{
if (authenticated && m_handler)
@@ -617,7 +620,7 @@ void CPipeEndpoint::RunClient()
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0)
{
CloseHandle(pipe);
break;
@@ -650,7 +653,7 @@ void CPipeEndpoint::RunClient()
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0)
{
CloseHandle(pipe);
break;
@@ -726,7 +729,7 @@ bool CPipeEndpoint::ReadMessages(HANDLE pipe)
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
WaitForSingleObject(m_stopEvent, 0) == WAIT_OBJECT_0)
break;
if (m_handler && !m_handler->PipeClientStillAuthorized(pipe))

View File

@@ -126,7 +126,6 @@ private:
static const DWORD AUTHENTICATION_TIMEOUT_MS;
static const DWORD AUTHORIZATION_POLL_MS;
static const DWORD WRITE_TIMEOUT_MS;
static const DWORD WAIT_FIRST_OBJECT_VALUE;
static bool IsDisconnectedError(_In_ DWORD error);
PipeIoResult WaitForOverlapped(

View File

@@ -59,7 +59,7 @@
<ItemDefinitionGroup>
<ClCompile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>UMDF_USING_NTSTATUS;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/EHsc /D_ATL_NO_WIN_SUPPORT %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>

View File

@@ -280,6 +280,11 @@
<LGPackageToolOutDir Condition="'$(Platform)'=='Win32'">$([MSBuild]::NormalizeDirectory('$(LGDriverSolutionDir)$(LGBaseConfiguration)'))</LGPackageToolOutDir>
<InfVerif_AdditionalOptions>/sw2084</InfVerif_AdditionalOptions>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>UMDF_USING_NTSTATUS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WppEnabled>true</WppEnabled>

View File

@@ -18,8 +18,12 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ntstatus.h>
#include "ipc/CInputPipeServer.h"
#include <wudfwdm.h>
#include "config/CSettings.h"
#include "CDebug.h"
#include "CSRWLock.h"
@@ -29,8 +33,6 @@
CInputPipeServer g_inputPipeServer;
static constexpr DWORD WAIT_FIRST_OBJECT_VALUE = 0;
bool CInputPipeServer::Init()
{
DeInit();
@@ -564,9 +566,9 @@ void CInputPipeServer::Thread()
{
const DWORD wait = WaitForMultipleObjects(
_countof(handles), handles, FALSE, INFINITE);
if (wait == WAIT_FIRST_OBJECT_VALUE)
if (wait == WAIT_OBJECT_0)
break;
if (wait != WAIT_FIRST_OBJECT_VALUE + 1)
if (wait != WAIT_OBJECT_0 + 1)
{
DEBUG_ERROR_HR(GetLastError(), "LGInput sender wait failed");
break;

View File

@@ -18,8 +18,12 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ntstatus.h>
#include "transport/lgmp/CLGMPClipboardTransport.h"
#include <wudfwdm.h>
#include "CDebug.h"
#include "Seq.h"
#include "transport/lgmp/CLGMPHost.h"
@@ -29,8 +33,6 @@
namespace
{
static constexpr DWORD WAIT_FIRST_OBJECT_VALUE = 0;
static_assert(sizeof(LGMPStreamDescriptor) ==
sizeof(KVMFRStreamDescriptor),
"LGMP and KVMFR stream descriptor sizes differ");
@@ -1899,14 +1901,14 @@ void CLGMPClipboardTransport::Thread()
const HANDLE handles[] = { m_stopEvent, m_wakeEvent };
const DWORD wait = WaitForMultipleObjects(
_countof(handles), handles, FALSE, timeout);
if (wait == WAIT_FIRST_OBJECT_VALUE)
if (wait == WAIT_OBJECT_0)
break;
if (wait == WAIT_FIRST_OBJECT_VALUE + 1)
if (wait == WAIT_OBJECT_0 + 1)
{
lgmpStreamPollActivity(&streamPoll);
continue;
}
if (wait != WAIT_FIRST_OBJECT_VALUE + 1 && wait != WAIT_TIMEOUT)
if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_TIMEOUT)
{
DEBUG_ERROR_HR(GetLastError(),
"LGMP clipboard worker wait failed");

View File

@@ -18,8 +18,12 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ntstatus.h>
#include "transport/lgmp/CLGMPInputTransport.h"
#include <wudfwdm.h>
#include "config/CSettings.h"
#include "transport/lgmp/CLGMPHost.h"
#include "Atomic.h"
@@ -53,8 +57,6 @@ static constexpr int32_t MAX_MOUSE_WHEEL =
INT8_MAX * MAX_SPLIT_REPORTS;
static constexpr int32_t MIN_MOUSE_WHEEL =
-INT8_MAX * MAX_SPLIT_REPORTS;
static constexpr DWORD WAIT_FIRST_OBJECT_VALUE = 0;
static bool IsZero(const void * data, size_t size)
{
const uint8_t * byte = static_cast<const uint8_t *>(data);
@@ -446,7 +448,7 @@ bool CLGMPInputTransport::Start(IInputTarget& target)
const DWORD state = WaitForSingleObject(m_thread, 0);
if (state == WAIT_TIMEOUT)
return true;
if (state != WAIT_FIRST_OBJECT_VALUE)
if (state != WAIT_OBJECT_0)
{
DEBUG_ERROR_HR(GetLastError(),
"Failed to inspect LGMP input worker");
@@ -1006,12 +1008,12 @@ void CLGMPInputTransport::Thread()
const DWORD wait = WaitForMultipleObjects(
_countof(waitHandles), waitHandles, FALSE, INFINITE);
if (wait == WAIT_FIRST_OBJECT_VALUE)
if (wait == WAIT_OBJECT_0)
{
failed = Atomic::Load(m_statusFailed, std::memory_order_acquire);
break;
}
if (wait != WAIT_FIRST_OBJECT_VALUE + 1)
if (wait != WAIT_OBJECT_0 + 1)
{
DEBUG_ERROR_HR(GetLastError(), "LGMP input worker wait failed");
failed = true;