IoShutdownSystem

VOID __stdcall IoShutdownSystem(UINT64 Phase){
  int v1; 
  _DEVICE_OBJECT *v2; 
  IRP *v3; 
  UINT64 v4; 
  UINT8 v5; 
  UINT8 v6; 
  _LIST_ENTRY *v7; 
  PADAPTER_OBJECT *v8; 
  _DEVICE_OBJECT *AttachedDeviceReference; 
  IRP *v10; 
  UINT64 v11; 
  UINT8 v12; 
  UINT8 v13; 
  _LIST_ENTRY *v14; 
  PADAPTER_OBJECT *v15; 
  IRP *v16; 
  IRP *v17; 
  struct _IO_STATUS_BLOCK IoStatusBlock; 
  struct _KEVENT Event; 
  memset(&Event, 0, sizeof(Event));
  v1 = Phase;
  IoStatusBlock = 0i64;
  if( (unsigned int)VfIsVerifierEnabled() )
    VfNotifyVerifierOfEvent(1ui64);
  KeInitializeEvent(&Event, NotificationEvent, 0);
  if( v1 )
  {
    if( v1 == 1 )
    {
      ExWaitForRundownProtectionRelease((EX_RUNDOWN_REF *)&IopFilesystemDatabaseShutdownRundown);
      ExAcquireResourceExclusiveLite(&IopDatabaseResource, 1u);
      IopShutdownBaseFileSystems(&IopDiskFileSystemQueueHead);
      IopShutdownBaseFileSystems((_LIST_ENTRY *)IopCdRomFileSystemQueueHead);
      IopShutdownBaseFileSystems(&IopTapeFileSystemQueueHead);
      while( 1 )
      {
        v14 = IopInterlockedRemoveHeadList((_LIST_ENTRY *)&IopNotifyLastChanceShutdownQueueHead);
        v15 = (PADAPTER_OBJECT *)v14;
        if( !v14 )
          break;
        AttachedDeviceReference = IoGetAttachedDeviceReference((DEVICE_OBJECT *)v14[1].Flink);
        v10 = IoBuildSynchronousFsdRequest(0x10u, AttachedDeviceReference, 0i64, 0, 0i64, &Event, &IoStatusBlock);
        if( v10 && IofCallDriver(AttachedDeviceReference, v10) == 259 )
          KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
        HalPutDmaAdapter((PADAPTER_OBJECT)AttachedDeviceReference);
        HalPutDmaAdapter(v15[2]);
        ExFreePoolWithTag(v15, 0);
        KeResetEvent(&Event, v11, v12, v13, v17);
      }
    }
  }
  else
  {
    PnpShutdownDevices();
    while( 1 )
    {
      v7 = IopInterlockedRemoveHeadList((_LIST_ENTRY *)&IopNotifyShutdownQueueHead);
      v8 = (PADAPTER_OBJECT *)v7;
      if( !v7 )
        break;
      v2 = IoGetAttachedDeviceReference((DEVICE_OBJECT *)v7[1].Flink);
      v3 = IoBuildSynchronousFsdRequest(0x10u, v2, 0i64, 0, 0i64, &Event, &IoStatusBlock);
      if( v3 && IofCallDriver(v2, v3) == 259 )
        KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
      HalPutDmaAdapter((PADAPTER_OBJECT)v2);
      HalPutDmaAdapter(v8[2]);
      ExFreePoolWithTag(v8, 0);
      KeResetEvent(&Event, v4, v5, v6, v16);
    }
    if( (MmVerifierData & 0x10) != 0 )
      IovUnloadDrivers();
    ZwSetSystemInformation();
  }
}

Referenced by:

PopGracefulShutdown