本文整理汇总了C++中NtWaitForSingleObject函数的典型用法代码示例。如果您正苦于以下问题:C++ NtWaitForSingleObject函数的具体用法?C++ NtWaitForSingleObject怎么用?C++ NtWaitForSingleObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NtWaitForSingleObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeviceInstallThread
/* Loop to install all queued devices installations */
static ULONG NTAPI
DeviceInstallThread(IN PVOID Parameter)
{
HINF hSetupInf = *(HINF*)Parameter;
PSLIST_ENTRY ListEntry;
DeviceInstallParams* Params;
LARGE_INTEGER Timeout;
for (;;)
{
ListEntry = RtlInterlockedPopEntrySList(&DeviceInstallListHead);
if (ListEntry == NULL)
{
/*
* The list is now empty, but there may be a new enumerated device
* that is going to be added to the list soon. In order to avoid
* setting the hNoPendingInstalls event to release it soon after,
* we wait for maximum 1 second for no PnP enumeration event being
* received before declaring that no pending installations are
* taking place and setting the corresponding event.
*/
Timeout.QuadPart = -10000000LL; /* Wait for 1 second */
if (NtWaitForSingleObject(hDeviceInstallListNotEmpty, FALSE, &Timeout) == STATUS_TIMEOUT)
{
/* We timed out: set the event and do the actual wait */
NtSetEvent(hNoPendingInstalls, NULL);
NtWaitForSingleObject(hDeviceInstallListNotEmpty, FALSE, NULL);
}
}
else
{
NtResetEvent(hNoPendingInstalls, NULL);
Params = CONTAINING_RECORD(ListEntry, DeviceInstallParams, ListEntry);
InstallDevice(hSetupInf, hEnumKey, hServicesKey, Params->DeviceIds);
RtlFreeHeap(ProcessHeap, 0, Params);
}
}
return 0;
}
示例2: WaitForSingleObjectEx
/*
* @implemented
*/
DWORD
WINAPI
WaitForSingleObjectEx(IN HANDLE hHandle,
IN DWORD dwMilliseconds,
IN BOOL bAlertable)
{
PLARGE_INTEGER TimePtr;
LARGE_INTEGER Time;
NTSTATUS Status;
RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActCtx;
/* APCs must execute with the default activation context */
if (bAlertable)
{
/* Setup the frame */
RtlZeroMemory(&ActCtx, sizeof(ActCtx));
ActCtx.Size = sizeof(ActCtx);
ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
RtlActivateActivationContextUnsafeFast(&ActCtx, NULL);
}
/* Get real handle */
hHandle = TranslateStdHandle(hHandle);
/* Check for console handle */
if ((IsConsoleHandle(hHandle)) && (VerifyConsoleIoHandle(hHandle)))
{
/* Get the real wait handle */
hHandle = GetConsoleInputWaitHandle();
}
/* Convert the timeout */
TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
/* Start wait loop */
do
{
/* Do the wait */
Status = NtWaitForSingleObject(hHandle, (BOOLEAN)bAlertable, TimePtr);
if (!NT_SUCCESS(Status))
{
/* The wait failed */
BaseSetLastNTError(Status);
Status = WAIT_FAILED;
}
} while ((Status == STATUS_ALERTED) && (bAlertable));
/* Cleanup the activation context */
if (bAlertable) RtlDeactivateActivationContextUnsafeFast(&ActCtx);
/* Return wait status */
return Status;
}
示例3: LockFile
/*
* @implemented
*/
BOOL
WINAPI
LockFile(IN HANDLE hFile,
IN DWORD dwFileOffsetLow,
IN DWORD dwFileOffsetHigh,
IN DWORD nNumberOfBytesToLockLow,
IN DWORD nNumberOfBytesToLockHigh)
{
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
LARGE_INTEGER BytesToLock, Offset;
/* Is this a console handle? */
if (IsConsoleHandle(hFile))
{
/* Can't "lock" a console! */
BaseSetLastNTError(STATUS_INVALID_HANDLE);
return FALSE;
}
/* Setup the parameters in NT style and call the native API */
BytesToLock.u.LowPart = nNumberOfBytesToLockLow;
BytesToLock.u.HighPart = nNumberOfBytesToLockHigh;
Offset.u.LowPart = dwFileOffsetLow;
Offset.u.HighPart = dwFileOffsetHigh;
Status = NtLockFile(hFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
&Offset,
&BytesToLock,
0,
TRUE,
TRUE);
if (Status == STATUS_PENDING)
{
/* Wait for completion if needed */
Status = NtWaitForSingleObject(hFile, FALSE, NULL);
if (NT_SUCCESS(Status)) Status = IoStatusBlock.Status;
}
/* Check if we failed */
if (!NT_SUCCESS(Status))
{
/* Convert the error code and fail */
BaseSetLastNTError(Status);
return FALSE;
}
/* Success! */
return TRUE;
}
示例4: IHF_ActiveDetachProcess
IHFSERVICE DWORD IHFAPI IHF_ActiveDetachProcess(DWORD pid)
{
DWORD module, engine, dwWrite;
HANDLE hProc, hThread, hCmd;
IO_STATUS_BLOCK ios;
//man->LockHookman();
ProcessRecord* pr = man->GetProcessRecord(pid);
hCmd = man->GetCmdHandleByPID(pid);
if (pr == 0 || hCmd == 0) return FALSE;
//hProc = pr->process_handle; //This handle may be closed(thus invalid) during the detach process.
NtDuplicateObject(NtCurrentProcess(), pr->process_handle,
NtCurrentProcess(), &hProc, 0, 0, DUPLICATE_SAME_ACCESS); //Make a copy of the process handle.
module = pr->module_register;
if (module == 0) return FALSE;
engine = pr->engine_register;
engine &= ~0xFF;
SendParam sp = {};
sp.type = 4;
NtWriteFile(hCmd, 0,0,0, &ios, &sp, sizeof(SendParam),0,0);
//cmdq->AddRequest(sp, pid);
dwWrite = 0x1000;
hThread = IthCreateThread(LdrUnloadDll, engine, hProc);
if (hThread == 0 ||
hThread == INVALID_HANDLE_VALUE) return FALSE;
NtWaitForSingleObject(hThread, 0, 0);
NtClose(hThread);
hThread = IthCreateThread(LdrUnloadDll, module, hProc);
if (hThread == 0 ||
hThread == INVALID_HANDLE_VALUE) return FALSE;
NtWaitForSingleObject(hThread, 0, 0);
//man->UnlockHookman();
THREAD_BASIC_INFORMATION info;
NtQueryInformationThread(hThread, ThreadBasicInformation, &info, sizeof(info), 0);
NtClose(hThread);
NtSetEvent(hPipeExist, 0);
FreeThreadStart(hProc);
NtClose(hProc);
dwWrite = 0x1000;
return info.ExitStatus;
}
示例5: PhpTailQueryObjectHack
NTSTATUS PhpTailQueryObjectHack(
__out_opt PULONG ReturnLength
)
{
NTSTATUS status;
LARGE_INTEGER timeout;
PhQueryObjectContext.Initialized = TRUE;
// Allow the worker thread to start.
NtSetEvent(PhQueryObjectStartEvent, NULL);
// Wait for the work to complete, with a timeout of 1 second.
timeout.QuadPart = -1000 * PH_TIMEOUT_MS;
status = NtWaitForSingleObject(PhQueryObjectCompletedEvent, FALSE, &timeout);
PhQueryObjectContext.Initialized = FALSE;
// Return normally if the work was completed.
if (status == STATUS_WAIT_0)
{
ULONG returnLength;
status = PhQueryObjectContext.Status;
returnLength = PhQueryObjectContext.ReturnLength;
PhReleaseQueuedLockExclusive(&PhQueryObjectMutex);
if (ReturnLength)
*ReturnLength = returnLength;
return status;
}
// Kill the worker thread if it took too long.
// else if (status == STATUS_TIMEOUT)
else
{
// Kill the thread.
if (NT_SUCCESS(NtTerminateThread(PhQueryObjectThreadHandle, STATUS_TIMEOUT)))
{
PhQueryObjectThreadHandle = NULL;
// Delete the fiber (and free the thread stack).
DeleteFiber(PhQueryObjectFiber);
PhQueryObjectFiber = NULL;
}
PhReleaseQueuedLockExclusive(&PhQueryObjectMutex);
return STATUS_UNSUCCESSFUL;
}
}
示例6: PhpWfsoThreadStart
static NTSTATUS PhpWfsoThreadStart(
_In_ PVOID Parameter
)
{
HANDLE eventHandle;
LARGE_INTEGER timeout;
eventHandle = Parameter;
timeout.QuadPart = -(LONGLONG)UInt32x32To64(5, PH_TIMEOUT_SEC);
NtWaitForSingleObject(eventHandle, FALSE, &timeout);
return STATUS_SUCCESS;
}
示例7: ClearDumpInfo
void ClearDumpInfo (void)
{
NTSTATUS Status;
//
// Pause profiling?
//
if (fPause) {
Status = NtPulseEvent (hPauseEvent, NULL);
if (!NT_SUCCESS(Status)) {
fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtPulseEvent() "
"failed for PAUSE event - %lx\n", Status);
exit (1);
}
}
//
// Dump data?
//
else if (fDump) {
Status = NtPulseEvent (hDumpEvent, NULL);
if (!NT_SUCCESS(Status)) {
fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtPulseEvent() "
"failed for DUMP event - %lx\n", Status);
exit (1);
}
}
//
// Clear data?
//
else if (fClear) {
Status = NtPulseEvent (hClearEvent, NULL);
if (!NT_SUCCESS(Status)) {
fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtPulseEvent() "
"failed for CLEAR event - %lx\n", Status);
exit (1);
}
}
//
// Wait for the DONE event..
//
Sleep (500);
Status = NtWaitForSingleObject (hDoneEvent, FALSE, NULL);
if (!NT_SUCCESS(Status)) {
fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtWaitForSingleObject() "
"failed for DONE event - %lx\n", Status);
exit (1);
}
} /* ClearDumpInfo() */
示例8: UpdateDotNetTraceInfoWithTimeout
ULONG UpdateDotNetTraceInfoWithTimeout(
__in PASMPAGE_CONTEXT Context,
__in BOOLEAN ClrV2,
__in_opt PLARGE_INTEGER Timeout
)
{
HANDLE threadHandle;
// ProcessDotNetTrace is not guaranteed to complete within any period of time, because
// the target process might terminate before it writes the DCStartComplete_V1 event.
// If the timeout is reached, the trace handle is closed, forcing ProcessTrace to stop
// processing.
Context->TraceClrV2 = ClrV2;
Context->TraceResult = 0;
Context->TraceHandleActive = 0;
Context->TraceHandle = 0;
threadHandle = PhCreateThread(0, UpdateDotNetTraceInfoThreadStart, Context);
if (NtWaitForSingleObject(threadHandle, FALSE, Timeout) != STATUS_WAIT_0)
{
// Timeout has expired. Stop the trace processing if it's still active.
// BUG: This assumes that the thread is in ProcessTrace. It might still be
// setting up though!
if (_InterlockedExchange(&Context->TraceHandleActive, 0) == 1)
{
CloseTrace(Context->TraceHandle);
}
NtWaitForSingleObject(threadHandle, FALSE, NULL);
}
NtClose(threadHandle);
return Context->TraceResult;
}
示例9: FsRtlpRegisterProviderWithMUP
NTSTATUS
FsRtlpRegisterProviderWithMUP(IN HANDLE MupHandle,
IN PCUNICODE_STRING RedirectorDeviceName,
IN BOOLEAN MailslotsSupported)
{
NTSTATUS Status;
ULONG BufferSize;
IO_STATUS_BLOCK IoStatusBlock;
PMUP_PROVIDER_REGISTRATION_INFO RegistrationInfo;
PAGED_CODE();
DPRINT1("FsRtlpRegisterProviderWithMUP(%p, %wZ, %u)\n", (PVOID)MupHandle, RedirectorDeviceName, MailslotsSupported);
/* We have to be able to store the name and the registration information */
BufferSize = RedirectorDeviceName->Length + sizeof(MUP_PROVIDER_REGISTRATION_INFO);
RegistrationInfo = ExAllocatePoolWithTag(NonPagedPool, BufferSize, TAG_UNC);
if (RegistrationInfo == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Set the information about the provider (including its name) */
RegistrationInfo->RedirectorDeviceNameOffset = sizeof(MUP_PROVIDER_REGISTRATION_INFO);
RegistrationInfo->RedirectorDeviceNameLength = RedirectorDeviceName->Length;
RegistrationInfo->MailslotsSupported = MailslotsSupported;
RtlCopyMemory((PWSTR)((ULONG_PTR)RegistrationInfo + RegistrationInfo->RedirectorDeviceNameOffset),
RedirectorDeviceName->Buffer, RedirectorDeviceName->Length);
/* Call MUP with the registration FSCTL */
Status = NtFsControlFile(MupHandle, NULL, NULL, NULL,
&IoStatusBlock, FSCTL_MUP_REGISTER_PROVIDER,
RegistrationInfo, BufferSize, NULL, 0);
if (Status == STATUS_PENDING)
{
Status = NtWaitForSingleObject(MupHandle, TRUE, NULL);
}
if (NT_SUCCESS(Status))
{
Status = IoStatusBlock.Status;
}
/* And we're done! */
ASSERT(NT_SUCCESS(Status));
ExFreePoolWithTag(RegistrationInfo, TAG_UNC);
return Status;
}
示例10: IHF_ModifyHook
IHFSERVICE DWORD IHFAPI IHF_ModifyHook(DWORD pid, HookParam* hp)
{
SendParam sp;
HANDLE hModify,hCmd;
hCmd = GetCmdHandleByPID(pid);
if (hCmd == 0) return -1;
hModify = IthCreateEvent(L"ITH_MODIFY_HOOK");
sp.type = IHF_COMMAND_MODIFY_HOOK;
sp.hp = *hp;
IO_STATUS_BLOCK ios;
if (NT_SUCCESS(NtWriteFile(hCmd, 0,0,0, &ios, &sp, sizeof(SendParam), 0, 0)))
NtWaitForSingleObject(hModify, 0, 0);
NtClose(hModify);
man -> RemoveSingleHook(pid, sp.hp.addr);
return 0;
}
示例11: RtlClipWaitForInput
/*++
* @name RtlClipWaitForInput
*
* The RtlClipWaitForInput routine waits for input from an input device.
*
* @param hDriver
* Handle of the driver/device to get input from.
*
* @param Buffer
* Input buffer.
*
* @param BufferSize
* Size of the input buffer.
*
* @return STATUS_SUCCESS or error code from the read operation.
*
* @remarks This routine waits for input to be available.
*
*--*/
NTSTATUS
RtlClipWaitForInput(IN HANDLE hDriver,
IN PVOID Buffer,
IN OUT PULONG BufferSize)
{
IO_STATUS_BLOCK Iosb;
LARGE_INTEGER ByteOffset;
NTSTATUS Status;
//
// Clean up the I/O Status block and read from byte 0
//
RtlZeroMemory(&Iosb, sizeof(Iosb));
RtlZeroMemory(&ByteOffset, sizeof(ByteOffset));
//
// Try to read the data
//
Status = NtReadFile(hDriver,
hEvent,
NULL,
NULL,
&Iosb,
Buffer,
*BufferSize,
&ByteOffset,
NULL);
//
// Check if data is pending
//
if (Status == STATUS_PENDING)
{
//
// Wait on the data to be read
//
Status = NtWaitForSingleObject(hEvent, TRUE, NULL);
}
//
// Return status and how much data was read
//
*BufferSize = (ULONG)Iosb.Information;
return Status;
}
示例12: WeLockServerSharedData
BOOLEAN WeLockServerSharedData(
__out PWE_HOOK_SHARED_DATA *Data
)
{
LARGE_INTEGER timeout;
if (!WeServerSharedSectionLock)
return FALSE;
timeout.QuadPart = -WE_CLIENT_MESSAGE_TIMEOUT * PH_TIMEOUT_MS;
if (NtWaitForSingleObject(WeServerSharedSectionLock, FALSE, &timeout) != WAIT_OBJECT_0)
return FALSE;
*Data = WeServerSharedData;
return TRUE;
}
示例13: IHF_RemoveHook
IHFSERVICE DWORD IHFAPI IHF_RemoveHook(DWORD pid, DWORD addr)
{
HANDLE hRemoved,hCmd;
hCmd = GetCmdHandleByPID(pid);
if (hCmd == 0) return -1;
hRemoved = IthCreateEvent(L"ITH_REMOVE_HOOK");
SendParam sp = {};
IO_STATUS_BLOCK ios;
sp.type = IHF_COMMAND_REMOVE_HOOK;
sp.hp.addr = addr;
//cmdq -> AddRequest(sp, pid);
NtWriteFile(hCmd, 0,0,0, &ios, &sp, sizeof(SendParam),0,0);
NtWaitForSingleObject(hRemoved, 0, 0);
NtClose(hRemoved);
man -> RemoveSingleHook(pid, sp.hp.addr);
return 0;
}
示例14: ReadConsoleInput
BOOL
WINAPI
ReadConsoleInput(
IN HANDLE hConsoleInput,
OUT PINPUT_RECORD lpBuffer,
IN DWORD nLength,
OUT LPDWORD lpNumberOfEventsRead)
{
LARGE_INTEGER Offset;
IO_STATUS_BLOCK IoStatusBlock;
KEYBOARD_INPUT_DATA InputData;
NTSTATUS Status;
Offset.QuadPart = 0;
Status = NtReadFile(hConsoleInput,
NULL,
NULL,
NULL,
&IoStatusBlock,
&InputData,
sizeof(KEYBOARD_INPUT_DATA),
&Offset,
0);
if (Status == STATUS_PENDING)
{
Status = NtWaitForSingleObject(hConsoleInput, FALSE, NULL);
Status = IoStatusBlock.Status;
}
if (!NT_SUCCESS(Status))
return FALSE;
lpBuffer->EventType = KEY_EVENT;
Status = IntTranslateKey(&InputData, &lpBuffer->Event.KeyEvent);
if (!NT_SUCCESS(Status))
return FALSE;
*lpNumberOfEventsRead = 1;
return TRUE;
}
示例15: GetAddrEntries
static
NTSTATUS
GetAddrEntries(
_In_ HANDLE TcpFile,
_In_ TDIEntityID InterfaceID,
_Out_ IPAddrEntry* Entries,
_In_ ULONG NumEntries)
{
TCP_REQUEST_QUERY_INFORMATION_EX TcpQueryInfo;
IO_STATUS_BLOCK StatusBlock;
NTSTATUS Status;
ZeroMemory(&TcpQueryInfo, sizeof(TcpQueryInfo));
TcpQueryInfo.ID.toi_class = INFO_CLASS_PROTOCOL;
TcpQueryInfo.ID.toi_type = INFO_TYPE_PROVIDER;
TcpQueryInfo.ID.toi_id = IP_MIB_ADDRTABLE_ENTRY_ID;
TcpQueryInfo.ID.toi_entity = InterfaceID;
Status = NtDeviceIoControlFile(
TcpFile,
NULL,
NULL,
NULL,
&StatusBlock,
IOCTL_TCP_QUERY_INFORMATION_EX,
&TcpQueryInfo,
sizeof(TcpQueryInfo),
Entries,
NumEntries * sizeof(Entries[0]));
if (Status == STATUS_PENDING)
{
/* So we have to wait a bit */
Status = NtWaitForSingleObject(TcpFile, FALSE, NULL);
if (NT_SUCCESS(Status))
Status = StatusBlock.Status;
}
return Status;
}