[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / ps / query.c
index a94cc46..d27ff3e 100644 (file)
@@ -5,6 +5,7 @@
  * PURPOSE:         Process Manager: Thread/Process Query/Set Information
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
  *                  Thomas Weidenmueller (w3seek@reactos.org)
+ *                  Eric Kohl
  */
 
 /* INCLUDES ******************************************************************/
@@ -63,7 +64,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 +87,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) &&
@@ -191,8 +194,8 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
                         Process->Vm.MinimumWorkingSetSize << PAGE_SHIFT;
 
                 /* Set default time limits */
-                QuotaLimits->TimeLimit.LowPart = (ULONG)-1;
-                QuotaLimits->TimeLimit.HighPart = (ULONG)-1;
+                QuotaLimits->TimeLimit.LowPart = MAXULONG;
+                QuotaLimits->TimeLimit.HighPart = MAXULONG;
 
                 /* Is quota block a default one? */
                 if (Process->QuotaBlock == &PspDefaultQuotaBlock)
@@ -733,6 +736,43 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
             ObDereferenceObject(Process);
             break;
 
+        case ProcessBreakOnTermination:
+
+            /* Set the return length*/
+            Length = sizeof(ULONG);
+            if (ProcessInformationLength != Length)
+            {
+                Status = STATUS_INFO_LENGTH_MISMATCH;
+                break;
+            }
+
+            /* Reference the process */
+            Status = ObReferenceObjectByHandle(ProcessHandle,
+                                               PROCESS_QUERY_INFORMATION,
+                                               PsProcessType,
+                                               PreviousMode,
+                                               (PVOID*)&Process,
+                                               NULL);
+            if (!NT_SUCCESS(Status))
+                break;
+
+            /* Enter SEH for writing back data */
+            _SEH2_TRY
+            {
+                /* Return the BreakOnTermination state */
+                *(PULONG)ProcessInformation = Process->BreakOnTermination;
+            }
+            _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+            {
+                /* Get the exception code */
+                Status = _SEH2_GetExceptionCode();
+            }
+            _SEH2_END;
+
+            /* Dereference the process */
+            ObDereferenceObject(Process);
+            break;
+
         /* Per-process security cookie */
         case ProcessCookie:
 
@@ -761,6 +801,9 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
                 Length = sizeof(ULONG);
             }
 
+            /* Indicate success */
+            Status = STATUS_SUCCESS;
+
             /* Enter SEH to protect write */
             _SEH2_TRY
             {
@@ -886,6 +929,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Get the LPC Port */
@@ -931,6 +975,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Assign the actual token */
@@ -984,6 +1029,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Setting the session id requires the SeTcbPrivilege */
@@ -1048,10 +1094,11 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             }
             _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
             {
-                /* Get the exception code */
+                /* Return the exception code */
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Check for invalid PriorityClass value */
@@ -1145,6 +1192,35 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
             Status = STATUS_NOT_IMPLEMENTED;
             break;
 
+        case ProcessBreakOnTermination:
+
+            /* Check buffer length */
+            if (ProcessInformationLength != sizeof(ULONG))
+            {
+                Status = STATUS_INFO_LENGTH_MISMATCH;
+                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
+            {
+                Process->BreakOnTermination = *(PULONG)ProcessInformation;
+            }
+            _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+            {
+                /* Get exception code */
+                Status = _SEH2_GetExceptionCode();
+            }
+            _SEH2_END;
+            break;
+
         /* We currently don't implement any of these */
         case ProcessLdtInformation:
         case ProcessLdtSize:
@@ -1220,7 +1296,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
         Access = THREAD_SET_THREAD_TOKEN;
     }
 
-    /* Reference the process */
+    /* Reference the thread */
     Status = ObReferenceObjectByHandle(ThreadHandle,
                                        Access,
                                        PsThreadType,
@@ -1254,6 +1330,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Validate it */
@@ -1290,6 +1367,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Validate it */
@@ -1336,7 +1414,6 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
-            if (!NT_SUCCESS(Status)) break;
 
             /* Validate it */
             if (!Affinity)
@@ -1404,6 +1481,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Assign the actual token */
@@ -1431,6 +1509,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Set the address */
@@ -1458,6 +1537,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Validate it */
@@ -1506,6 +1586,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* Call the kernel */
@@ -1533,6 +1614,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle,
                 Status = _SEH2_GetExceptionCode();
             }
             _SEH2_END;
+
             if (!NT_SUCCESS(Status)) break;
 
             /* This is only valid for the current thread */
@@ -1614,7 +1696,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 +1705,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 */
@@ -1826,9 +1908,19 @@ NtQueryInformationThread(IN HANDLE ThreadHandle,
             KeLowerIrql(OldIrql);
             break;
 
+        /* LDT and GDT information */
         case ThreadDescriptorTableEntry:
-            DPRINT1("NtQueryInformationThread(): case ThreadDescriptorTableEntry not implemented!\n");
+
+#if defined(_X86_)
+            /* Call the worker routine */
+            Status = PspQueryDescriptorThread(Thread,
+                                              ThreadInformation,
+                                              ThreadInformationLength,
+                                              ReturnLength);
+#else
+            /* Only implemented on x86 */
             Status = STATUS_NOT_IMPLEMENTED;
+#endif
             break;
 
         case ThreadPriorityBoost: