ExCreateHandleEx

VOID *__stdcall ExCreateHandleEx(
        _HANDLE_TABLE *HandleTable,
        VOID *ObjectPointer,
        UINT64 GrantedAccess,
        UINT64 Attributes,
        _HANDLE_TABLE_ENTRY_INFO *ExtraInfo){
  int v5; 
  _ETHREAD *CurrentThread; 
  _HANDLE_TABLE_ENTRY *v8; 
  void *GenericHandleOverlay; 
  _HANDLE_TABLE_ENTRY *v10; 
  __int64 v12; 
  __int64 v13; 
  _EXHANDLE Handle; 

  v5 = GrantedAccess & 0x1FFFFFF;
  HIDWORD(v13) = 0;
  if( (Attributes & 8) != 0 )
    v5 |= 0x2000000u;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  LODWORD(v13) = v5;
  v12 = ((_QWORD)ObjectPointer << 16) ^ (((_DWORD)Attributes << 17) ^ ((_DWORD)ObjectPointer << 16)) & 0xE0000 | 1i64;
  --CurrentThread->Tcb.KernelApcDisable;
  Handle = 0i64;
  v8 = ExpAllocateHandleTableEntry(HandleTable, &Handle);
  GenericHandleOverlay = Handle.GenericHandleOverlay;
  v10 = v8;
  if( v8 )
  {
    if( ExtraInfo
      && (ExtraInfo->AuditMask || ExtraInfo->MaxRelativeAccessMask)
      && ExpSetHandleExtraInfo(HandleTable, Handle.GenericHandleOverlay, ExtraInfo) )
    {
      ExpFreeHandleTableEntry(HandleTable, (_EXHANDLE)GenericHandleOverlay, v10);
      GenericHandleOverlay = 0i64;
    }
    else
    {
      if( HandleTable->DebugInfo )
        ExpUpdateDebugInfo(HandleTable, CurrentThread, GenericHandleOverlay, 1ui64);
      v10->HighValue = v13;
      v10->LowValue = v12;
    }
  }
  KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
  return GenericHandleOverlay;
}

Referenced by:

AlpcpAllocateMessageFromExtendedTables
AlpcpAllocateMessageFunction
ExCreateHandle
ObCompleteObjectDuplication
PspAllocateThread
RtlpInsertStringAtom