Fix RtlpGetStackLimits to get the right limits if called in kernel-mode (separated...
authorAlex Ionescu <aionescu@gmail.com>
Mon, 12 Sep 2005 02:57:47 +0000 (02:57 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Mon, 12 Sep 2005 02:57:47 +0000 (02:57 +0000)
svn path=/trunk/; revision=17814

reactos/lib/ntdll/main/i386/dispatch.S
reactos/lib/rtl/i386/except.s
reactos/ntoskrnl/ke/exception.c
reactos/ntoskrnl/ke/i386/exp.c
reactos/ntoskrnl/rtl/i386/seh.s

index 42bbff5..a812835 100644 (file)
@@ -184,3 +184,19 @@ Exit:
     call _RtlRaiseException@4\r
     ret 8\r
 \r
+.globl _RtlpGetStackLimits@8\r
+_RtlpGetStackLimits@8:\r
+\r
+    /* Get the stack limits */\r
+    mov eax, [fs:TEB_STACK_LIMIT]\r
+    mov ecx, [fs:TEB_STACK_BASE]\r
+\r
+    /* Return them */\r
+    mov edx, [esp+4]\r
+    mov [edx], eax\r
+    mov edx, [esp+8]\r
+    mov [edx], ecx\r
+\r
+    /* return */\r
+    ret 8\r
+\r
index ac8b384..949c92f 100644 (file)
 
 /* FUNCTIONS ****************************************************************/
 
-.globl _RtlpGetStackLimits@8
-_RtlpGetStackLimits@8:
-
-    /* Get the stack limits */
-    mov eax, [fs:TEB_STACK_LIMIT]
-    mov ecx, [fs:TEB_STACK_BASE]
-
-    /* Return them */
-    mov edx, [esp+4]
-    mov [edx], eax
-    mov edx, [esp+8]
-    mov [edx], ecx
-
-    /* return */
-    ret 8
-
 .globl _RtlpGetExceptionList@0
 _RtlpGetExceptionList@0:
 
index 7ecf157..40f190e 100644 (file)
@@ -23,7 +23,7 @@ KiContinuePreviousModeUser(IN PCONTEXT Context,
     CONTEXT LocalContext;\r
 \r
     /* We'll have to make a copy and probe it */\r
-    ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));\r
+    //ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));\r
     RtlMoveMemory(&LocalContext, Context, sizeof(CONTEXT));\r
     Context = &LocalContext;\r
 \r
@@ -99,6 +99,7 @@ KiRaiseException(PEXCEPTION_RECORD ExceptionRecord,
         /* Check the previous mode */\r
         if (PreviousMode != KernelMode)\r
         {\r
+#if 0\r
             /* Probe the context */\r
             ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));\r
 \r
@@ -107,13 +108,14 @@ KiRaiseException(PEXCEPTION_RECORD ExceptionRecord,
                          FIELD_OFFSET(EXCEPTION_RECORD, NumberParameters) +\r
                          sizeof(ULONG),\r
                          sizeof(ULONG));\r
-\r
+#endif\r
             /* Validate the maximum parameters */\r
             if ((ParameterCount = ExceptionRecord->NumberParameters) >\r
                 EXCEPTION_MAXIMUM_PARAMETERS)\r
             {\r
                 /* Too large */\r
-                return STATUS_INVALID_PARAMETER;\r
+                Status = STATUS_INVALID_PARAMETER;\r
+                _SEH_LEAVE;\r
             }\r
 \r
             /* Probe the entire parameters now*/\r
index 61f2bba..2288f27 100644 (file)
@@ -930,6 +930,7 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
     KD_CONTINUE_TYPE Action;
     ULONG_PTR Stack, NewStack;
     ULONG Size;
+    BOOLEAN UserDispatch = FALSE;
     DPRINT1("KiDispatchException() called\n");
 
     /* Increase number of Exception Dispatches */
@@ -1042,7 +1043,8 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
 
                 /* Set EIP to the User-mode Dispathcer */
                 TrapFrame->Eip = (ULONG)KeUserExceptionDispatcher;
-                return;
+                UserDispatch = TRUE;
+                _SEH_LEAVE;
             }
             _SEH_HANDLE
             {
@@ -1051,6 +1053,9 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
             _SEH_END;
         }
 
+        /* If we dispatch to user, return now */
+        if (UserDispatch) return;
+
         /* FIXME: Forward the exception to the debugger for 2nd chance */
 
         /* 3rd strike, kill the thread */
index 03ccd6b..8255cf8 100755 (executable)
@@ -9,6 +9,8 @@
  *                    Please keep them in sync.
  */
 
+#include <ndk/asm.h>
+
 #define ExceptionContinueExecution     0
 #define ExceptionContinueSearch                1
 #define ExceptionNestedException       2
@@ -364,3 +366,26 @@ _except_finish:
 
     // We should never get here
     ret
+    
+.intel_syntax noprefix
+.globl _RtlpGetStackLimits@8
+_RtlpGetStackLimits@8:
+
+    /* Get the current thread */
+    mov eax, [fs:KPCR_CURRENT_THREAD]
+
+    /* Get the stack limits */
+    mov ecx, [eax+KTHREAD_STACK_LIMIT]
+    mov edx, [eax+KTHREAD_INITIAL_STACK]
+    sub edx, SIZEOF_FX_SAVE_AREA
+
+    /* Return them */
+    mov eax, [esp+4]
+    mov [eax], ecx
+
+    mov eax, [esp+8]
+    mov [eax], edx
+
+    /* return */
+    ret 8
+