[NTOS]: Fix Implementation of BreakOnTermination -- Process Flags should be accessed...
[reactos.git] / reactos / ntoskrnl / ps / query.c
index d27ff3e..342c818 100644 (file)
@@ -753,8 +753,7 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
                                                PreviousMode,
                                                (PVOID*)&Process,
                                                NULL);
                                                PreviousMode,
                                                (PVOID*)&Process,
                                                NULL);
-            if (!NT_SUCCESS(Status))
-                break;
+            if (!NT_SUCCESS(Status)) break;
 
             /* Enter SEH for writing back data */
             _SEH2_TRY
 
             /* Enter SEH for writing back data */
             _SEH2_TRY
@@ -869,6 +868,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
     PROCESS_SESSION_INFORMATION SessionInfo = {0};
     PROCESS_PRIORITY_CLASS PriorityClass = {0};
     PVOID ExceptionPort;
     PROCESS_SESSION_INFORMATION SessionInfo = {0};
     PROCESS_PRIORITY_CLASS PriorityClass = {0};
     PVOID ExceptionPort;
+    ULONG Break;
     PAGED_CODE();
 
     /* Verify Information Class validity */
     PAGED_CODE();
 
     /* Verify Information Class validity */
@@ -927,11 +927,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Get the LPC Port */
             Status = ObReferenceObjectByHandle(PortHandle,
                                                0,
             /* Get the LPC Port */
             Status = ObReferenceObjectByHandle(PortHandle,
                                                0,
@@ -973,11 +972,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Assign the actual token */
             Status = PspSetPrimaryToken(Process, TokenHandle, NULL);
             break;
             /* Assign the actual token */
             Status = PspSetPrimaryToken(Process, TokenHandle, NULL);
             break;
@@ -1027,11 +1025,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Setting the session id requires the SeTcbPrivilege */
             if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode))
             {
             /* Setting the session id requires the SeTcbPrivilege */
             if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode))
             {
@@ -1096,11 +1093,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             {
                 /* Return the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Return the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Check for invalid PriorityClass value */
             if (PriorityClass.PriorityClass > PROCESS_PRIORITY_CLASS_ABOVE_NORMAL)
             {
             /* Check for invalid PriorityClass value */
             if (PriorityClass.PriorityClass > PROCESS_PRIORITY_CLASS_ABOVE_NORMAL)
             {
@@ -1201,24 +1197,37 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
                 break;
             }
 
                 break;
             }
 
-            /* Setting 'break on termination' requires the SeDebugPrivilege */
-            if (!SeSinglePrivilegeCheck(SeDebugPrivilege, PreviousMode))
-            {
-                Status = STATUS_PRIVILEGE_NOT_HELD;
-                break;
-            }
-
             /* Enter SEH for direct buffer read */
             _SEH2_TRY
             {
             /* Enter SEH for direct buffer read */
             _SEH2_TRY
             {
-                Process->BreakOnTermination = *(PULONG)ProcessInformation;
+                Break = *(PULONG)ProcessInformation;
             }
             _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
             {
                 /* Get exception code */
             }
             _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
             {
                 /* Get exception code */
+                Break = 0;
                 Status = _SEH2_GetExceptionCode();
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
             }
             _SEH2_END;
+            
+            /* Setting 'break on termination' requires the SeDebugPrivilege */
+            if (!SeSinglePrivilegeCheck(SeDebugPrivilege, PreviousMode))
+            {
+                Status = STATUS_PRIVILEGE_NOT_HELD;
+                break;
+            }
+            
+            /* Set or clear the flag */
+            if (Break)
+            {
+                PspSetProcessFlag(Process, PSF_BREAK_ON_TERMINATION_BIT);
+            }
+            else
+            {
+                PspClearProcessFlag(Process, PSF_BREAK_ON_TERMINATION_BIT);
+            }
+
             break;
 
         /* We currently don't implement any of these */
             break;
 
         /* We currently don't implement any of these */
@@ -1328,11 +1337,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Validate it */
             if ((Priority > HIGH_PRIORITY) ||
                 (Priority <= LOW_PRIORITY))
             /* Validate it */
             if ((Priority > HIGH_PRIORITY) ||
                 (Priority <= LOW_PRIORITY))
@@ -1365,11 +1373,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Validate it */
             if ((Priority > THREAD_BASE_PRIORITY_MAX) ||
                 (Priority < THREAD_BASE_PRIORITY_MIN))
             /* Validate it */
             if ((Priority > THREAD_BASE_PRIORITY_MAX) ||
                 (Priority < THREAD_BASE_PRIORITY_MIN))
@@ -1479,11 +1486,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Assign the actual token */
             Status = PsAssignImpersonationToken(Thread, TokenHandle);
             break;
             /* Assign the actual token */
             Status = PsAssignImpersonationToken(Thread, TokenHandle);
             break;
@@ -1507,11 +1513,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Set the address */
             Thread->Win32StartAddress = Address;
             break;
             /* Set the address */
             Thread->Win32StartAddress = Address;
             break;
@@ -1535,11 +1540,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Validate it */
             if (IdealProcessor > MAXIMUM_PROCESSORS)
             {
             /* Validate it */
             if (IdealProcessor > MAXIMUM_PROCESSORS)
             {
@@ -1584,11 +1588,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* Call the kernel */
             KeSetDisableBoostThread(&Thread->Tcb, (BOOLEAN)DisableBoost);
             break;
             /* Call the kernel */
             KeSetDisableBoostThread(&Thread->Tcb, (BOOLEAN)DisableBoost);
             break;
@@ -1612,11 +1615,10 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
             {
                 /* Get the exception code */
                 Status = _SEH2_GetExceptionCode();
+                _SEH2_YIELD(break);
             }
             _SEH2_END;
 
             }
             _SEH2_END;
 
-            if (!NT_SUCCESS(Status)) break;
-
             /* This is only valid for the current thread */
             if (Thread != PsGetCurrentThread())
             {
             /* This is only valid for the current thread */
             if (Thread != PsGetCurrentThread())
             {