KiInsertQueueInternal

VOID __stdcall KiInsertQueueInternal(_KQUEUE *Queue, _LIST_ENTRY *Entry){
  _QWORD *v2; 
  struct _KPRCB *CurrentPrcb; 
  _ETHREAD *CurrentThread; 
  char v7; 
  int v8; 
  _LIST_ENTRY *v9; 

  Entry->Flink = 0i64;
  v2 = (_QWORD *)((char *)Queue + 8);
  KeGetCurrentIrql();
  __writecr8(2ui64);
  CurrentPrcb = KeGetCurrentPrcb();
  CurrentThread = CurrentPrcb->CurrentThread;
  KiAcquireKobjectLockSafe(Queue);
  if( (_QWORD *)*v2 == v2
    || *((_DWORD *)Queue + 10) >= *((_DWORD *)Queue + 11)
    || (_KQUEUE *)CurrentThread->Tcb.Queue == Queue && CurrentThread->Tcb.WaitReason == 15
    || (KiWakeQueueWaiter(CurrentPrcb, Queue, (INT64)Entry), !v7) )
  {
    v8 = *((_DWORD *)Queue + 1);
    *((_DWORD *)Queue + 1) = v8 + 1;
    v9 = (_LIST_ENTRY *)*((_QWORD *)Queue + 4);
    if( v9->Flink != (_LIST_ENTRY *)((char *)Queue + 24) )
      __fastfail(3u);
    Entry->Flink = (_LIST_ENTRY *)((char *)Queue + 24);
    Entry->Blink = v9;
    v9->Flink = Entry;
    *((_QWORD *)Queue + 4) = Entry;
    if( !v8 && (_QWORD *)*v2 != v2 )
      KiWakeOtherQueueWaiters(CurrentPrcb, Queue);
  }
  _InterlockedAnd((volatile signed __int32 *)Queue, 0xFFFFFF7F);
}

Referenced by:

KiWakeOtherQueueWaiters