KeAllocateCalloutStackEx

NTSTATUS __stdcall KeAllocateCalloutStackEx(
        _KSTACK_TYPE StackType,
        UINT8 RecursionDepth,
        UINT64 Reserved,
        VOID **StackContext){
  unsigned int v4; 
  unsigned __int8 v5; 
  VOID **PoolWithTag; 
  unsigned int v7; 
  _QWORD *v8; 
  VOID *KernelStack; 

  v4 = RecursionDepth;
  if( StackType )
  {
    if( StackType != ReserveStackLarge )
      return -1073741585;
    v5 = 1;
  }
  else
  {
    v5 = 0;
  }
  if( !RecursionDepth )
    return -1073741584;
  if( Reserved )
    return -1073741583;
  PoolWithTag = ExAllocatePoolWithTag(0x200ui64, 8i64 * RecursionDepth + 64, 1666409803i64);
  if( !PoolWithTag )
    return -1073741801;
  v7 = 0;
  if( (_BYTE)v4 )
  {
    v8 = PoolWithTag + 8;
    while( 1 )
    {
      KernelStack = MmCreateKernelStack(v5 != 0 ? 5 : 0, 0, 0i64);
      if( !KernelStack )
        break;
      *v8 = KernelStack;
      ++v7;
      ++v8;
      if( v7 >= v4 )
        goto LABEL_10;
    }
    while( v7 )
      MmDeleteKernelStack(PoolWithTag[--v7 + 8], v5);
    ExFreePoolWithTag(PoolWithTag, 0);
    return -1073741670;
  }
  else
  {
LABEL_10:
    *(_DWORD *)PoolWithTag = 1801548883;
    *((_BYTE *)PoolWithTag + 4) = v5;
    *((_BYTE *)PoolWithTag + 5) = v4;
    *((_BYTE *)PoolWithTag + 6) = 0;
    KeInitializeMutex((PRKMUTEX)(PoolWithTag + 1), 0);
    *StackContext = PoolWithTag;
    return 0;
  }
}

Referenced by:

KeAllocateCalloutStack