RtlRunOnceComplete

NTSTATUS __stdcall RtlRunOnceComplete(_RTL_RUN_ONCE *RunOnce, UINT64 Flags, VOID *Context){
  unsigned int v4; 
  signed __int64 Value; 
  unsigned __int64 v7; 
  __int64 v8; 
  __int64 v9; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  _ETHREAD *v12; 
  unsigned __int64 v13; 

  if( (((_DWORD)Flags - 1) & (unsigned int)Flags) != 0 || (Flags & 0xFFFFFFF9) != 0 )
    return -1073741584;
  v4 = ~(unsigned __int8)((unsigned int)Flags >> 1) & 3;
  if( Context && (((unsigned __int8)Context & 3) != 0 || (v4 & 2) == 0) )
    return -1073741583;
  _m_prefetchw(RunOnce);
  Value = RunOnce->Value;
  v7 = RunOnce->Value & 3;
  v8 = (unsigned __int64)Context & 0xFFFFFFFFFFFFFFFCui64 | (v4 >= 2 ? 2 : 0);
  if( v7 == 1 )
  {
    if( (v4 & 1) != 0 )
    {
      v9 = _InterlockedExchange64((volatile __int64 *)RunOnce, v8);
      if( (v9 & 3) == 1 )
      {
        v10 = v9 & 0xFFFFFFFFFFFFFFFCui64;
        if( v10 )
        {
          do
          {
            v11 = *(_QWORD *)v10;
            v12 = *(_ETHREAD **)(v10 + 24);
            _interlockedbittestandset((volatile signed __int32 *)(v10 + 36), 2u);
            KeAlertThreadByThreadId(&v12->Tcb);
            v10 = v11;
          }
          while( v11 );
        }
        return 0;
      }
      return -1073741734;
    }
    return -1073741584;
  }
  if( v7 != 3 )
    return -1073741823;
  if( (v4 & 1) != 0 )
    return -1073741584;
  v13 = RunOnce->Value;
  if( v13 == _InterlockedCompareExchange64((volatile signed __int64 *)RunOnce, v8, Value) )
    return 0;
  return -1073741771;
}

Referenced by:

RtlRunOnceExecuteOnce