- Use _SEH2_YIELD when returning from an exception instead of returning outside the...
authorStefan Ginsberg <stefanginsberg@gmail.com>
Mon, 24 Aug 2009 19:58:15 +0000 (19:58 +0000)
committerStefan Ginsberg <stefanginsberg@gmail.com>
Mon, 24 Aug 2009 19:58:15 +0000 (19:58 +0000)
- Re-enable user mode probes in KiRaiseException; they do not seem to be an issue anymore -- booting and running the ntdll exception Winetest didn't reveal any issue. Put a breakpoint there in case this code is ever hit (unlikely).

svn path=/trunk/; revision=42923

reactos/lib/rtl/debug.c
reactos/ntoskrnl/config/ntapi.c
reactos/ntoskrnl/dbgk/dbgkobj.c
reactos/ntoskrnl/ke/except.c
reactos/ntoskrnl/ke/i386/exp.c
reactos/ntoskrnl/ke/i386/usercall.c
reactos/ntoskrnl/ke/wait.c
reactos/ntoskrnl/lpc/reply.c
reactos/ntoskrnl/lpc/send.c
reactos/ntoskrnl/po/power.c
reactos/ntoskrnl/vdm/vdmmain.c

index c491a46..f34adef 100644 (file)
@@ -54,7 +54,7 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
                               IN va_list ap,
                               IN BOOLEAN HandleBreakpoint)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     ANSI_STRING DebugString;
     CHAR Buffer[512];
     ULONG Length, PrefixLength;
@@ -65,11 +65,11 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
         !(NtQueryDebugFilterState(ComponentId, Level)))
     {
         /* This message is masked */
-        return Status;
+        return STATUS_SUCCESS;
     }
 
     /* For user mode, don't recursively DbgPrint */
-    if (RtlpSetInDbgPrint(TRUE)) return Status;
+    if (RtlpSetInDbgPrint(TRUE)) return STATUS_SUCCESS;
 
     /* Guard against incorrect pointers */
     _SEH2_TRY
@@ -91,10 +91,9 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
     {
         /* Fail */
         Length = PrefixLength = 0;
-        Status = _SEH2_GetExceptionCode();
+        _SEH2_YIELD(return _SEH2_GetExceptionCode());
     }
     _SEH2_END;
-    if (!NT_SUCCESS(Status)) return Status;
 
     /* Check if we went past the buffer */
     if (Length == -1U)
index 20176b3..0d62269 100644 (file)
@@ -27,7 +27,7 @@ NtCreateKey(OUT PHANDLE KeyHandle,
             IN ULONG CreateOptions,
             OUT PULONG Disposition OPTIONAL)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     CM_PARSE_CONTEXT ParseContext = {0};
     HANDLE Handle;
@@ -63,11 +63,10 @@ NtCreateKey(OUT PHANDLE KeyHandle,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get the error code */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
     else
     {
@@ -113,7 +112,7 @@ NtOpenKey(OUT PHANDLE KeyHandle,
 {
     CM_PARSE_CONTEXT ParseContext = {0};
     HANDLE Handle;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     PAGED_CODE();
     DPRINT("NtOpenKey(OB 0x%wZ)\n", ObjectAttributes->ObjectName);
@@ -135,11 +134,10 @@ NtOpenKey(OUT PHANDLE KeyHandle,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get the status */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
 
     /* Just let the object manager handle this */
@@ -267,17 +265,12 @@ NtEnumerateKey(IN HANDLE KeyHandle,
                           sizeof(ULONG));
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-        {
-            Status = _SEH2_GetExceptionCode();
-        }
-        _SEH2_END;
-
-        if (!NT_SUCCESS(Status))
         {
             /* Dereference and return status */
             ObDereferenceObject(KeyObject);
-            return Status;
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
+        _SEH2_END;
     }
 
     /* Setup the callback */
@@ -356,17 +349,12 @@ NtEnumerateValueKey(IN HANDLE KeyHandle,
                           sizeof(ULONG));
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-        {
-            Status = _SEH2_GetExceptionCode();
-        }
-        _SEH2_END;
-
-        if (!NT_SUCCESS(Status))
         {
             /* Dereference and return status */
             ObDereferenceObject(KeyObject);
-            return Status;
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
+        _SEH2_END;
     }
 
     /* Setup the callback */
@@ -475,17 +463,12 @@ NtQueryKey(IN HANDLE KeyHandle,
                           sizeof(ULONG));
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-        {
-            Status = _SEH2_GetExceptionCode();
-        }
-        _SEH2_END;
-
-        if (!NT_SUCCESS(Status))
         {
             /* Dereference and return status */
             ObDereferenceObject(KeyObject);
-            return Status;
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
+        _SEH2_END;
     }
 
     /* Setup the callback */
@@ -555,17 +538,12 @@ NtQueryValueKey(IN HANDLE KeyHandle,
                           sizeof(ULONG));
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-        {
-            Status = _SEH2_GetExceptionCode();
-        }
-        _SEH2_END;
-
-        if (!NT_SUCCESS(Status))
         {
             /* Dereference and return status */
             ObDereferenceObject(KeyObject);
-            return Status;
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
+        _SEH2_END;
     }
 
     /* Make sure the name is aligned properly */
@@ -1131,7 +1109,7 @@ NtUnloadKey2(IN POBJECT_ATTRIBUTES TargetKey,
              IN ULONG Flags)
 {
 #if 0
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING ObjectName;
     CM_PARSE_CONTEXT ParseContext = {0};
@@ -1175,11 +1153,10 @@ NtUnloadKey2(IN POBJECT_ATTRIBUTES TargetKey,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get the error code */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
     else
     {
index c59ad79..6b509a0 100644 (file)
@@ -1517,7 +1517,7 @@ NtCreateDebugObject(OUT PHANDLE DebugHandle,
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     PDEBUG_OBJECT DebugObject;
     HANDLE hDebug;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PAGED_CODE();
 
     /* Check if we were called from user mode*/
@@ -1531,10 +1531,9 @@ NtCreateDebugObject(OUT PHANDLE DebugHandle,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get exception error */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         } _SEH2_END;
-        if (!NT_SUCCESS(Status)) return Status;
     }
 
     /* Check for invalid flags */
@@ -1610,7 +1609,7 @@ NtDebugContinue(IN HANDLE DebugHandle,
 {
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     PDEBUG_OBJECT DebugObject;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PDEBUG_EVENT DebugEvent = NULL, DebugEventToWake = NULL;
     PLIST_ENTRY ListHead, NextEntry;
     BOOLEAN NeedsWake = FALSE;
@@ -1632,10 +1631,9 @@ NtDebugContinue(IN HANDLE DebugHandle,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get exception error */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         } _SEH2_END;
-        if (!NT_SUCCESS(Status)) return Status;
     }
 
     /* Make sure that the status is valid */
@@ -1869,7 +1867,7 @@ NtSetInformationDebugObject(IN HANDLE DebugHandle,
 {
     PDEBUG_OBJECT DebugObject;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PDEBUG_OBJECT_KILL_PROCESS_ON_EXIT_INFORMATION DebugInfo = DebugInformation;
     PAGED_CODE();
 
@@ -1881,6 +1879,7 @@ NtSetInformationDebugObject(IN HANDLE DebugHandle,
                                        DebugInformation,
                                        DebugInformationLength,
                                        PreviousMode);
+    if (!NT_SUCCESS(Status)) return Status;
 
     /* Check if the caller wanted the return length */
     if (ReturnLength)
@@ -1894,12 +1893,11 @@ NtSetInformationDebugObject(IN HANDLE DebugHandle,
         }
         _SEH2_EXCEPT(ExSystemExceptionFilter())
         {
-            /* Get SEH Exception code */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
     }
-    if (!NT_SUCCESS(Status)) return Status;
 
     /* Open the Object */
     Status = ObReferenceObjectByHandle(DebugHandle,
@@ -1955,7 +1953,7 @@ NtWaitForDebugEvent(IN HANDLE DebugHandle,
     LARGE_INTEGER NewTime;
     PDEBUG_OBJECT DebugObject;
     DBGUI_WAIT_STATE_CHANGE WaitStateChange;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PDEBUG_EVENT DebugEvent = NULL, DebugEvent2;
     PLIST_ENTRY ListHead, NextEntry, NextEntry2;
     PAGED_CODE();
@@ -1987,11 +1985,10 @@ NtWaitForDebugEvent(IN HANDLE DebugHandle,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get the exception code */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if (!NT_SUCCESS(Status)) return Status;
     }
     else
     {
index 8cb8d96..fd4ba95 100644 (file)
@@ -97,13 +97,12 @@ KiRaiseException(IN PEXCEPTION_RECORD ExceptionRecord,
     ULONG ParameterCount, Size;
     NTSTATUS Status = STATUS_SUCCESS;
 
-    /* Set up SEH */
-    _SEH2_TRY
+    /* Check if we need to probe */
+    if (PreviousMode != KernelMode)
     {
-        /* Check the previous mode */
-        if (PreviousMode != KernelMode)
+        /* Set up SEH */
+        _SEH2_TRY
         {
-#if 0
             /* Probe the context */
             ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));
 
@@ -112,7 +111,7 @@ KiRaiseException(IN PEXCEPTION_RECORD ExceptionRecord,
                          FIELD_OFFSET(EXCEPTION_RECORD, NumberParameters) +
                          sizeof(ULONG),
                          sizeof(ULONG));
-#endif
+
             /* Validate the maximum parameters */
             if ((ParameterCount = ExceptionRecord->NumberParameters) >
                 EXCEPTION_MAXIMUM_PARAMETERS)
@@ -136,14 +135,15 @@ KiRaiseException(IN PEXCEPTION_RECORD ExceptionRecord,
             /* Update the parameter count */
             ExceptionRecord->NumberParameters = ParameterCount;
         }
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+        {
+            DbgBreakPoint();
+
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
+        }
+        _SEH2_END;
     }
-    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-    {
-        /* Get the exception code */
-        Status = _SEH2_GetExceptionCode();
-    }
-    _SEH2_END;
-    if (!NT_SUCCESS(Status)) return Status;
 
     /* Convert the context record */
     KeContextToTrapFrame(Context,
index 4424a3d..6ee3c74 100644 (file)
@@ -1072,7 +1072,6 @@ NTSTATUS
 NTAPI
 KeRaiseUserException(IN NTSTATUS ExceptionCode)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
     ULONG OldEip;
     PTEB Teb = KeGetCurrentThread()->Teb;
     PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
@@ -1085,11 +1084,10 @@ KeRaiseUserException(IN NTSTATUS ExceptionCode)
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
-        /* Save exception code */
-        Status = ExceptionCode;
+        /* Return the exception code */
+        _SEH2_YIELD(return _SEH2_GetExceptionCode());
     }
     _SEH2_END;
-    if (!NT_SUCCESS(Status)) return Status;
 
     /* Get the old EIP */
     OldEip = TrapFrame->Eip;
index 11acfaf..a07a055 100644 (file)
@@ -135,7 +135,7 @@ KeUserModeCallback(IN ULONG RoutineIndex,
 {
     ULONG_PTR NewStack, OldStack;
     PULONG UserEsp;
-    NTSTATUS CallbackStatus = STATUS_SUCCESS;
+    NTSTATUS CallbackStatus;
     PEXCEPTION_REGISTRATION_RECORD ExceptionList;
     PTEB Teb;
     ULONG GdiBatchCount = 0;
@@ -192,10 +192,9 @@ KeUserModeCallback(IN ULONG RoutineIndex,
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
         /* Get the SEH exception */
-        CallbackStatus = _SEH2_GetExceptionCode();
+        _SEH2_YIELD(return _SEH2_GetExceptionCode());
     }
     _SEH2_END;
-    if (!NT_SUCCESS(CallbackStatus)) return CallbackStatus;
 
     /* Check if we have GDI Batch operations */
     if (GdiBatchCount)
index 83d9c69..2e9c1c8 100644 (file)
@@ -849,10 +849,10 @@ NtDelayExecution(IN BOOLEAN Alertable,
 {
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
     LARGE_INTEGER SafeInterval;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
 
     /* Check the previous mode */
-    if(PreviousMode != KernelMode)
+    if (PreviousMode != KernelMode)
     {
         /* Enter SEH for probing */
         _SEH2_TRY
@@ -863,11 +863,10 @@ NtDelayExecution(IN BOOLEAN Alertable,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            /* Get SEH exception */
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if (!NT_SUCCESS(Status)) return Status;
    }
 
    /* Call the Kernel Function */
index af8f573..0233ea1 100644 (file)
@@ -160,7 +160,7 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
 {
     PLPCP_PORT_OBJECT Port, ReceivePort, ConnectionPort = NULL;
     KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(), WaitMode = PreviousMode;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PLPCP_MESSAGE Message;
     PETHREAD Thread = PsGetCurrentThread(), WakeupThread;
     PLPCP_CONNECTION_MESSAGE ConnectMessage;
@@ -200,14 +200,10 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
         _SEH2_EXCEPT(ExSystemExceptionFilter())
         {
             DPRINT1("SEH crash [1]\n");
-           DbgBreakPoint();
-            Status = _SEH2_GetExceptionCode();
+            DbgBreakPoint();
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-
-        /* Bail out if pointer was invalid */
-        if (!NT_SUCCESS(Status))
-            return Status;
     }
     else
     {
index 6b4ee12..dad5a35 100644 (file)
@@ -544,6 +544,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
         /* No callback, just copy the message */
         _SEH2_TRY
         {
+            /* Copy it */
             LpcpMoveMessage(&Message->Request,
                             LpcRequest,
                             LpcRequest + 1,
@@ -552,16 +553,12 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            Status = _SEH2_GetExceptionCode();
-        }
-        _SEH2_END;
-
-        if (!NT_SUCCESS(Status))
-        {
+            /* Fail */
             LpcpFreeToPortZone(Message, 0);
             ObDereferenceObject(Port);
-            return Status;
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
+        _SEH2_END;
 
         /* Acquire the LPC lock */
         KeAcquireGuardedMutex(&LpcpLock);
index dbf72a9..0d5d10d 100644 (file)
@@ -609,7 +609,7 @@ NtSetThreadExecutionState(IN EXECUTION_STATE esFlags,
             /* Check if the pointer is valid */
             ProbeForWriteUlong(PreviousFlags);
         }
-        _SEH2_EXCEPT(ExSystemExceptionFilter())
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
             /* It isn't -- fail */
             _SEH2_YIELD(return _SEH2_GetExceptionCode());
index 228753e..3dcf145 100644 (file)
@@ -120,25 +120,21 @@ VdmpInitialize(PVOID ControlData)
         return Status;
     }
 
-    /* Now, copy the first physical page into the first virtual page */
+    /* Enter SEH */
     _SEH2_TRY
     {
+        /* Copy the first physical page into the first virtual page */
         RtlMoveMemory(NullAddress, BaseAddress, ViewSize);
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
-        /* Get the status */
-        Status = _SEH2_GetExceptionCode();
-    }
-    _SEH2_END;
-
-    if (!NT_SUCCESS(Status))
-    {
+        /* Fail */
         DPRINT1("Couldn't copy first page (%x)\n", Status);
         ZwClose(PhysMemHandle);
         ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
-        return Status;
+        _SEH2_YIELD(return _SEH2_GetExceptionCode());
     }
+    _SEH2_END;
 
     /* Close physical memory section handle */
     ZwClose(PhysMemHandle);