···943943 PVOID HandlerData;
944944 ULONG i, FramesToSkip;
945945 PRUNTIME_FUNCTION FunctionEntry;
946946+ MODE CurrentMode = RtlpGetMode();
946947947948 DPRINT("Enter RtlWalkFrameChain\n");
948949···955956956957 /* Get the stack limits */
957958 RtlpGetStackLimits(&StackLow, &StackHigh);
958958-959959- /* Check if we want the user-mode stack frame */
960960- if (Flags & 1)
961961- {
962962- }
963959964960 _SEH2_TRY
965961 {
···990986 }
991987992988 /* Check if we are in kernel mode */
993993- if (RtlpGetMode() == KernelMode)
989989+ if (CurrentMode == KernelMode)
994990 {
995991 /* Check if we left the kernel range */
996996- if (!(Flags & 1) && (Context.Rip < 0xFFFF800000000000ULL))
992992+ if (Context.Rip < 0xFFFF800000000000ULL)
997993 {
998998- break;
994994+ /* Bail out, unless user mode was requested */
995995+ if ((Flags & 1) == 0)
996996+ {
997997+ break;
998998+ }
999999+10001000+ /* We are in user mode now, get UM stack bounds */
10011001+ CurrentMode = UserMode;
10021002+ StackLow = (ULONG64)NtCurrentTeb()->NtTib.StackLimit;
10031003+ StackHigh = (ULONG64)NtCurrentTeb()->NtTib.StackBase;
9991004 }
10001005 }
10011001- else
10061006+10071007+ /* Check (again) if we are in user mode now */
10081008+ if (CurrentMode == UserMode)
10021009 {
10031010 /* Check if we left the user range */
10041011 if ((Context.Rip < 0x10000) ||