[ros-diffs] [ekohl] 47423: [NTOSKRNL / RTL] - Implement BreakOnTermination case for NtQueryInformationProcess and NtSetInformationProcess. - Implement RtlSetProcessIsCritical.

ekohl at svn.reactos.org ekohl at svn.reactos.org
Sat May 29 20:22:47 CEST 2010


Author: ekohl
Date: Sat May 29 20:22:47 2010
New Revision: 47423

URL: http://svn.reactos.org/svn/reactos?rev=47423&view=rev
Log:
[NTOSKRNL / RTL]
- Implement BreakOnTermination case for NtQueryInformationProcess and NtSetInformationProcess.
- Implement RtlSetProcessIsCritical.

Modified:
    trunk/reactos/include/ndk/rtlfuncs.h
    trunk/reactos/lib/rtl/process.c
    trunk/reactos/ntoskrnl/include/internal/ps_i.h
    trunk/reactos/ntoskrnl/ps/query.c

Modified: trunk/reactos/include/ndk/rtlfuncs.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/rtlfuncs.h?rev=47423&r1=47422&r2=47423&view=diff
==============================================================================
--- trunk/reactos/include/ndk/rtlfuncs.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/rtlfuncs.h [iso-8859-1] Sat May 29 20:22:47 2010
@@ -2042,12 +2042,12 @@
 );
 
 NTSYSAPI
-VOID
+NTSTATUS
 NTAPI
 RtlSetProcessIsCritical(
     IN BOOLEAN NewValue,
     OUT PBOOLEAN OldValue OPTIONAL,
-    IN BOOLEAN IsWinlogon
+    IN BOOLEAN NeedBreaks
 );
 
 NTSYSAPI

Modified: trunk/reactos/lib/rtl/process.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/process.c?rev=47423&r1=47422&r2=47423&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/process.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/process.c [iso-8859-1] Sat May 29 20:22:47 2010
@@ -5,6 +5,7 @@
  * PURPOSE:           Process functions
  * PROGRAMMER:        Alex Ionescu (alex at relsoft.net)
  *                    Ariadne (ariadne at xs4all.nl)
+ *                    Eric Kohl
  */
 
 /* INCLUDES ****************************************************************/
@@ -351,18 +352,45 @@
 }
 
 /*
- * @unimplemented
- */
-NTSYSAPI
-VOID
-NTAPI
-RtlSetProcessIsCritical(
-    IN   BOOLEAN   NewValue,
-    OUT  PBOOLEAN  OldValue OPTIONAL,
-    IN   BOOLEAN   IsWinlogon)
-{
-	//TODO
-    UNIMPLEMENTED;
+ * @implemented
+ *
+ * NOTES:
+ *   Implementation based on the documentation from:
+ *   http://www.geoffchappell.com/studies/windows/win32/ntdll/api/rtl/peb/setprocessiscritical.htm
+ */
+NTSTATUS
+NTAPI
+RtlSetProcessIsCritical(IN BOOLEAN NewValue,
+                        OUT PBOOLEAN OldValue OPTIONAL,
+                        IN BOOLEAN NeedBreaks)
+{
+    ULONG BreakOnTermination = FALSE;
+
+    if (OldValue)
+        *OldValue = FALSE;
+
+    /* Fail, if the critical breaks flag is required but is not set */
+    if (NeedBreaks == TRUE &&
+        !(NtCurrentPeb()->NtGlobalFlag & FLG_ENABLE_SYSTEM_CRIT_BREAKS))
+        return STATUS_UNSUCCESSFUL;
+
+    if (OldValue)
+    {
+        /* Query and return the old break on termination flag for the process */
+        ZwQueryInformationProcess(NtCurrentProcess(),
+                                  ProcessBreakOnTermination,
+                                  &BreakOnTermination,
+                                  sizeof(ULONG),
+                                  NULL);
+        *OldValue = (BOOLEAN)BreakOnTermination;
+    }
+
+    /* Set the break on termination flag for the process */
+    BreakOnTermination = NewValue;
+    return ZwSetInformationProcess(NtCurrentProcess(),
+                                   ProcessBreakOnTermination,
+                                   &BreakOnTermination,
+                                   sizeof(ULONG));
 }
 
 ULONG

Modified: trunk/reactos/ntoskrnl/include/internal/ps_i.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/ps_i.h?rev=47423&r1=47422&r2=47423&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ps_i.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ps_i.h [iso-8859-1] Sat May 29 20:22:47 2010
@@ -249,9 +249,9 @@
     /* ProcessBreakOnTermination */
     IQS_SAME
     (
-        UCHAR,
-        UCHAR,
-        0
+        ULONG,
+        ULONG,
+        ICIF_QUERY | ICIF_SET
     ),
 
     /* ProcessDebugObjectHandle */

Modified: trunk/reactos/ntoskrnl/ps/query.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/query.c?rev=47423&r1=47422&r2=47423&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ps/query.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ps/query.c [iso-8859-1] Sat May 29 20:22:47 2010
@@ -5,6 +5,7 @@
  * PURPOSE:         Process Manager: Thread/Process Query/Set Information
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu at reactos.org)
  *                  Thomas Weidenmueller (w3seek at reactos.org)
+ *                  Eric Kohl
  */
 
 /* INCLUDES ******************************************************************/
@@ -735,6 +736,43 @@
             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:
 
@@ -1144,6 +1182,35 @@
 
             DPRINT1("Not implemented: ProcessDebugPort\n");
             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 */




More information about the Ros-diffs mailing list