- Make use of _SEH2_YIELD in Ex, Io, Ob, Ps and Se.
[reactos.git] / reactos / ntoskrnl / ex / timer.c
index 65a43b0..5ad5e4a 100644 (file)
@@ -254,22 +254,23 @@ NtCancelTimer(IN HANDLE TimerHandle,
     KIRQL OldIrql;
     PETHREAD TimerThread;
     ULONG DerefsToDo = 1;
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PAGED_CODE();
 
-    /* Check Parameter Validity */
+    /* Check if we need to probe */
     if ((CurrentState) && (PreviousMode != KernelMode))
     {
         _SEH2_TRY
         {
+            /* Make sure the pointer is valid */
             ProbeForWriteBoolean(CurrentState);
         }
-        _SEH2_EXCEPT(ExSystemExceptionFilter())
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
 
     /* Get the Timer Object */
@@ -341,11 +342,12 @@ NtCancelTimer(IN HANDLE TimerHandle,
         /* Dereference the Object */
         ObDereferenceObjectEx(Timer, DerefsToDo);
 
-        /* Make sure it's safe to write to the handle */
+        /* Check if caller wants the state */
         if (CurrentState)
         {
             _SEH2_TRY
             {
+                /* Return the Timer State */
                 *CurrentState = State;
             }
             _SEH2_EXCEPT(ExSystemExceptionFilter())
@@ -370,7 +372,7 @@ NtCreateTimer(OUT PHANDLE TimerHandle,
     PETIMER Timer;
     HANDLE hTimer;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PAGED_CODE();
 
     /* Check for correct timer type */
@@ -381,19 +383,20 @@ NtCreateTimer(OUT PHANDLE TimerHandle,
         return STATUS_INVALID_PARAMETER_4;
     }
 
-    /* Check Parameter Validity */
+    /* Check if we need to probe */
     if (PreviousMode != KernelMode)
     {
         _SEH2_TRY
         {
+            /* Make sure the pointer is valid */
             ProbeForWriteHandle(TimerHandle);
         }
-        _SEH2_EXCEPT(ExSystemExceptionFilter())
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
 
     /* Create the Object */
@@ -431,9 +434,10 @@ NtCreateTimer(OUT PHANDLE TimerHandle,
         /* Check for success */
         if (NT_SUCCESS(Status))
         {
-            /* Make sure it's safe to write to the handle */
+            /* Enter SEH */
             _SEH2_TRY
             {
+                /* Return the Timer Handle */
                 *TimerHandle = hTimer;
             }
             _SEH2_EXCEPT(ExSystemExceptionFilter())
@@ -456,7 +460,7 @@ NtOpenTimer(OUT PHANDLE TimerHandle,
 {
     HANDLE hTimer;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     PAGED_CODE();
 
     /* Check Parameter Validity */
@@ -464,14 +468,15 @@ NtOpenTimer(OUT PHANDLE TimerHandle,
     {
         _SEH2_TRY
         {
+            /* Make sure the pointer is valid */
             ProbeForWriteHandle(TimerHandle);
         }
         _SEH2_EXCEPT(ExSystemExceptionFilter())
         {
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
 
     /* Open the Timer */
@@ -484,9 +489,10 @@ NtOpenTimer(OUT PHANDLE TimerHandle,
                                 &hTimer);
     if (NT_SUCCESS(Status))
     {
-        /* Make sure it's safe to write to the handle */
+        /* Enter SEH */
         _SEH2_TRY
         {
+            /* Return the Timer Handle */
             *TimerHandle = hTimer;
         }
         _SEH2_EXCEPT(ExSystemExceptionFilter())
@@ -523,7 +529,7 @@ NtQueryTimer(IN HANDLE TimerHandle,
                                          TimerInformationLength,
                                          ReturnLength,
                                          PreviousMode);
-    if(!NT_SUCCESS(Status)) return Status;
+    if (!NT_SUCCESS(Status)) return Status;
 
     /* Get the Timer Object */
     Status = ObReferenceObjectByHandle(TimerHandle,
@@ -532,7 +538,7 @@ NtQueryTimer(IN HANDLE TimerHandle,
                                        PreviousMode,
                                        (PVOID*)&Timer,
                                        NULL);
-    if(NT_SUCCESS(Status))
+    if (NT_SUCCESS(Status))
     {
         /* Return the Basic Information */
         _SEH2_TRY
@@ -550,6 +556,7 @@ NtQueryTimer(IN HANDLE TimerHandle,
         }
         _SEH2_EXCEPT(ExSystemExceptionFilter())
         {
+            /* Get the exception code */
             Status = _SEH2_GetExceptionCode();
         }
         _SEH2_END;
@@ -586,20 +593,23 @@ NtSetTimer(IN HANDLE TimerHandle,
     /* Check for a valid Period */
     if (Period < 0) return STATUS_INVALID_PARAMETER_6;
 
-    /* Check Parameter Validity */
+    /* Check if we need to probe */
     if (PreviousMode != KernelMode)
     {
         _SEH2_TRY
         {
+            /* Probe and capture the due time */
             TimerDueTime = ProbeForReadLargeInteger(DueTime);
+
+            /* Probe the state pointer if one was passed */
             if (PreviousState) ProbeForWriteBoolean(PreviousState);
         }
-        _SEH2_EXCEPT(ExSystemExceptionFilter())
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
-            Status = _SEH2_GetExceptionCode();
+            /* Return the exception code */
+            _SEH2_YIELD(return _SEH2_GetExceptionCode());
         }
         _SEH2_END;
-        if(!NT_SUCCESS(Status)) return Status;
     }
     else
     {
@@ -715,15 +725,18 @@ NtSetTimer(IN HANDLE TimerHandle,
         /* Dereference if it was previously enabled */
         if (DerefsToDo) ObDereferenceObjectEx(Timer, DerefsToDo);
 
-        /* Make sure it's safe to write to the handle */
+        /* Check if we need to return the State */
         if (PreviousState)
         {
+            /* Enter SEH */
             _SEH2_TRY
             {
+                /* Return the Timer State */
                 *PreviousState = State;
             }
             _SEH2_EXCEPT(ExSystemExceptionFilter())
             {
+
             }
             _SEH2_END;
         }