MiInsertSlabEntry

VOID __stdcall MiInsertSlabEntry(_IRP *Irp, _DEVICE_OBJECT *DeviceObject){
  UINT64 v2; 
  UINT64 v4; 
  unsigned __int8 v6; 
  UINT64 v7; 
  unsigned __int64 v8; 
  BOOL v9; 
  int v10; 
  UINT64 v11; 
  _DEVICE_OBJECT *AttachedDevice; 
  unsigned int v13; 

  v4 = v2;
  v6 = ExAcquireSpinLockExclusive((INT64 *)&DeviceObject->NextDevice);
  v7 = *(_QWORD *)&DeviceObject->Type;
  v8 = v6;
  if( ((__int64)DeviceObject->DriverObject & 1) != 0 && v7 )
    v7 ^= (unsigned __int64)DeviceObject;
  v9 = 0;
  v10 = (__int64)DeviceObject->DriverObject & 1;
  if( v7 )
  {
    while( 1 )
    {
      if( (int)MiCompareSlabEntry((_QWORD *)(v4 + 24), v7) < 0 )
      {
        v11 = *(_QWORD *)v7;
        if( v10 )
        {
          if( !v11 )
            goto LABEL_15;
          v11 ^= v7;
        }
        if( !v11 )
        {
LABEL_15:
          v9 = 0;
          break;
        }
      }
      else
      {
        v11 = *(_QWORD *)(v7 + 8);
        if( v10 )
        {
          if( !v11 )
            goto LABEL_16;
          v11 ^= v7;
        }
        if( !v11 )
        {
LABEL_16:
          v9 = 1;
          break;
        }
      }
      v7 = v11;
    }
  }
  RtlRbInsertNodeEx((UINT64 *)DeviceObject, v7, v9, v4);
  AttachedDevice = DeviceObject->AttachedDevice;
  if( !AttachedDevice || (v13 = *(_DWORD *)(v4 + 132), *(_DWORD *)&AttachedDevice->gap4D[55] > v13) && v13 )
    DeviceObject->AttachedDevice = (_DEVICE_OBJECT *)v4;
  DeviceObject->CurrentIrp = (_IRP *)((char *)DeviceObject->CurrentIrp + *(unsigned int *)(v4 + 132));
  ++DeviceObject->Timer;
  _InterlockedExchangeAdd64((volatile signed __int64 *)&Irp[36].Tail.DriverContext[3], 0x200ui64);
  if( *(_DWORD *)(v4 + 132) == 512 )
  {
    *(_QWORD *)&DeviceObject->gap4D[27] = KiQueryUnbiasedInterruptTime(1u);
    LODWORD(DeviceObject->Vpb) |= 1u;
  }
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&DeviceObject->NextDevice);
  __writecr8(v8);
}

Referenced by:

MiCreateBootSlabEntries
MiReplenishSlabAllocator
MmUpdateSlabRangeProtection