KeWaitForGate

INT64 __stdcall KeWaitForGate(PVOID PcValue, INT8 a2){
  _ETHREAD *CurrentThread; 
  _KWAIT_REASON v3; 
  _QWORD *v5; 
  unsigned __int8 CurrentIrql; 
  unsigned int v7; 
  unsigned int v8; 
  PVOID *v9; 
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v3 = a2;
  v5 = (_QWORD *)((char *)CurrentThread + 320);
  do
  {
    CurrentIrql = KeGetCurrentIrql();
    __writecr8(2ui64);
    *((_BYTE *)CurrentThread + 390) = CurrentIrql;
    KiBeginThreadWait(CurrentThread, 0, v3, 0);
    v8 = v7;
    if( v7 )
      break;
    *((_BYTE *)CurrentThread + 336) = 1;
    *((_BYTE *)CurrentThread + 337) = 4;
    *((_WORD *)CurrentThread + 169) = 0;
    *((_QWORD *)CurrentThread + 44) = PcValue;
    KiAcquireKobjectLockSafe(PcValue);
    if( *((_DWORD *)PcValue + 1) )
    {
      *((_DWORD *)PcValue + 1) = 0;
      _InterlockedAnd((volatile signed __int32 *)PcValue, 0xFFFFFF7F);
      KiFastExitThreadWait((__int64)KeGetCurrentPrcb(), (__int64)CurrentThread, 0);
      return v8;
    }
    v9 = (PVOID *)*((_QWORD *)PcValue + 2);
    if( *v9 != (char *)PcValue + 8 )
      __fastfail(3u);
    *v5 = (char *)PcValue + 8;
    *((_QWORD *)CurrentThread + 41) = v9;
    *v9 = v5;
    *((_QWORD *)PcValue + 2) = v5;
    _InterlockedAnd((volatile signed __int32 *)PcValue, 0xFFFFFF7F);
    *((_BYTE *)CurrentThread + 587) = 1;
    v8 = KiCommitThreadWait((__int64)CurrentThread, (__int64 *)CurrentThread + 40, 0, 0i64, 0i64);
  }
  while( v8 == 256 );
  return v8;
}

Referenced by:

KiEpfStart
KiExecuteDpc
MiAttemptSectionDelete
MiChangingSubsectionProtos
MiCheckPurgeAndUpMapCount
MiDrainControlAreaWrites
MiFreeUnusedPfnPages
MiIncrementAweMapCount
MiIncrementLargeSubsections
MiLockControlAreaSectionExtend
MiMappedPageWriter
MiMarkSessionDeletePending
MiReferenceControlArea
MiTryUnlinkNodeLargePage
MiUnlinkNodeLargePages
MiUnlinkWorkingSet
MiWaitForExtentDeletions
MiWaitForPageWriteCompletion
MiWaitForVadDeletion
MiZeroBootLargePages
MiZeroInParallel
MiZeroNodePages
MmOutSwapProcess
MmScrubMemory
PspGetContextThreadInternal
PspQueryWorkingSetWatch
PspRundownUmsThreadForApcDelivery
PspSetContextThreadInternal