ExSwapinWorkerThreads

VOID __stdcall ExSwapinWorkerThreads(UINT8 AllowSwap){
  _LIST_ENTRY **CurrentThread; 
  PFN_WDFDEVICEINDICATEWAKESTATUS *i; 
  PFN_WDFDEVICEINDICATEWAKESTATUS *v3; 
  PFN_WDFDEVICEINDICATEWAKESTATUS *v4; 
  _ETHREAD *j; 
  _LIST_ENTRY **NextProcessThread; 
  _LIST_ENTRY **v7; 
  int v8[8]; 
  __int128 SystemArgument1; 
  __int64 v10; 
  _KAPC Apc; 
  UINT8 Enable; 
  UINT64 v13; 

  Enable = AllowSwap;
  memset(&Apc, 0i64, sizeof(Apc));
  v13 = 0i64;
  SystemArgument1 = 0i64;
  v10 = 0i64;
  CurrentThread = (_LIST_ENTRY **)KeGetCurrentThread();
  KeInitializeEvent((INT64)&SystemArgument1, 1, 0);
  ExAcquireFastMutex((PFAST_MUTEX)((char *)&WheapDeferredInternalLogsEventLock + 2528));
  *(&WheapDeferredInternalLogsEventLock + 2584) = Enable;
  _InterlockedOr(v8, 0);
  for( i = 0i64; ; i = v4 )
  {
    LODWORD(v3) = PsGetNextPartitionUnsafe(i);
    v4 = v3;
    if( !v3 )
      break;
    if( PsReferencePartitionSystemProcess(v3, &v13) >= 0 )
    {
      for( j = 0i64; ; j = (_ETHREAD *)v7 )
      {
        NextProcessThread = PsGetNextProcessThread((_EPROCESS *)v13, j);
        v7 = NextProcessThread;
        if( !NextProcessThread )
          break;
        if( (*((_DWORD *)NextProcessThread + 325) & 1) != 0 )
        {
          if( NextProcessThread == CurrentThread )
          {
            KeSetKernelStackSwapEnable(Enable);
          }
          else
          {
            KeInitializeApc(
              (INT64)&Apc,
              (INT64)NextProcessThread,
              0i64,
              (INT64)ExpSetSwappingKernelApc,
              0i64,
              0i64,
              0,
              (INT64)&Enable);
            if( KeInsertQueueApc((INT64)&Apc, (INT64)&SystemArgument1, 0i64, 3i64) )
              KeWaitForSingleObject((UINT64)&SystemArgument1, 0, 0, 0, 0i64);
          }
        }
      }
      HalPutDmaAdapter((PADAPTER_OBJECT)v13);
    }
  }
  KeReleaseGuardedMutex((PKGUARDED_MUTEX)((char *)&WheapDeferredInternalLogsEventLock + 2528));
}

Referenced by:

ExShutdownSystem
PopTransitionSystemPowerStateEx
PopUnlockAfterSleepWorker