[FORMATTING]
[reactos.git] / reactos / lib / rtl / process.c
index 25d68e9..50e36eb 100644 (file)
@@ -5,6 +5,7 @@
  * PURPOSE:           Process functions
  * PROGRAMMER:        Alex Ionescu (alex@relsoft.net)
  *                    Ariadne (ariadne@xs4all.nl)
+ *                    Eric Kohl
  */
 
 /* INCLUDES ****************************************************************/
@@ -42,7 +43,7 @@ RtlpMapFile(PUNICODE_STRING ImageFileName,
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to read image file from disk\n");
-        return(Status);
+        return Status;
     }
 
     /* Now create a section for this image */
@@ -93,7 +94,7 @@ RtlpInitEnvironment(HANDLE ProcessHandle,
         if (!NT_SUCCESS(Status))
         {
             DPRINT1("Failed to reserve 1MB of space \n");
-            return(Status);
+            return Status;
         }
     }
 
@@ -117,7 +118,7 @@ RtlpInitEnvironment(HANDLE ProcessHandle,
         if (!NT_SUCCESS(Status))
         {
             DPRINT1("Failed to allocate Environment Block\n");
-            return(Status);
+            return Status;
         }
 
         /* Write the Environment Block */
@@ -143,7 +144,7 @@ RtlpInitEnvironment(HANDLE ProcessHandle,
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to allocate Parameter Block\n");
-        return(Status);
+        return Status;
     }
 
     /* Write the Parameter Block */
@@ -195,7 +196,7 @@ RtlCreateUserProcess(IN PUNICODE_STRING ImageFileName,
     HANDLE hSection;
     PROCESS_BASIC_INFORMATION ProcessBasicInfo;
     OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING DebugString = RTL_CONSTANT_STRING(L"\\WindowsSS");;
+    UNICODE_STRING DebugString = RTL_CONSTANT_STRING(L"\\WindowsSS");
     DPRINT("RtlCreateUserProcess: %wZ\n", ImageFileName);
 
     /* Map and Load the File */
@@ -244,7 +245,7 @@ RtlCreateUserProcess(IN PUNICODE_STRING ImageFileName,
     {
         DPRINT1("Could not create Kernel Process Object\n");
         ZwClose(hSection);
-        return(Status);
+        return Status;
     }
 
     /* Get some information on the image */
@@ -258,7 +259,7 @@ RtlCreateUserProcess(IN PUNICODE_STRING ImageFileName,
         DPRINT1("Could not query Section Info\n");
         ZwClose(ProcessInfo->ProcessHandle);
         ZwClose(hSection);
-        return(Status);
+        return Status;
     }
 
     /* Get some information about the process */
@@ -272,7 +273,7 @@ RtlCreateUserProcess(IN PUNICODE_STRING ImageFileName,
         DPRINT1("Could not query Process Info\n");
         ZwClose(ProcessInfo->ProcessHandle);
         ZwClose(hSection);
-        return(Status);
+        return Status;
     }
 
     /* Create Process Environment */
@@ -311,36 +312,90 @@ PVOID
 NTAPI
 RtlEncodePointer(IN PVOID Pointer)
 {
-  ULONG Cookie;
-  NTSTATUS Status;
-
-  Status = ZwQueryInformationProcess(NtCurrentProcess(),
-                                     ProcessCookie,
-                                     &Cookie,
-                                     sizeof(Cookie),
-                                     NULL);
-
-  if(!NT_SUCCESS(Status))
-  {
-    DPRINT1("Failed to receive the process cookie! Status: 0x%lx\n", Status);
-    return Pointer;
-  }
-
-  return (PVOID)((ULONG_PTR)Pointer ^ Cookie);
+    ULONG Cookie;
+    NTSTATUS Status;
+
+    Status = ZwQueryInformationProcess(NtCurrentProcess(),
+                                       ProcessCookie,
+                                       &Cookie,
+                                       sizeof(Cookie),
+                                       NULL);
+    if(!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to receive the process cookie! Status: 0x%lx\n", Status);
+        return Pointer;
+    }
+
+    return (PVOID)((ULONG_PTR)Pointer ^ Cookie);
+}
+
+/*
+ * @implemented
+ */
+PVOID
+NTAPI
+RtlDecodePointer(IN PVOID Pointer)
+{
+    return RtlEncodePointer(Pointer);
 }
 
 /*
  * @unimplemented
  */
-NTSYSAPI
-VOID
+PVOID
 NTAPI
-RtlSetProcessIsCritical(
-    IN   BOOLEAN   NewValue,
-    OUT  PBOOLEAN  OldValue OPTIONAL,
-    IN   BOOLEAN   IsWinlogon)
+RtlEncodeSystemPointer(IN PVOID Pointer)
 {
-       //TODO
+    UNIMPLEMENTED;
+    return NULL;
 }
 
-/* EOF */
+/*
+ * @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
+NTAPI
+RtlGetCurrentProcessorNumber(VOID)
+{
+    /* Forward to kernel */
+    return NtGetCurrentProcessorNumber();
+}