PiPnpRtlBeginOperation

__int64 __fastcall PiPnpRtlBeginOperation(__int64 **a1){
  _ETHREAD *CurrentThread; 
  int CurrentOperation; 
  unsigned int v4; 
  __int64 *v5; 
  char *PoolWithTag; 
  char *v7; 
  _ETHREAD *v8; 
  __int64 v9; 
  INT64 *v10; 
  INT64 *v12; 
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  *a1 = 0i64;
  v12 = 0i64;
  CurrentOperation = PiPnpRtlGetCurrentOperation(&v12);
  v4 = CurrentOperation;
  if( CurrentOperation == -1073741275 )
  {
    v4 = 0;
  }
  else if( CurrentOperation < 0 )
  {
    return v4;
  }
  v5 = v12;
  if( v12 )
  {
    ++*((_DWORD *)v12 + 36);
  }
  else
  {
    PoolWithTag = (char *)ExAllocatePoolWithTag(PagedPool, 0x98ui64, 0x41706E50ui64);
    v12 = (INT64 *)PoolWithTag;
    v7 = PoolWithTag;
    if( !PoolWithTag )
      return(unsigned int)-1073741670;
    *((_DWORD *)PoolWithTag + 36) = 1;
    *((_QWORD *)PoolWithTag + 2) = CurrentThread;
    RtlInitializeGenericTableAvl(
      (PRTL_AVL_TABLE)(PoolWithTag + 24),
      PiPnpRtlObjectEventCompareObjects,
      (PRTL_AVL_ALLOCATE_ROUTINE)PiPnpRtlOperationAllocateGenericTableEntry,
      PiPnpRtlOperationFreeGenericTableEntry,
      0i64);
    *((_QWORD *)v7 + 17) = v7 + 128;
    *((_QWORD *)v7 + 16) = v7 + 128;
    v8 = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)v8 + 242);
    ExAcquireResourceExclusiveLite(&PiPnpRtlActiveOperationsLock, 1u);
    v9 = PiPnpRtlActiveOperations;
    if( *(__int64 **)(PiPnpRtlActiveOperations + 8) != &PiPnpRtlActiveOperations )
      __fastfail(3u);
    v10 = v12;
    *v12 = PiPnpRtlActiveOperations;
    v10[1] = (INT64)&PiPnpRtlActiveOperations;
    *(_QWORD *)(v9 + 8) = v10;
    PiPnpRtlActiveOperations = (__int64)v10;
    ExReleaseResourceLite(&PiPnpRtlActiveOperationsLock);
    KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
    v5 = v12;
  }
  *a1 = v5;
  return v4;
}

Referenced by:

IoReportDetectedDevice
IoReportRootDevice
IopRegisterDeviceInterface
IopRemoveDevice
PiCMCreateDevice
PiCMDeleteClassKey
PiCMDeleteDevice
PiCMDeleteObject
PiDcHandleCustomDeviceEvent
PiDcUpdateDeviceContainerMembership
PiDqActionDataGetChangedProperties
PiDqActionDataGetRequestedProperties
PiDqIrpPropertySet
PiDqQueryEvaluateFilter
PiInitializeDevice
PiPnpRtlEnsureObjectCached
PiPnpRtlObjectEventWorker
PiProcessAddBootDevices
PiProcessClearDeviceProblem
PiProcessNewDeviceNode
PiProcessQueryDeviceState
PiProcessSetDeviceProblem
PiSwPropertySet
PipClearDevNodeProblem
PipEnumerateCompleted
PipMergeDependencyEdgeList
PipProcessStartPhase3
PipSetDevNodeProblem
PnpNewDeviceNodeDependencyCheck
PnpProcessTargetDeviceEvent
PnpUnlinkDeviceRemovalRelations
PpDevCfgProcessDevices