KeSetEvent
NTSTATUS __stdcall KeSetEvent(PRKEVENT Event, KPRIORITY Increment, BOOL Wait){
UINT8 OldIrql;
_KPRCB *CurrentPrcb;
NTSTATUS v8;
_KWAIT_BLOCK *v9;
_KWAIT_BLOCK *v10;
_KWAIT_BLOCK *Flink;
_KWAIT_BLOCK *v12;
_KWAIT_BLOCK **Blink;
unsigned __int8 WaitType;
bool v16;
_KWAIT_BLOCK *v17;
unsigned __int8 v18;
INT64 WaitKey;
_KPRCB *v20;
_ETHREAD *v21;
char v22;
int v23;
_ETHREAD **QuantumTarget;
_KPRCB *v25;
_ETHREAD *v26;
char v27;
int v28;
_LIST_ENTRY *v29;
_KPRCB *v30;
_KPRCB *v31;
_KPRCB *Prcb;
_KPRCB *Prcba;
_ETHREAD *CurrentThread;
_ETHREAD *v35;
int Object;
_ETHREAD *Objecta;
_ETHREAD *Objectb;
_KWAIT_BLOCK *Entry;
_KWAIT_BLOCK *Entrya;
if( (*(_BYTE *)Event & 0x7F) != 0 )
{
Object = 0;
LABEL_3:
OldIrql = KeGetCurrentIrql();
__writecr8(2ui64);
CurrentPrcb = KeGetCurrentPrcb();
KiAcquireKobjectLockSafe(Event);
v8 = *((_DWORD *)Event + 1);
*((_DWORD *)Event + 1) = 1;
if( v8 )
{
LABEL_10:
_InterlockedAnd((volatile signed __int32 *)Event, 0xFFFFFF7F);
KiExitDispatcher(CurrentPrcb, Wait ? 3 : 0, AdjustUnwait, (unsigned int)Increment, OldIrql);
return v8;
}
v9 = (_KWAIT_BLOCK *)((char *)Event + 8);
v10 = (_KWAIT_BLOCK *)*((_QWORD *)Event + 1);
if( !Object )
{
if( v10 != v9 )
{
while( 1 )
{
Flink = (_KWAIT_BLOCK *)v10->WaitListEntry.Flink;
v12 = v10;
Entry = v10;
v10 = Flink;
Blink = (_KWAIT_BLOCK **)Entry->WaitListEntry.Blink;
if( (_KWAIT_BLOCK *)Flink->WaitListEntry.Blink != Entry || *Blink != v12 )
goto LABEL_7;
*Blink = Flink;
Flink->WaitListEntry.Blink = (_LIST_ENTRY *)Blink;
WaitType = v12->WaitType;
if( WaitType == 1 )
{
if( KiTryUnwaitThread(CurrentPrcb, v12, v12->WaitKey, 0i64) )
{
v16 = (*((_DWORD *)Event + 1))-- == 1;
if( v16 )
goto LABEL_10;
}
}
else
{
if( WaitType == 2 )
{
v12->BlockState = 5;
Objecta = v12->Thread;
v30 = (_KPRCB *)&Objecta->Tcb.gap0[8];
v12->WaitListEntry.Flink = 0i64;
KeGetCurrentIrql();
__writecr8(2ui64);
Prcb = KeGetCurrentPrcb();
CurrentThread = Prcb->CurrentThread;
KiAcquireKobjectLockSafe(Objecta);
v20 = v30;
v21 = Objecta;
if( *(_KPRCB **)&v20->_MxCsr == v20
|| LODWORD(Objecta->Tcb.InitialStack) >= HIDWORD(Objecta->Tcb.InitialStack)
|| (_ETHREAD *)CurrentThread->Tcb.Queue == Objecta && CurrentThread->Tcb.WaitReason == 15 )
{
LABEL_33:
v23 = *(_DWORD *)&v21->Tcb.gap0[4];
*(_DWORD *)&v21->Tcb.gap0[4] = v23 + 1;
QuantumTarget = (_ETHREAD **)v21->Tcb.QuantumTarget;
if( *QuantumTarget != (_ETHREAD *)&v21->Tcb.SListFaultAddress )
goto LABEL_7;
Entry->WaitListEntry.Flink = (_LIST_ENTRY *)&v21->Tcb.SListFaultAddress;
Entry->WaitListEntry.Blink = (_LIST_ENTRY *)QuantumTarget;
*QuantumTarget = (_ETHREAD *)Entry;
v21->Tcb.QuantumTarget = (unsigned __int64)Entry;
if( !v23 && *(_KPRCB **)&v20->_MxCsr != v20 )
{
KiWakeOtherQueueWaiters(Prcb, (_KQUEUE *)v21);
v21 = Objecta;
}
}
else
{
KiWakeQueueWaiter(Prcb, (_KQUEUE *)Objecta, (INT64)Entry);
v21 = Objecta;
if( !v22 )
{
v20 = (_KPRCB *)&Objecta->Tcb.gap0[8];
goto LABEL_33;
}
}
_InterlockedAnd((volatile signed __int32 *)v21, 0xFFFFFF7F);
v16 = (*((_DWORD *)Event + 1))-- == 1;
if( v16 )
goto LABEL_10;
goto LABEL_49;
}
KiTryUnwaitThread(CurrentPrcb, v12, 256i64, 0i64);
}
LABEL_49:
if( v10 == v9 )
goto LABEL_10;
}
}
goto LABEL_10;
}
if( v10 == v9 )
{
LABEL_9:
*((_QWORD *)Event + 2) = (char *)Event + 8;
v9->WaitListEntry.Flink = &v9->WaitListEntry;
goto LABEL_10;
}
while( 1 )
{
v17 = v10;
v10 = (_KWAIT_BLOCK *)v10->WaitListEntry.Flink;
Entrya = v17;
v18 = v17->WaitType;
if( v18 == 1 )
{
WaitKey = v17->WaitKey;
}
else
{
if( v18 == 2 )
{
v17->BlockState = 5;
Objectb = v17->Thread;
Prcba = (_KPRCB *)&Objectb->Tcb.gap0[8];
v17->WaitListEntry.Flink = 0i64;
KeGetCurrentIrql();
__writecr8(2ui64);
v31 = KeGetCurrentPrcb();
v35 = v31->CurrentThread;
KiAcquireKobjectLockSafe(Objectb);
v25 = Prcba;
v26 = Objectb;
if( *(_KPRCB **)&v25->_MxCsr == v25
|| LODWORD(Objectb->Tcb.InitialStack) >= HIDWORD(Objectb->Tcb.InitialStack)
|| (_ETHREAD *)v35->Tcb.Queue == Objectb && v35->Tcb.WaitReason == 15 )
{
LABEL_44:
v28 = *(_DWORD *)&v26->Tcb.gap0[4];
*(_DWORD *)&v26->Tcb.gap0[4] = v28 + 1;
v29 = (_LIST_ENTRY *)v26->Tcb.QuantumTarget;
if( (void **)v29->Flink != &v26->Tcb.SListFaultAddress )
LABEL_7:
__fastfail(3u);
Entrya->WaitListEntry.Flink = (_LIST_ENTRY *)&v26->Tcb.SListFaultAddress;
Entrya->WaitListEntry.Blink = v29;
v29->Flink = &Entrya->WaitListEntry;
v26->Tcb.QuantumTarget = (unsigned __int64)Entrya;
if( !v28 && *(_KPRCB **)&v25->_MxCsr != v25 )
{
KiWakeOtherQueueWaiters(v31, (_KQUEUE *)v26);
v26 = Objectb;
}
}
else
{
KiWakeQueueWaiter(v31, (_KQUEUE *)Objectb, (INT64)Entrya);
v26 = Objectb;
if( !v27 )
{
v25 = (_KPRCB *)&Objectb->Tcb.gap0[8];
goto LABEL_44;
}
}
_InterlockedAnd((volatile signed __int32 *)v26, 0xFFFFFF7F);
goto LABEL_21;
}
WaitKey = 256i64;
}
KiTryUnwaitThread(CurrentPrcb, v17, WaitKey, 0i64);
LABEL_21:
if( v10 == v9 )
goto LABEL_9;
}
}
if( *((_DWORD *)Event + 1) != 1 || Wait )
{
Object = 1;
goto LABEL_3;
}
return 1;
}Referenced by:
AlpcpCompleteDispatchMessage
AlpcpSignal
AlpcpSignalAndWait
AlpcpTrackPortReferences
AnFwpFadeAnimationTimer
ArbArbiterHandler
ArbBuildAssignmentOrdering
CMFSystemThreadRoutine
CcCanIWrite
CcCancelMmWaitForUninitializeCacheMap
CcDeleteBcbs
CcDeletePartition
CcDeleteSharedCacheMap
CcDereferencePartition
CcFlushCachePriv
CcFreeVirtualAddress
CcInitializeCacheMapEx
CcMapAndCopyInToCache
CcNotifyWriteBehindInternal
CcPinFileData
CcPostDeferredWrites
CcPostWorkQueueAsyncRead
CcPrepareMdlWrite
CcPurgeAndClearCacheSection
CcUninitializeCacheMap
CcUnpinFileDataEx
CcWorkerThread
CcWriteBehindInternal
CmLoadAppKey
CmNotifyRunDown
CmThawRegistry
CmpCompleteUnloadKey
CmpFinishSystemHivesLoad
CmpGetVolumeClusterSizeCompletion
CmpInitializeSystemHivesLoad
CmpLazyFlushDpcRoutine
CmpLoadHiveThread
CmpMachineHiveLoadedWorkItem
CmpPostApc
CmpPostApcRunDown
CmpPostNotify
CmpWaitForHiveMount
CmpWakeWriteQueueWaiters
DbgkRegisterErrorPort
DbgkpCloseObject
DbgkpLkmdSnapThreadApc
DbgkpQueueMessage
DbgkpSetProcessDebugObject
DbgkpWakeTarget
EmpReleasePagingReference
EtwInitialize
EtwSendTraceBuffer
EtwpCovSampCaptureCleanupLookasides
EtwpCovSampCaptureContextSetPaused
EtwpCovSampCaptureQueueBuffer
EtwpCovSampCaptureQueueDpc
EtwpCovSampCaptureRebalanceDpc
EtwpCovSampCaptureWorkerThread
EtwpCovSampHashMakeRoomAndAcquireLock
EtwpDisassociateConsumer
EtwpFreeLoggerContext
EtwpLogger
EtwpLoggerDpc
EtwpQueueNotification
EtwpRealtimeDisconnectAllConsumers
EtwpRealtimeInjectEtwBuffer
EtwpStopLoggerInstance
EtwpSwitchBuffer
EtwpSynchronizeWithLogger
EtwpThreadRundownApc
ExCompareExchangeCallBack
ExNotifyBootDeviceRemoval
ExNotifyWithProcessing
ExReferenceCallBackBlock
ExRegisterBootDevice
ExReleaseRundownProtectionCacheAware
ExReleaseRundownProtectionCacheAwareEx
ExReleaseRundownProtectionEx
ExfReleaseRundownProtection
ExpEnumerateCallback
ExpPartitionCreatePool
ExpPartitionCreateThreadIfNecessary
ExpPartitionDestroy
ExpQueueWorkItem
ExpSetSwappingKernelApc
ExpUnblockPushLock
ExpWakePushLock
ExpWnfNotifyNameSubscribers
ExpWnfNotifySubscription
ExpWorkQueueManagerReaperTimer
ExpWorkerThread
FsFilterFreeCompletionStack
FsRtlStackOverflowRead
FsRtlpOplockWaitCompleteRoutine
HalGetAdapterV2
HalGetAdapterV3
HalpDynamicDeviceInterfaceNotification
HalpGetDynamicDevicePointer
HalpProcessSecondarySignalList
HalpReleaseSecondaryIcEntryExclusive
HalpReleaseSecondaryIcEntryShared
IoAcquireRemoveLockEx
IoReleaseRemoveLockEx
IoVerifyVolume
IopAcquireReleaseConnectLockInternal
IopAcquireReleaseDispatcherLock
IopCancelIrpsInCurrentThreadListApcRoutine
IopCancelIrpsInCurrentThreadListSpecialApc
IopCompleteRequest
IopConnectLinkTrackingPort
IopDestroyActiveConnectBlock
IopFreeBackpocketIrp
IopFreeReserveIrp
IopInvalidateVolumesForDevice
IopLoadUnloadDriver
IopMountVolume
IopSendMessageToTrackService
IopTrackLink
IopWarmEjectDevice
IopXxxControlFile
IopfCompleteRequest
KdpTimeSlipWork
KeAbCrossThreadDeleteDpcRoutine
KeBalanceSetManager
KeRetryOutswapProcess
KeUpdateUmsThreadState
KiBalanceSetManagerDeferredRoutine
KiBlockAndActivateUmsThread
KiConnectSecondaryInterrupt
KiDecrementProcessStackCount
KiDetachProcess
KiDisconnectSecondaryInterrupt
KiExitDispatcher
KiInvokeInterruptServiceRoutine
KiPassiveIsrWatchdog
KiProcessDisconnectList
KiReadyThread
KiRequestProcessInSwap
KiSignalWaitDisconnectLock
KiSynchronizePassiveInterruptExecution
LZNT1DecompressChunkWorkItem
MUIRegistrySystemRoutine
MiAddZeroingThreads
MiAllocatePfnRepurposeLogDispatch
MiAttemptPageFileReductionApc
MiCompleteProtoPteFault
MiCopyDataPageToImagePage
MiCopyFileOnlyGlobalSubsectionPage
MiCopyImageExtentContents
MiDecreaseAvailablePages
MiDecrementCloneHeaderCount
MiDecrementControlAreaCount
MiDecrementVadsBeingDeleted
MiDeleteCloneDescriptor
MiDeletePartitionResources
MiDereferenceSessionFinal
MiFinishHardFault
MiFinishHoldingDirtyFaults
MiFinishPageFileExtension
MiFinishResume
MiFinishVadDeletion
MiFlushAllFilesystemPages
MiFlushAllHintedStorePages
MiFlushAllPagesWorker
MiFlushComplete
MiFreeExcessSegments
MiFreeOverlappedFlushEntry
MiHandleTransitionFault
MiInSwapStoreWorker
MiIncreaseAvailablePages
MiInitializePagedPoolEvents
MiInsertLargePageInNodeList
MiInsertPageFileInList
MiInsertPageInFreeOrZeroedList
MiInsertPageInList
MiInsertProtectedStandbyPage
MiInsertUnusedSubsection
MiIrpCompletionApcRoutine
MiIssueHardFaultIo
MiMakeOutswappedPageResident
MiMarkMdlComplete
MiMarkSessionDeletePending
MiModifiedPageWriter
MiObtainFreePages
MiPageNotZero
MiPfCompleteCoalescedIo
MiPfExecuteReadList
MiPfIssueCoalescedSupport
MiPrivateFixup
MiProcessDereferenceList
MiProcessWorkingSets
MiProcessingPageExtendComplete
MiQueueControlAreaDelete
MiQueuePageAccessLog
MiQueueWorkingSetRequest
MiReAcquireOutSwappedProcessCommit
MiReclaimSystemVa
MiReduceZeroingThreads
MiReleaseCommitForResetPages
MiReleasePageFileInfo
MiResolveTransitionFault
MiReturnCrossPartitionCharges
MiShutdownSystem
MiSignalNonPagedPoolWatchers
MiStoreEvictThread
MiStoreSetEvictPageFile
MiStoreUpdateMemoryConditions
MiSyncCommitSignals
MiTrimUnusedPageFileRegionsApc
MiUnlinkFreeOrZeroedPage
MiUnlinkPageFromList
MiUpdateAvailableEvents
MiWakeModifiedPageWriter
MiWakePageZeroing
MiWakeZeroingThreads
MiWorkingSetManager
MiWriteComplete
MiZeroAllPageFiles
MiZeroNodePages
MiZeroPageCalibrate
MiZeroPageFile
MmDuplicateMemory
MmSetSessionObjectIoEvent
MmStoreFlushOutstandingEvictions
MmStoreRegister
NtDebugContinue
NtLockFile
NtNotifyChangeSession
NtReadFile
NtSetEvent
NtSignalAndWaitForSingleObject
NtWaitForWorkViaWorkerFactory
NtWriteFile
PfFileInfoNotify
PfGenerateTrace
PfGetCompletedTrace
PfSnEndTrace
PfSnReferenceProcessTrace
PfSnRemoveProcessTrace
PfSnTracingStateExWorkerRoutine
PfTCleanup
PfTLoggingWorker
PfTReplaceCurrentBuffer
PfTTraceListAdd
PfpEventHandleFullBuffer
PfpParametersWatcher
PfpReturnAccessBuffer
PfpScenCtxPrefetchStateSet
PfpScenCtxScenarioSet
PfpScenCtxWaiterTimedOut
PiDrvDbLoadNodeWorkerCallback
PiUEventDereferenceEventEntry
PiUEventHandleVetoEvent
PnpCompleteDeviceEvent
PnpCompleteSystemStartProcess
PnpDeviceActionWorker
PnpDeviceEventWorker
PnpDiagnosticCompletionRoutine
PnpRemoveDeviceActionRequests
PnpShutdownDevices
PnpUnlockDeviceActionQueue
PnpUnlockMountableDevice
PnprInitiateReplaceOperation
PnprQuiesce
PnprQuiesceWorker
PoFxNotifySurprisePowerOn
PoFxPowerControl
PoFxPrepareDevice
PopBatteryIrpComplete
PopBatteryReadTag
PopBatteryWakeDpc
PopBuildDeviceNotifyListWatchdog
PopCheckPowerSourceAfterRtcWakeCancel
PopCheckPowerSourceAfterRtcWakeTimerWorker
PopCompleteAction
PopCompleteNotifyTransitionCommon
PopDeviceIdleCompletion
PopEndMirroring
PopFanWorker
PopFinalizeWakeInfo
PopFlushVolumeWorker
PopFxAcpiForwardNotification
PopFxAcpiForwardPepAcpiNotifyRequest
PopFxAcpiForwardPepWorkRequest
PopFxActivateDevice
PopFxAllocatePowerIrp
PopFxClearDeviceConstraints
PopFxCompleteComponentActivation
PopFxCompleteComponentPerfState
PopFxCompleteDirectedPowerTransition
PopFxComponentPerfWork
PopFxComponentWork
PopFxDestroyDirectedDripsCandidateDeviceList
PopFxDeviceWork
PopFxDirectedPowerTransitionWorker
PopFxPlatformIdleVeto
PopFxProcessWork
PopFxProcessorIdleVeto
PopFxReleaseAcpiRefDevice
PopFxReleaseDevice
PopFxReleasePowerIrp
PopFxUnregisterDevice
PopFxUnregisterDeviceOrWait
PopFxUpdatePlatformIdleState
PopFxUpdateProcessorIdleState
PopFxUpdateVetoMaskWork
PopGracefulShutdown
PopHandleWakeSources
PopIrpWorker
PopPepCompleteComponentIdleStateChangeActivity
PopPepStartDeviceUnregisterActivity
PopPepUpdateConstraints
PopPowerAggregatorSystemTransitionEnterStateHandler
PopPropogateCoolingChange
PopQueueDirectedDripsWork
PopQueueTargetDpc
PopReleaseTransitionLock
PopRequestCompletion
PopRequestPowerIrp
PopThermalWorker
PopTimestampTargetProcessor
PopTransitionSystemPowerStateEx
PopTransitionToSleep
PopUnregisterPowerSettingCallback
PopUpdateWakeSourceWorker
PopUpdateWatchdogNoWorkersEvent
PopUserPresentSetWorker
PpmReleaseLock
PsDispatchIumService
PsIsVsmEnclaveTerminated
PsTerminateVsmEnclave
PspDeferredWorkerRoutine
PspDeleteServerSiloGlobals
PspEvaluateAndNotifyEmptyJob
PspReleaseEnclaveThread
PspSetVmProcessorHostProcessWorkerRoutine
RtlDecompressBufferLZNT1
RtlDecompressFragmentLZNT1
RtlpCtSelfSubscribe
SMKM_STORE::SmStCleanup
SMKM_STORE::SmStReadThread
SMKM_STORE::SmStWorkItemQueue
SMKM_STORE::SmStWorker
SMKM_STORE_MGR::SmCompressContextQueueEntry
SMKM_STORE_MGR::SmCompressCtxCleanup
SMKM_STORE_MGR::SmCompressCtxWorkerThread
SMKM_STORE_MGR::SmFeEvictComplete
SPCallServerHandleQueryPolicy
SbpVmbusNotificationHandler
SepRmCallLsa
SmFpFree
SmIoRequestComplete
SmKmGenericCompletion
SmKmStoreDeleteWhenEmptyWorker
SmKmStoreHelperSendCommand
SmKmStoreHelperWorker
SmcCacheAdd
SmcCacheDelete
SmpDeviceIoCompletion
SmpFlushStorePages
SmpIoCompletionApc
TlgAggregateInternalFlushWorkItemRoutineKernelMode
TtmiCloseEventQueue
TtmiWriteEventToSingleQueue
VfPoolDelayFreeIfPossible
ViFilterRemoveNotificationCompletion
ViIrpSynchronousCompletionRoutine
ViPendingQueuePassiveLevelCompletion
WdtpBarkWorkerThread
WheaLogInternalEvent
WheapAttemptPhysicalPageOfflineWorker
WheapEtwEnableCallback
WheapProcessWorkQueueItem
WmipAddDataSource
WmipQueueNotification
WmipReleaseCollectionEnabled
WmipUnreferenceRegEntry