PspAllocatePartition

INT64 __fastcall PspAllocatePartition(INT64 a1, INT64 a2, INT8 a3, INT64 a4, CHAR a5, _QWORD *a6, _QWORD *a7){
  CHAR v8; 
  char v9; 
  int PartitionSystemProcess; 
  _QWORD *v11; 
  _QWORD *v13; 
  PVOID v14; 
  signed __int64 v15; 
  bool v16; 
  signed __int64 v17; 
  __int64 v18; 
  __int64 v19; 
  PVOID Object; 
  UINT64 DesiredAccess; 
  PVOID Handle; 
  _QWORD *v23; 
  _KAPC_STATE ApcState; 
  LODWORD(DesiredAccess) = a2;
  v23 = a7;
  v8 = 0;
  memset(&ApcState, 0, sizeof(ApcState));
  Handle = 0i64;
  v9 = 0;
  Object = 0i64;
  PartitionSystemProcess = ObCreateObjectEx(a3, PsPartitionType, a1, a3, v18, 128, 0, 0, &Object, 0i64);
  if( PartitionSystemProcess < 0 )
  {
    v11 = Object;
    goto LABEL_9;
  }
  v9 = 1;
  v11 = Object;
  memset((INT64)Object, 0i64);
  v11[3] = 2i64;
  ObfReferenceObjectWithTag(v11, 0x64726148u);
  v11[4] = 1i64;
  v11[12] = 0i64;
  if( a4 )
  {
    if( _InterlockedIncrement64((volatile signed __int64 *)(a4 + 24)) <= 1 )
      __fastfail(0xEu);
    v11 = Object;
    *((_QWORD *)Object + 7) = a4;
  }
  else
  {
    if( a5 )
      goto LABEL_4;
    if( _InterlockedIncrement64((volatile signed __int64 *)PspSystemPartition + 3) <= 1 )
      __fastfail(0xEu);
    v11 = Object;
    *((_QWORD *)Object + 7) = PspSystemPartition;
  }
  if( !a5 )
  {
    KiStackAttachProcess(PsInitialSystemProcess, 0i64, &ApcState);
    PartitionSystemProcess = PspCreatePartitionSystemProcess((PVOID *)v11 + 13, v11 + 14);
    KiUnstackDetachProcess(&ApcState, 0i64);
    if( PartitionSystemProcess < 0 )
      goto LABEL_9;
    PartitionSystemProcess = ExpPartitionInitialize((INT64)v11);
    if( PartitionSystemProcess < 0 )
      goto LABEL_9;
    goto LABEL_5;
  }
LABEL_4:
  v8 = 1;
LABEL_5:
  PartitionSystemProcess = MmCreatePartition(v11, v8);
  if( PartitionSystemProcess < 0 )
    goto LABEL_9;
  PspAddPartitionToGlobalList(v11);
  if( a5 )
  {
    *((_DWORD *)v11 + 30) |= 1u;
    *a6 = v11;
    v11 = 0i64;
    Object = 0i64;
LABEL_8:
    PartitionSystemProcess = 0;
    goto LABEL_9;
  }
  PartitionSystemProcess = ExpPartitionStart(v11[2]);
  if( PartitionSystemProcess >= 0 )
  {
    LODWORD(v19) = 0;
    v9 = 0;
    PartitionSystemProcess = ObInsertObjectEx(v11, 0i64, (unsigned int)DesiredAccess, 0i64, v19, 0i64, &Handle);
    if( PartitionSystemProcess >= 0 )
    {
      v13 = v23;
      v14 = Handle;
      *a6 = v11;
      *v13 = v14;
      goto LABEL_8;
    }
  }
LABEL_9:
  if( v11 )
  {
    if( v9 )
      HalPutDmaAdapter((PADAPTER_OBJECT)v11);
    v15 = _InterlockedExchangeAdd64(v11 + 4, 0xFFFFFFFFFFFFFFFFui64);
    v16 = v15 <= 1;
    v17 = v15 - 1;
    if( v16 )
    {
      if( v17 )
        __fastfail(0xEu);
      PsDereferencePartition((INT64)Object);
    }
    if( PartitionSystemProcess < 0 )
      PsDereferencePartition((INT64)Object);
  }
  return(unsigned int)PartitionSystemProcess;
}

Referenced by:

NtCreatePartition
PspInitializeSystemPartitionPhase0