[REACTX] Fix 64 bit issues
[reactos.git] / ntoskrnl / ps / process.c
index d59dfc6..c696276 100644 (file)
@@ -24,7 +24,7 @@ KGUARDED_MUTEX PspActiveProcessMutex;
 
 LARGE_INTEGER ShortPsLockDelay;
 
-ULONG PsRawPrioritySeparation = 0;
+ULONG PsRawPrioritySeparation;
 ULONG PsPrioritySeparation;
 CHAR PspForegroundQuantum[3];
 
@@ -255,11 +255,16 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
         /* Use a variable table */
         QuantumTable = PspVariableQuantums;
     }
-    else
+    else if (PspQuantumTypeFromMask(PrioritySeparation) == PSP_FIXED_QUANTUMS)
     {
         /* Use fixed table */
         QuantumTable = PspFixedQuantums;
     }
+    else
+    {
+        /* Use default for the type of system we're on */
+        QuantumTable = MmIsThisAnNtAsSystem() ? PspFixedQuantums : PspVariableQuantums;
+    }
 
     /* Now check if we should use long or short */
     if (PspQuantumLengthFromMask(PrioritySeparation) == PSP_LONG_QUANTUMS)
@@ -267,6 +272,16 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
         /* Use long quantums */
         QuantumTable += 3;
     }
+    else if (PspQuantumLengthFromMask(PrioritySeparation) == PSP_SHORT_QUANTUMS)
+    {
+        /* Keep existing table */
+        NOTHING;
+    }
+    else
+    {
+        /* Use default for the type of system we're on */
+        QuantumTable += MmIsThisAnNtAsSystem() ? 3 : 0;
+    }
 
     /* Check if we're using long fixed quantums */
     if (QuantumTable == &PspFixedQuantums[3])
@@ -292,12 +307,10 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
         Process = PsGetNextProcess(Process);
         while (Process)
         {
-            /*
-             * Use the priority separation, unless the process has
-             * low memory priority
-             */
-            i = (Process->Vm.Flags.MemoryPriority == 1) ?
-                0: PsPrioritySeparation;
+            /* Use the priority separation if this is a foreground process */
+            i = (Process->Vm.Flags.MemoryPriority ==
+                 MEMORY_PRIORITY_BACKGROUND) ?
+                 0: PsPrioritySeparation;
 
             /* Make sure that the process isn't idle */
             if (Process->PriorityClass != PROCESS_PRIORITY_CLASS_IDLE)
@@ -306,8 +319,7 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
                 if ((Process->Job) && (PspUseJobSchedulingClasses))
                 {
                     /* Use job quantum */
-                    Quantum = PspJobSchedulingClasses[Process->Job->
-                                                      SchedulingClass];
+                    Quantum = PspJobSchedulingClasses[Process->Job->SchedulingClass];
                 }
                 else
                 {
@@ -436,15 +448,14 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
     /* Check if we have a parent */
     if (Parent)
     {
-        /* Inherit PID and Hard Error Processing */
+        /* Inherit PID and hard-error processing */
         Process->InheritedFromUniqueProcessId = Parent->UniqueProcessId;
-        Process->DefaultHardErrorProcessing = Parent->
-                                              DefaultHardErrorProcessing;
+        Process->DefaultHardErrorProcessing = Parent->DefaultHardErrorProcessing;
     }
     else
     {
-        /* Use default hard error processing */
-        Process->DefaultHardErrorProcessing = TRUE;
+        /* Use default hard-error processing */
+        Process->DefaultHardErrorProcessing = SEM_FAILCRITICALERRORS;
     }
 
     /* Check for a section handle */
@@ -574,7 +585,8 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
                         PROCESS_PRIORITY_NORMAL,
                         Affinity,
                         DirectoryTableBase,
-                        (BOOLEAN)(Process->DefaultHardErrorProcessing & 4));
+                        BooleanFlagOn(Process->DefaultHardErrorProcessing,
+                                      SEM_NOALIGNMENTFAULTEXCEPT));
 
     /* Duplicate Parent Token */
     Status = PspInitializeProcessSecurity(Process, Parent);
@@ -702,7 +714,6 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
     {
         /* FIXME: We need to insert this process */
         DPRINT1("Jobs not yet supported\n");
-        ASSERT(FALSE);
     }
 
     /* Create PEB only for User-Mode Processes */
@@ -1279,7 +1290,7 @@ PsSetProcessWin32Process(
         if (Process->Win32Process == OldWin32Process)
         {
             /* Yes, so reset the win32 process to NULL */
-            Process->Win32Process = 0;
+            Process->Win32Process = NULL;
         }
         else
         {
@@ -1405,8 +1416,8 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
             "Parent: %p Attributes: %p\n", ParentProcess, ObjectAttributes);
 
     /* Set new-style flags */
-    if ((ULONG)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY;
-    if ((ULONG)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT;
+    if ((ULONG_PTR)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY;
+    if ((ULONG_PTR)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT;
     if (InheritObjectTable) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES;
 
     /* Call the new API */
@@ -1471,7 +1482,9 @@ NtOpenProcess(OUT PHANDLE ProcessHandle,
                          sizeof(OBJECT_ATTRIBUTES),
                          sizeof(ULONG));
             HasObjectName = (ObjectAttributes->ObjectName != NULL);
-            Attributes = ObjectAttributes->Attributes;
+
+            /* Validate user attributes */
+            Attributes = ObpValidateAttributes(ObjectAttributes->Attributes, PreviousMode);
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
@@ -1484,7 +1497,9 @@ NtOpenProcess(OUT PHANDLE ProcessHandle,
     {
         /* Otherwise just get the data directly */
         HasObjectName = (ObjectAttributes->ObjectName != NULL);
-        Attributes = ObjectAttributes->Attributes;
+
+        /* Still have to sanitize attributes */
+        Attributes = ObpValidateAttributes(ObjectAttributes->Attributes, PreviousMode);
     }
 
     /* Can't pass both, fail */