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

View File

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

View File

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

View File

@@ -59,7 +59,7 @@
<ItemDefinitionGroup> <ItemDefinitionGroup>
<ClCompile> <ClCompile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <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> <AdditionalOptions>/EHsc /D_ATL_NO_WIN_SUPPORT %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>

View File

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

View File

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

View File

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

View File

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