PopIrpWorker

NTSTATUS __fastcall PopIrpWorker(VOID *Entry){
  unsigned __int8 CurrentIrql; 
  _KSEMAPHORE *v3; 
  _LARGE_INTEGER *v4; 
  __int64 v5; 
  __int64 v6; 
  int v7; 
  char *v8; 
  __int64 v9; 
  _IRP *v10; 
  _DEVICE_OBJECT *v11; 
  __int64 v12; 
  char v13; 
  __int64 v14; 
  INT64 v15; 
  __int64 v16; 
  int v17; 
  NTSTATUS DeviceDStateReason; 
  __int64 v19; 
  __int64 v20; 
  _DEVICE_POWER_STATE v21; 
  int v22; 
  __int128 v23; 
  char v24; 
  _KLOCK_QUEUE_HANDLE LockHandle; 
  __int128 v27; 
  __m256i v28; 
  _LARGE_INTEGER v29; 

  v29.QuadPart = 0i64;
  CurrentIrql = 0;
  memset(&LockHandle, 0, sizeof(LockHandle));
  v27 = 0i64;
  *(_OWORD *)&v28.m256i_u64[2] = 0i64;
  *(_OWORD *)v28.m256i_i8 = (unsigned __int64)KeGetCurrentThread();
  if( Entry )
  {
    v3 = *(_KSEMAPHORE **)Entry;
    if( v3 )
      KeReleaseSemaphore(v3, 0i64, 1i64, 0);
    ExFreeToNPagedLookasideList(&PopDynamicIrpWorkerLookaside, Entry);
    v29.QuadPart = -100000000i64;
    v4 = &v29;
    v28.m256i_i8[24] = 0;
  }
  else
  {
    v4 = 0i64;
    v28.m256i_i8[24] = 1;
  }
  PopAcquireIrpWorkerLock();
  --*(&PopIrpWorkerControlEvent + 30);
  ++*(&PopIrpWorkerControlEvent + 7);
  if( (_UNKNOWN *)**(&PopIrpWorkerControlEvent + 17) != (_UNKNOWN *)((char *)&PopIrpWorkerControlEvent + 128) )
LABEL_49:
    __fastfail(3u);
  *(_QWORD *)&v27 = (char *)&PopIrpWorkerControlEvent + 128;
  *((_QWORD *)&v27 + 1) = *(&PopIrpWorkerControlEvent + 17);
  **(&PopIrpWorkerControlEvent + 17) = &v27;
  *(&PopIrpWorkerControlEvent + 17) = &v27;
LABEL_7:
  PopReleaseIrpWorkerLock();
  do
  {
    if( KeWaitForSingleObject((UINT64)&PopIrpWorkerSemaphore, 0, 0, 0, (INT64)v4) != 258 )
    {
      KeAcquireInStackQueuedSpinLock((PKSPIN_LOCK)&stru_140C23628 + 121, &LockHandle);
      v5 = PopIrpWorkerList;
      v6 = *(_QWORD *)PopIrpWorkerList;
      if( *(__int64 **)(PopIrpWorkerList + 8) != &PopIrpWorkerList || *(_QWORD *)(v6 + 8) != PopIrpWorkerList )
        goto LABEL_49;
      PopIrpWorkerList = *(_QWORD *)PopIrpWorkerList;
      *(_QWORD *)(v6 + 8) = &PopIrpWorkerList;
      KeReleaseInStackQueuedSpinLock(&LockHandle);
      PopAcquireIrpWorkerLock();
      v7 = ++*(&PopIrpWorkerControlEvent + 8);
      if( PopCreateIrpWorkerAllowed
        && v7 == *(&PopIrpWorkerControlEvent + 7)
        && !*(&PopIrpWorkerControlEvent + 30)
        && *(&PopIrpWorkerControlEvent + 7) < 0xFu
        && !*(&PopIrpWorkerControlEvent + 24) )
      {
        *(&PopIrpWorkerControlEvent + 24) = 1;
        KeSetEvent((PRKEVENT)&PopIrpWorkerControlEvent, 0, 0);
      }
      PopReleaseIrpWorkerLock();
      v8 = (char *)(v5 - 168);
      v9 = *(_QWORD *)(v5 - 168 + 184);
      v10 = (_IRP *)(v5 - 168);
      v11 = *(_DEVICE_OBJECT **)(v9 + 40);
      PoDeviceAcquireIrp(v10, *(_BYTE *)(v9 + 1), v11);
      v12 = *(_QWORD *)&v8[72 * v8[66] + 200];
      if( *(_BYTE *)(v12 + 184) == 2 && *(_DWORD *)(v12 + 188) == 1 && *(_DEVICE_OBJECT **)(v12 + 32) == v11 )
      {
        v14 = *(_QWORD *)(v12 + 24);
        v15 = *(_QWORD *)(v12 + 200);
        v16 = v14 ? *(_QWORD *)(*(_QWORD *)(v14 + 312) + 40i64) : 0i64;
        v17 = *(_DWORD *)(v16 + 156);
        *(_DWORD *)(v16 + 156) = *(_DWORD *)(v12 + 192);
        if( v15 )
        {
          DeviceDStateReason = PopFxGetDeviceDStateReason(v15);
          *(_DWORD *)(v19 + 248) = DeviceDStateReason;
          *(_BYTE *)(v19 + 208) = 0;
          if( DeviceDStateReason == 1 )
            *(_BYTE *)(v19 + 208) = 1;
          v21 = *(_DWORD *)(v19 + 192);
          *(_BYTE *)(v19 + 209) = v21 != v17;
          if( v21 != v17 )
          {
            if( v21 == PowerDeviceD0 )
            {
              _InterlockedOr((volatile signed __int32 *)(v20 + 32), 2u);
              v21 = *(_DWORD *)(v19 + 192);
            }
            PopPepDeviceDState(*(PEPHANDLE__ **)(v20 + 56), v21, 0i64, *(unsigned int *)(v19 + 248));
          }
        }
      }
      v13 = 0;
      v28.m256i_i64[1] = (__int64)v8;
      v28.m256i_i64[2] = (__int64)v11;
      if( (v11->Flags & 0x2000) == 0 && v8 == (char *)PopInrushIrp )
      {
        CurrentIrql = KeGetCurrentIrql();
        __writecr8(2ui64);
        v13 = 1;
      }
      v11->DriverObject->MajorFunction[22](v11, (_IRP *)v8);
      if( v13 )
        __writecr8(CurrentIrql);
      if( KeGetCurrentThread()->WaitBlock[3].SpareLong )
        KeBugCheckEx(0xA0u, (PVOID)0x901, v11, v8, (PVOID)KeGetCurrentThread()->CombinedApcDisable);
      *(_OWORD *)&v28.m256i_u64[1] = 0i64;
      ObfDereferenceObjectWithTag(v11, 0x72496F50ui64);
      PopAcquireIrpWorkerLock();
      --*(&PopIrpWorkerControlEvent + 8);
      goto LABEL_7;
    }
    PopAcquireIrpWorkerLock();
    if( PopCreateIrpWorkerAllowed
      && ((v22 = *(&PopIrpWorkerControlEvent + 7) - 1,
           *(&PopIrpWorkerControlEvent + 8) != *(&PopIrpWorkerControlEvent + 7) - 1)
       || *(&PopIrpWorkerControlEvent + 30)) )
    {
      v23 = v27;
      v24 = 0;
      if( *(__int128 **)(v27 + 8) != &v27 || **((__int128 ***)&v27 + 1) != &v27 )
        goto LABEL_49;
      **((_QWORD **)&v27 + 1) = v27;
      *(_QWORD *)(v23 + 8) = *((_QWORD *)&v23 + 1);
      *(&PopIrpWorkerControlEvent + 7) = v22;
    }
    else
    {
      v24 = 1;
    }
    PopReleaseIrpWorkerLock();
  }
  while( v24 );
  return PsTerminateSystemThread(0i64);
}

Referenced by:

No references.