KeGetNextKernelStackSegment

INT64 __fastcall KeGetNextKernelStackSegment(
        _ETHREAD *Thread,
        _KERNEL_STACK_SEGMENT *StackSegment,
        INT64 FirstEnumeration){
  INT64 result; 
  if( (_BYTE)FirstEnumeration )
  {
    StackSegment->StackBase = *((_QWORD *)Thread + 7);
    StackSegment->StackLimit = *((_QWORD *)Thread + 6);
    StackSegment->KernelStack = *((_QWORD *)Thread + 11);
    result = *((_QWORD *)Thread + 5);
    StackSegment->InitialStack = result;
  }
  else
  {
    result = StackSegment->InitialStack;
    if( !*(_QWORD *)(result + 16) )
    {
      LOBYTE(result) = 0;
      return result;
    }
    *StackSegment = *(_KERNEL_STACK_SEGMENT *)(result + 16);
  }
  LOBYTE(result) = 1;
  return result;
}

Referenced by:

KeEnumerateKernelStackSegments
KiInSwapKernelStacks
RtlpIsFrameInBoundsEx
RtlpWalkFrameChain