Reactos

[RTL/x64] Improve RtlWalkFrameChain to handle user mode

+16 -9
+16 -9
sdk/lib/rtl/amd64/unwind.c
··· 943 943 PVOID HandlerData; 944 944 ULONG i, FramesToSkip; 945 945 PRUNTIME_FUNCTION FunctionEntry; 946 + MODE CurrentMode = RtlpGetMode(); 946 947 947 948 DPRINT("Enter RtlWalkFrameChain\n"); 948 949 ··· 955 956 956 957 /* Get the stack limits */ 957 958 RtlpGetStackLimits(&StackLow, &StackHigh); 958 - 959 - /* Check if we want the user-mode stack frame */ 960 - if (Flags & 1) 961 - { 962 - } 963 959 964 960 _SEH2_TRY 965 961 { ··· 990 986 } 991 987 992 988 /* Check if we are in kernel mode */ 993 - if (RtlpGetMode() == KernelMode) 989 + if (CurrentMode == KernelMode) 994 990 { 995 991 /* Check if we left the kernel range */ 996 - if (!(Flags & 1) && (Context.Rip < 0xFFFF800000000000ULL)) 992 + if (Context.Rip < 0xFFFF800000000000ULL) 997 993 { 998 - break; 994 + /* Bail out, unless user mode was requested */ 995 + if ((Flags & 1) == 0) 996 + { 997 + break; 998 + } 999 + 1000 + /* We are in user mode now, get UM stack bounds */ 1001 + CurrentMode = UserMode; 1002 + StackLow = (ULONG64)NtCurrentTeb()->NtTib.StackLimit; 1003 + StackHigh = (ULONG64)NtCurrentTeb()->NtTib.StackBase; 999 1004 } 1000 1005 } 1001 - else 1006 + 1007 + /* Check (again) if we are in user mode now */ 1008 + if (CurrentMode == UserMode) 1002 1009 { 1003 1010 /* Check if we left the user range */ 1004 1011 if ((Context.Rip < 0x10000) ||