CmpTransMgrPrepare

__int64 __fastcall CmpTransMgrPrepare(__int64 a1, __int64 a2, _DWORD *a3, _BYTE *a4){
  char v8; 
  __int64 v9; 
  __int64 v10; 
  _CMHIVE *i; 
  _CMHIVE *NextActiveHive; 
  _CMHIVE *v13; 
  NTSTATUS v14; 
  ULONG_PTR v15; 
  NTSTATUS v17; 
  struct _EX_RUNDOWN_REF *v18; 
  CHAR v19; 
  EVENT_DESCRIPTOR *v20; 
  LIST_ENTRY *ListIterator; 
  KAPC_STATE ApcState; 
  *a4 = 0;
  *a3 = 0;
  memset(&ApcState, 0, sizeof(ApcState));
  LOCK_TRANSACTION_LIST();
  v8 = 1;
  *(_DWORD *)(a2 + 48) |= 1u;
  UNLOCK_TRANSACTION_LIST();
  if( *(_QWORD *)(a2 + 16) == a2 + 16 )
  {
    *a4 = 1;
    return 0;
  }
  CmpAttachToRegistryProcess(&ApcState);
  CmpLockRegistry();
  ListIterator = 0i64;
  while( 1 )
  {
    LODWORD(v9) = CmListGetNextElement((LIST_ENTRY *)(a2 + 16), &ListIterator, 0i64);
    if( !v9 )
      break;
    if( *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v9 + 48) + 32i64) + 4192i64) == a1 )
      ++*a3;
  }
  v10 = *(_QWORD *)(a1 + 80);
  if( v10 )
  {
    if( ExAcquireRundownProtection((PEX_RUNDOWN_REF)(v10 + 1632)) )
    {
      CmpUnlockRegistry();
      v17 = CmpTransMgrSyncHive((_CMHIVE *)v10);
      v18 = (struct _EX_RUNDOWN_REF *)(v10 + 1632);
      v14 = v17;
      ExReleaseRundownProtection(v18);
      goto LABEL_18;
    }
    v14 = 0;
  }
  else
  {
    for( i = 0i64; ; i = v13 )
    {
      NextActiveHive = CmpGetNextActiveHive(i);
      v13 = NextActiveHive;
      if( !NextActiveHive )
        break;
      if( *((_QWORD *)NextActiveHive + 524) == a1
        && (*((_DWORD *)NextActiveHive + 40) & 2) == 0
        && CmpIsHiveBoundToTrans((__int64)NextActiveHive, a2) )
      {
        CmpUnlockRegistry();
        v14 = CmpTransMgrSyncHive(v13);
        if( v14 < 0 )
        {
          CmpQuitNextActiveHive((struct _EX_RUNDOWN_REF *)v13);
          goto LABEL_18;
        }
        CmpLockRegistry();
      }
    }
    v15 = Hive;
    if( (*(_DWORD *)(*(_QWORD *)(Hive + 64) + 144i64) & 1) != 0 )
    {
LABEL_16:
      v14 = 0;
      if( !v8 )
        goto LABEL_18;
      goto LABEL_17;
    }
    HvLockHiveFlusherExclusive(Hive);
    HvLockHiveWriter(v15);
    v19 = HvMarkDirty(v15, 0i64, 32i64);
    HvUnlockHiveWriter(v15);
    if( v19 )
    {
      *(_DWORD *)(*(_QWORD *)(v15 + 64) + 144i64) |= 1u;
      HvUnlockHiveFlusherExclusive(v15);
      CmpUnlockRegistry();
      v8 = 0;
      if( (int)CmpFlushHive(v15, 0, v20) < 0 )
      {
        v14 = -1073741670;
        goto LABEL_18;
      }
      goto LABEL_16;
    }
    HvUnlockHiveFlusherExclusive(v15);
    v14 = -1073741670;
  }
LABEL_17:
  CmpUnlockRegistry();
LABEL_18:
  CmpDetachFromRegistryProcess(&ApcState);
  return(unsigned int)v14;
}

Referenced by:

CmKtmNotification
CmpRmUnDoPhase