SMKM_STORE::SmStOutSwapStore

__int64 __fastcall SMKM_STORE::SmStOutSwapStore(__int64 a1){
  __int64 v1; 
  int v2; 
  unsigned int *v3; 
  unsigned int v4; 
  __int64 v6; 
  __int64 v7; 
  unsigned int *v8; 
  _ETHREAD *CurrentThread; 
  unsigned int v10; 
  unsigned int v11; 
  __int64 v12; 
  __int64 v13; 
  _DWORD *v14; 
  _DWORD *v15; 
  int v16; 
  int v17; 
  unsigned int v18; 
  unsigned int i; 
  unsigned int v20; 
  __int64 v21; 
  __int64 v22; 
  __int64 v23; 
  UINT64 v24; 
  __int64 v25; 
  _QWORD *v26; 
  __int64 v27; 
  _DWORD *v28; 
  int v29; 
  _ETHREAD *v30; 
  unsigned int *v31; 
  __int64 v32; 
  int v34; 
  __int64 v35; 
  PVOID P; 
  PVOID v37; 
  INT64 v38[2]; 
  __int64 v39; 
  UINT64 EntryCountMax; 
  int v41; 
  PVOID PoolWithTag; 
  v1 = 0i64;
  v37 = 0i64;
  v39 = 0i64;
  *(_OWORD *)v38 = 0i64;
  v2 = 0;
  v35 = -1i64;
  P = 0i64;
  v3 = 0i64;
  PoolWithTag = 0i64;
  v4 = 0;
  ST_STORE::StDrainReadContextList(a1);
  v8 = *(unsigned int **)(a1 + 6568);
  if( (unsigned __int64)v8 - 1 > 0xFFFFFFFFFFFFFFFDui64 )
  {
    v29 = -1073700861;
    goto LABEL_41;
  }
  if( v8 != (unsigned int *)_InterlockedCompareExchange64(
                               (volatile signed __int64 *)(a1 + 6568),
                               -1i64,
                               (signed __int64)v8) )
    return(unsigned int)-1073700861;
  if( *(_QWORD *)v8 )
  {
    v1 = (__int64)v8;
    v29 = -1073741791;
    goto LABEL_47;
  }
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v35 = 0i64;
  v37 = v8;
  v41 = 1;
  --*((_WORD *)CurrentThread + 243);
  ExAcquirePushLockSharedEx(a1 + 6024, 0i64);
  PoolWithTag = ExAllocatePoolWithTag(NonPagedPoolNx, (unsigned int)(4 * *(_DWORD *)(a1 + 6212)), 0x77536D73ui64);
  if( !PoolWithTag )
  {
    v29 = -1073741670;
    goto LABEL_59;
  }
  LODWORD(EntryCountMax) = 0;
  v10 = 0;
LABEL_6:
  while( 1 )
  {
    v11 = v8[2];
    if( v11 <= v10 )
      break;
    v12 = *((_QWORD *)v8 + 2);
    v13 = v10;
    v14 = (_DWORD *)(v12 + 4 * ((unsigned __int64)(v11 - 1) >> 5));
    v15 = (_DWORD *)(v12 + 4 * ((unsigned __int64)v10 >> 5));
    if( v15 != v14 && (*v15 | *((_DWORD *)qword_140011CE0 + (v10 & 0x1F))) == -1 )
    {
      v13 = v10 - (v10 & 0x1F) + 32;
      for( ++v15; v15 < v14 && *v15 == -1; ++v15 )
        v13 = (unsigned int)(v13 + 32);
    }
    for( ; (unsigned int)v13 < v11; v13 = (unsigned int)(v13 + 1) )
    {
      if( !_bittest(*((const signed __int32 **)v8 + 2), v13) )
        break;
    }
    v16 = 0;
    if( v15 != v14 )
    {
      v17 = v13 & 0x1F;
      if( (*v15 & ~*((_DWORD *)qword_140011CE0 + (v13 & 0x1F))) == 0 )
      {
        v16 = 32 - v17;
        if( v17 == 33 )
          goto LABEL_22;
        v28 = v15 + 1;
        while( v28 < v14 && !*v28 )
        {
          ++v28;
          v16 += 32;
          if( v16 == -1 )
            goto LABEL_22;
        }
      }
    }
    v18 = v8[2];
    for( i = v16 + v13; i < v18; ++v16 )
    {
      if( _bittest(*((const signed __int32 **)v8 + 2), i) )
        break;
      if( v16 == -1 )
        break;
      ++i;
    }
LABEL_22:
    v10 = v13;
    if( !v16 )
      break;
    v20 = v16 + v13;
    if( (unsigned int)v13 < v16 + (int)v13 )
    {
      v21 = 8i64 * (unsigned int)v13;
      while( 1 )
      {
        v22 = *(_QWORD *)(v21 + *(_QWORD *)(a1 + 6216));
        if( (v22 & 0x7FFFFFFFFFFF0000i64) != 0 && v22 >= 0 )
        {
          v23 = SMKM_STORE::SmStMapVirtualRegion(a1, v10, 0, v13, 4u);
          if( !(unsigned int)SmArrayGrow(v4, v24, &EntryCountMax, &P) )
          {
            SMKM_STORE::SmStUnmapVirtualRegion(a1, v10, v25, v13, v34, 2u);
            v2 = v41;
            v29 = -1073741670;
            goto LABEL_40;
          }
          v26 = P;
          *((_DWORD *)PoolWithTag + v4) = v10;
          v27 = 2i64 * v4++;
          v26[v27] = v23;
          v26[v27 + 1] = *(unsigned int *)(a1 + 6208);
        }
        ++v10;
        v21 += 8i64;
        if( v10 >= v20 )
          goto LABEL_6;
      }
    }
  }
  if( _InterlockedCompareExchange64((volatile signed __int64 *)(a1 + 6024), 0i64, 17i64) != 17 )
    ExfReleasePushLockShared((INT64 *)(a1 + 6024));
  KeAbPostRelease((PVOID)(a1 + 6024));
  KiLeaveGuardedRegionUnsafe((__int64)KeGetCurrentThread());
  v2 = 0;
  if( v4 )
  {
    v38[1] = (INT64)P;
    v39 = v4;
    v29 = SmPerformStoreSwapOperation(1i64, (INT64)v38);
    if( v29 >= 0 )
    {
      v29 = 0;
      *(_QWORD *)v8 = v38[0];
      v35 = (__int64)v8;
      v37 = 0i64;
    }
LABEL_40:
    v3 = (unsigned int *)PoolWithTag;
LABEL_41:
    if( v4 )
    {
      if( !v2 )
      {
        v30 = (_ETHREAD *)KeGetCurrentThread();
        v2 = 1;
        --*((_WORD *)v30 + 243);
        ExAcquirePushLockSharedEx(a1 + 6024, 0i64);
      }
      v31 = v3;
      v32 = v4;
      do
      {
        SMKM_STORE::SmStUnmapVirtualRegion(a1, *v31++, v6, v7, v34, 2u);
        --v32;
      }
      while( v32 );
    }
    v1 = v35;
    if( !v2 )
    {
LABEL_47:
      if( v1 != -1 )
        goto LABEL_48;
      goto LABEL_49;
    }
LABEL_59:
    if( _InterlockedCompareExchange64((volatile signed __int64 *)(a1 + 6024), 0i64, 17i64) != 17 )
      ExfReleasePushLockShared((INT64 *)(a1 + 6024));
    KeAbPostRelease((PVOID)(a1 + 6024));
    KiLeaveGuardedRegionUnsafe((__int64)KeGetCurrentThread());
    goto LABEL_47;
  }
  v1 = 0i64;
  v29 = -1073741607;
LABEL_48:
  _InterlockedExchange64((volatile __int64 *)(a1 + 6568), v1);
LABEL_49:
  if( v37 )
    ExFreePoolWithTag(v37, 0);
  if( P )
    ExFreePoolWithTag(P, 0);
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0);
  return(unsigned int)v29;
}

Referenced by:

No references.