- Make use of _SEH2_YIELD in Ex, Io, Ob, Ps and Se.
[reactos.git] / reactos / ntoskrnl / ps / query.c
index a94cc46..6a340df 100644 (file)
@@ -63,7 +63,7 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
 {
     PEPROCESS Process;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     ULONG Length = 0;
     PPROCESS_BASIC_INFORMATION ProcessBasicInfo =
         (PPROCESS_BASIC_INFORMATION)ProcessInformation;
@@ -86,18 +86,20 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
         /* Prepare to probe parameters */
         _SEH2_TRY
         {
+            /* Probe the buffer */
             ProbeForWrite(ProcessInformation,
                           ProcessInformationLength,
                           sizeof(ULONG));
+
+            /* Probe the return length if required */
             if (ReturnLength) ProbeForWriteUlong(ReturnLength);
         }
         _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;
     }
 
     if((ProcessInformationClass == ProcessCookie) &&
@@ -761,6 +763,9 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
                 Length = sizeof(ULONG);
             }
 
+            /* Indicate success */
+            Status = STATUS_SUCCESS;
+
             /* Enter SEH to protect write */
             _SEH2_TRY
             {
@@ -882,11 +887,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             }
             _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)) break;
 
             /* Get the LPC Port */
             Status = ObReferenceObjectByHandle(PortHandle,
@@ -927,11 +931,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             }
             _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)) break;
 
             /* Assign the actual token */
             Status = PspSetPrimaryToken(Process, TokenHandle, NULL);
@@ -980,11 +983,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             }
             _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)) break;
 
             /* Setting the session id requires the SeTcbPrivilege */
             if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode))
@@ -1048,11 +1050,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             }
             _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)) break;
 
             /* Check for invalid PriorityClass value */
             if (PriorityClass.PriorityClass > PROCESS_PRIORITY_CLASS_ABOVE_NORMAL)
@@ -1250,11 +1251,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Validate it */
             if ((Priority > HIGH_PRIORITY) ||
@@ -1286,11 +1286,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Validate it */
             if ((Priority > THREAD_BASE_PRIORITY_MAX) ||
@@ -1332,11 +1331,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Validate it */
             if (!Affinity)
@@ -1400,11 +1398,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Assign the actual token */
             Status = PsAssignImpersonationToken(Thread, TokenHandle);
@@ -1427,11 +1424,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Set the address */
             Thread->Win32StartAddress = Address;
@@ -1454,11 +1450,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Validate it */
             if (IdealProcessor > MAXIMUM_PROCESSORS)
@@ -1502,11 +1497,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* Call the kernel */
             KeSetDisableBoostThread(&Thread->Tcb, (BOOLEAN)DisableBoost);
@@ -1529,11 +1523,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             }
             _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)) break;
 
             /* This is only valid for the current thread */
             if (Thread != PsGetCurrentThread())
@@ -1614,7 +1607,7 @@ NtQueryInformationThread(IN HANDLE ThreadHandle,
 {
     PETHREAD Thread;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-    NTSTATUS Status = STATUS_SUCCESS;
+    NTSTATUS Status;
     ULONG Access;
     ULONG Length = 0;
     PTHREAD_BASIC_INFORMATION ThreadBasicInfo =
@@ -1623,26 +1616,26 @@ NtQueryInformationThread(IN HANDLE ThreadHandle,
     KIRQL OldIrql;
     PAGED_CODE();
 
+    /* Check if we were called from user mode */
     if (PreviousMode != KernelMode)
     {
+        /* Enter SEH */
         _SEH2_TRY
         {
+            /* Probe the buffer */
             ProbeForWrite(ThreadInformation,
                           ThreadInformationLength,
                           sizeof(ULONG));
 
-            if (ReturnLength)
-            {
-                ProbeForWriteUlong(ReturnLength);
-            }
+            /* Probe the return length if required */
+            if (ReturnLength) ProbeForWriteUlong(ReturnLength);
         }
         _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;
     }
 
     /* Check what class this is */