[ros-diffs] [sginsberg] 42923: - Use _SEH2_YIELD when returning from an exception instead of returning outside the SEH block. Avoids unnecessary status checks for the most common case (no exception). Move the cleanup code into the handler too in favor of the no-exception case. Futhermore, don't call ExSystemExceptionFilter when we know we are called from user mode. Finally, only enter SEH if we need to do any probing. - 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).

sginsberg at svn.reactos.org sginsberg at svn.reactos.org
Mon Aug 24 21:58:15 CEST 2009


Author: sginsberg
Date: Mon Aug 24 21:58:15 2009
New Revision: 42923

URL: http://svn.reactos.org/svn/reactos?rev=42923&view=rev
Log:
- Use _SEH2_YIELD when returning from an exception instead of returning outside the SEH block. Avoids unnecessary status checks for the most common case (no exception). Move the cleanup code into the handler too in favor of the no-exception case. Futhermore, don't call ExSystemExceptionFilter when we know we are called from user mode. Finally, only enter SEH if we need to do any probing.
- 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).

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

Modified: trunk/reactos/lib/rtl/debug.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/debug.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/debug.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/debug.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -54,7 +54,7 @@
                               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 @@
         !(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 @@
     {
         /* 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)

Modified: trunk/reactos/ntoskrnl/config/ntapi.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/ntapi.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/config/ntapi.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/ntapi.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -27,7 +27,7 @@
             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 @@
         }
         _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 @@
 {
     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 @@
         }
         _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 */
@@ -268,16 +266,11 @@
         }
         _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 */
@@ -357,16 +350,11 @@
         }
         _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 */
@@ -476,16 +464,11 @@
         }
         _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 */
@@ -556,16 +539,11 @@
         }
         _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 @@
              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 @@
         }
         _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
     {

Modified: trunk/reactos/ntoskrnl/dbgk/dbgkobj.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/dbgk/dbgkobj.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/dbgk/dbgkobj.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/dbgk/dbgkobj.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -1517,7 +1517,7 @@
     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 @@
         }
         _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 @@
 {
     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 @@
         }
         _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 @@
 {
     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 @@
                                        DebugInformation,
                                        DebugInformationLength,
                                        PreviousMode);
+    if (!NT_SUCCESS(Status)) return Status;
 
     /* Check if the caller wanted the return length */
     if (ReturnLength)
@@ -1894,12 +1893,11 @@
         }
         _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 @@
     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 @@
         }
         _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
     {

Modified: trunk/reactos/ntoskrnl/ke/except.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/except.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/except.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/except.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -97,13 +97,12 @@
     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 @@
                          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 @@
             /* 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,

Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/exp.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/exp.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/i386/exp.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -1072,7 +1072,6 @@
 NTAPI
 KeRaiseUserException(IN NTSTATUS ExceptionCode)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
     ULONG OldEip;
     PTEB Teb = KeGetCurrentThread()->Teb;
     PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
@@ -1085,11 +1084,10 @@
     }
     _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;

Modified: trunk/reactos/ntoskrnl/ke/i386/usercall.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/usercall.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/usercall.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/i386/usercall.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -135,7 +135,7 @@
 {
     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 @@
     _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)

Modified: trunk/reactos/ntoskrnl/ke/wait.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/wait.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/wait.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/wait.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -849,10 +849,10 @@
 {
     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 @@
         }
         _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 */

Modified: trunk/reactos/ntoskrnl/lpc/reply.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/reply.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/reply.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/reply.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -160,7 +160,7 @@
 {
     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 @@
         _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
     {

Modified: trunk/reactos/ntoskrnl/lpc/send.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/send.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/send.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/send.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -544,6 +544,7 @@
         /* No callback, just copy the message */
         _SEH2_TRY
         {
+            /* Copy it */
             LpcpMoveMessage(&Message->Request,
                             LpcRequest,
                             LpcRequest + 1,
@@ -552,16 +553,12 @@
         }
         _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);

Modified: trunk/reactos/ntoskrnl/po/power.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/po/power.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/po/power.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/po/power.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -609,7 +609,7 @@
             /* 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());

Modified: trunk/reactos/ntoskrnl/vdm/vdmmain.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/vdm/vdmmain.c?rev=42923&r1=42922&r2=42923&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/vdm/vdmmain.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/vdm/vdmmain.c [iso-8859-1] Mon Aug 24 21:58:15 2009
@@ -120,25 +120,21 @@
         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);




More information about the Ros-diffs mailing list