MiReferenceControlAreaFile

_FILE_OBJECT *__stdcall MiReferenceControlAreaFile(_CONTROL_AREA *ControlArea){
  _EX_FAST_REF *p_FilePointer; 
  signed __int64 Object; 
  signed __int64 v4; 
  _FILE_OBJECT *v5; 
  UINT64 v6; 
  volatile int *p_ControlAreaLock; 
  unsigned __int64 v9; 
  _FILE_OBJECT *v10; 
  signed __int64 Value; 
  signed __int64 v12; 
  void *BugCheckParameter4; 

  p_FilePointer = &ControlArea->FilePointer;
  _m_prefetchw(&ControlArea->FilePointer);
  Object = (signed __int64)ControlArea->FilePointer.Object;
  if( (Object & 0xF) != 0 )
  {
    do
    {
      v4 = _InterlockedCompareExchange64((volatile signed __int64 *)p_FilePointer, Object - 1, Object);
      if( Object == v4 )
        break;
      Object = v4;
    }
    while( (v4 & 0xF) != 0 );
  }
  v5 = (_FILE_OBJECT *)(Object & 0xFFFFFFFFFFFFFFF0ui64);
  v6 = Object & 0xF;
  if( (unsigned int)v6 <= 1 )
  {
    if( !(_DWORD)v6 )
      goto LABEL_7;
    ObReferenceObjectExWithTag(v5, 0xFui64, v6);
    _m_prefetchw(p_FilePointer);
    Value = p_FilePointer->Value;
    while( (Value & 0xF) == 0 )
    {
      if( v5 != (_FILE_OBJECT *)(Value & 0xFFFFFFFFFFFFFFF0ui64) )
        break;
      v12 = Value;
      Value = _InterlockedCompareExchange64((volatile signed __int64 *)p_FilePointer, Value + 15, Value);
      if( v12 == Value )
        goto LABEL_4;
    }
    ObpTraceObjectDereferenceIfActive((_OBJECT_HEADER *)&v5[-1].gap80[40], 0xFui64, 0x746C6644ui64);
    BugCheckParameter4 = (void *)(_InterlockedExchangeAdd64(
                                    (volatile signed __int64 *)&v5[-1].gap80[40],
                                    0xFFFFFFFFFFFFFFF1ui64)
                                - 15);
    if( (__int64)BugCheckParameter4 <= 0 )
    {
      if( v5[-1].CompletionContext )
        KeBugCheckEx(
          0x18u,
          (PVOID)ObTypeIndexTable[(unsigned __int8)ObHeaderCookie ^ LOBYTE(v5[-1].IrpList.Flink) ^ (unsigned __int64)(unsigned __int8)((unsigned __int16)((_WORD)v5 - 48) >> 8)],
          v5,
          (PVOID)6,
          v5[-1].CompletionContext);
      if( (__int64)BugCheckParameter4 < 0 )
        KeBugCheckEx(0x18u, 0i64, v5, (PVOID)5, BugCheckParameter4);
      ObpDeferObjectDeletion((_OBJECT_HEADER *)&v5[-1].gap80[40]);
    }
  }
LABEL_4:
  if( v5 )
    return v5;
LABEL_7:
  p_ControlAreaLock = &ControlArea->ControlAreaLock;
  v9 = (unsigned __int8)ExAcquireSpinLockShared((INT64 *)&ControlArea->ControlAreaLock);
  v10 = (_FILE_OBJECT *)ObFastReferenceObjectLocked(p_FilePointer);
  ExReleaseSpinLockSharedFromDpcLevel(p_ControlAreaLock);
  __writecr8(v9);
  return v10;
}

Referenced by:

DbgkCreateThread
MiAllocateFileExtents
MiAllowImageMap
MiCompleteRestrictedImageFault
MiCreateSectionCommon
MiDeprioritizeVad
MiDriverLoadSucceeded
MiFillMapFileInfo
MiFlushSectionInternal
MiGatherMappedPages
MiLoadUserSymbols
MiLogRelocationFaults
MiMakeSystemCachePteValid
MiMakeSystemCacheRangeValid
MiMapImageForEnclaveUse
MiMapImageInSystemSpace
MiMapViewOfImageSection
MiParseComAndCetHeaders
MiParseImageLoadConfig
MiReferenceInPageFile
MiUnmapVad
MiWriteComplete
MmEnumerateAddressSpaceAndReferenceImages
MmExtendSection
MmFlushSection
MmFlushVirtualMemory
MmGetFileNameForAddress
MmGetFileNameForSection
MmGetFileObjectForSection
MmIsFileMapped
MmLoadSystemImageEx
MmQueryVirtualMemory
MmSectionToSectionObjectPointers
NtAreMappedFilesTheSame
PsReferenceProcessFilePointer
PspInitializeFullProcessImageName