WmipRegisterDevice

NTSTATUS __stdcall WmipRegisterDevice(PVOID DeviceObject, UINT64 RegistrationFlag){
  unsigned int v2; 
  char v3; 
  INT64 v5; 
  _REGENTRY *RegEntryByDevice; 
  INT64 v7; 
  __int64 v8; 
  _ADAPTER_OBJECT *v9; 
  int updated; 
  __int64 v11; 

  v2 = 0;
  v3 = 0;
  if( (RegistrationFlag & 0x80000000) != 0i64 )
    v2 = 0x10000000;
  if( (RegistrationFlag & 0x10000) != 0 )
    v2 |= 16 * (RegistrationFlag & 0xF00000 | 0x4000000);
  KeWaitForSingleObject((UINT64)&ExBootDevicesRemovedEvent + 3072, 0, 0, 0, 0i64);
  RegEntryByDevice = WmipFindRegEntryByDevice((_DEVICE_OBJECT *)DeviceObject);
  if( RegEntryByDevice )
  {
    KeReleaseMutex((_KMUTANT *)((char *)&ExBootDevicesRemovedEvent + 3072), 0);
    updated = 0x40000000;
LABEL_13:
    WmipUnreferenceRegEntry(RegEntryByDevice);
    goto LABEL_14;
  }
  if( (v2 & 0x10000000) != 0 )
  {
    updated = 0;
  }
  else
  {
    LODWORD(v8) = IoGetAttachedDeviceReference((INT64)DeviceObject, v5, v7);
    v9 = (_ADAPTER_OBJECT *)v8;
    WmipUpdateDeviceStackSize(*(_BYTE *)(v8 + 76) + 1);
    HalPutDmaAdapter(v9);
    updated = ObReferenceObjectByPointer(DeviceObject, 0i64, 0i64, 0);
  }
  if( updated < 0 )
  {
    KeReleaseMutex((_KMUTANT *)((char *)&ExBootDevicesRemovedEvent + 3072), 0);
  }
  else
  {
    v11 = WmipAllocRegEntry(DeviceObject, v2);
    RegEntryByDevice = (_REGENTRY *)v11;
    if( v11 )
    {
      _InterlockedAdd((volatile signed __int32 *)(v11 + 48), 1u);
      KeReleaseMutex((_KMUTANT *)((char *)&ExBootDevicesRemovedEvent + 3072), 0);
      if( (v2 & 0x10000000) != 0 )
      {
        updated = WmipRegisterOrUpdateDS(RegEntryByDevice, 0);
        if( updated < 0 )
          v3 = 1;
      }
      else
      {
        v3 = 0;
        updated = WmipQueueRegWork(0i64, RegEntryByDevice);
        if( updated < 0 )
          v3 = 1;
      }
      goto LABEL_13;
    }
    KeReleaseMutex((_KMUTANT *)((char *)&ExBootDevicesRemovedEvent + 3072), 0);
    updated = -1073741670;
  }
LABEL_14:
  if( v3 )
    WmipDeregisterRegEntry(RegEntryByDevice);
  return updated;
}

Referenced by:

IoWMIRegistrationControl