#ifndef _NTOBAPI_H
//
// Objects, handles
//
#if (PHNT_MODE != PHNT_MODE_KERNEL)
/**
* Waits for one or all of an array of waitable objects. Use WaitAny to identify
* the satisfied object, or WaitAll to acquire the complete set without partially
* consuming available signals while other objects are not ready.
*
* \param Count Number of handles, from 1 through MAXIMUM_WAIT_OBJECTS (64).
* \param Handles Array of Count pointer-sized handles, each requiring SYNCHRONIZE
* (0x00100000). WaitAll rejects duplicate underlying dispatcher objects, including
* distinct handle values obtained by duplicating a handle to the same object.
* \param WaitType WaitAll (0) or WaitAny (1). WaitAny selects the lowest array
* index among objects simultaneously eligible when the wait is evaluated.
* \param Alertable TRUE permits an alert or ordinary user APC to interrupt the wait.
* \param Timeout Optional 100-nanosecond deadline: NULL for no deadline, pointed-to
* zero for polling, negative for a relative interval, positive for absolute NT system time.
* \return WaitAny returns STATUS_WAIT_0 plus the selected zero-based index, or
* STATUS_ABANDONED_WAIT_0 (0x80) plus that index when acquiring an abandoned mutant.
* WaitAll returns STATUS_SUCCESS (0), or STATUS_ABANDONED (0x80) when the set is
* acquired and includes an abandoned mutant; the latter does not identify an index.
* STATUS_TIMEOUT (0x102), STATUS_USER_APC (0xC0) and STATUS_ALERTED (0x101) do not
* establish acquisition. Test the status category, not just NT_SUCCESS.
* \remarks On the native x64 and WoW64 paths, invalid Count returns
* STATUS_INVALID_PARAMETER_1, invalid WaitType returns STATUS_INVALID_PARAMETER_3,
* and WaitAll with duplicate objects returns STATUS_INVALID_PARAMETER_MIX.
* All handles are referenced and access-checked before entering the dispatcher wait;
* an inaccessible later handle fails even if an earlier object is already signaled.
* A WaitAll timeout does not consume signals or acquire an abandoned mutant from
* an incomplete set. A completion-port handle is rejected for WaitAll with
* STATUS_INVALID_HANDLE. Cross-VM and special object paths
* have additional restrictions; this is not a promise that any handle is waitable.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitformultipleobjectsex
*/
_Kernel_entry_
NTSYSCALLAPI
NTSTATUS
NTAPI
NtWaitForMultipleObjects(
_In_ ULONG Count,
_In_reads_(Count) HANDLE Handles[],
_In_ WAIT_TYPE WaitType,
_In_ BOOLEAN Alertable,
_In_opt_ PLARGE_INTEGER Timeout
);
View code on GitHub#ifndef _NTZWAPI_H
_Kernel_entry_
NTSYSCALLAPI
NTSTATUS
NTAPI
ZwWaitForMultipleObjects(
_In_ ULONG Count,
_In_reads_(Count) HANDLE Handles[],
_In_ WAIT_TYPE WaitType,
_In_ BOOLEAN Alertable,
_In_opt_ PLARGE_INTEGER Timeout
);
View code on GitHubWaits for one or more objects to enter a signaled state.
Count - the number of handles passed in the Handles parameter, up to MAXIMUM_WAIT_OBJECTS (64).Handles - a pointer to an array of handles. Each handle must grant SYNCHRONIZE access.WaitType - the type of wait to perform, either WaitAll or WaitAny.Alertable - determines whether the wait should be altertable. This allows external triggers (such as APCs or calls to NtAlertThread) to interrupt wait prematurely.Timeout - an optional pointer to a variable that stores the wait internal. A negative value indicates relative timeout for the specified number of 100-nanosecond intervals. To wait a specific number of milliseconds, multiply them by -10,000. Positive values indicate an absolute time. NULL indicates an infinite timeout.STATUS_WAIT_0..STATUS_WAIT_63 - the thread woke due to the n'th object being signaled.STATUS_ABANDONED_WAIT_0..STATUS_ABANDONED_WAIT_63 - the thread woke due to the n'th passed mutex becoming abandoned.STATUS_TIMEOUT - the thread woke due to the timeout.STATUS_USER_APC - the wait was interrupted by an APC.STATUS_ALERTED - the wait was interrupted by a call to NtAlertThread.Despite the name, NtAlertThreadByThreadId is unrelated to alertable waits and cannot interrupt them.
Number of objects in ObjectsArray array.
Pointer to array of HANDLE. Each must be opened with SYNCHRONIZE access.
Can be WaitAllObjects or WaitAnyObject.
If set, thread is signaled (APC routines queued for this thread are executed).
Time-out interval.
NtWaitForMultipleObjects is used typically to response for notyfications. For synchronization purposes you should use NtWaitForSingleObject.
NtSignalAndWaitForSingleObjectNtWaitForSingleObjectOBJECT_WAIT_TYPE