- Last patch was incomplete, apologies. SVN @ 5AM = bad idea.
authorAlex Ionescu <aionescu@gmail.com>
Tue, 9 Aug 2005 08:50:57 +0000 (08:50 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Tue, 9 Aug 2005 08:50:57 +0000 (08:50 +0000)
- Do not report that ROS is running on 0 active processors, that's a bad idea.
- Actually check the affinity mask set by NtSetInformationThread
- Fix the check in KeSetAffinityThread
- Give a valid affinity to the system thread (corresponding to the active cpu affinity set).

This removes all bugchecks from the kernel32 thread winetest.

svn path=/trunk/; revision=17235

reactos/ntoskrnl/include/internal/ke.h
reactos/ntoskrnl/ke/kthread.c
reactos/ntoskrnl/ke/main.c
reactos/ntoskrnl/ps/psmgr.c
reactos/ntoskrnl/ps/query.c

index ebef9d0..507d5b2 100644 (file)
@@ -226,6 +226,12 @@ LONG
 STDCALL
 KeQueryBasePriorityThread(IN PKTHREAD Thread);
 
+VOID
+STDCALL
+KiSetPriorityThread(PKTHREAD Thread,
+                    KPRIORITY Priority,
+                    PBOOLEAN Released);
+
 VOID
 STDCALL
 KeStackAttachProcess (
index ce2c14d..4b41b63 100644 (file)
@@ -1299,7 +1299,12 @@ KeSetAffinityThread(PKTHREAD Thread,
 
     DPRINT("KeSetAffinityThread(Thread %x, Affinity %x)\n", Thread, Affinity);
 
-    ASSERT(Affinity & ((1 << KeNumberProcessors) - 1));
+    /* Verify correct affinity */
+    if ((Affinity & Thread->ApcStatePointer[0]->Process->Affinity) !=
+        Affinity || !Affinity)
+    {
+        KEBUGCHECK(INVALID_AFFINITY_SET);
+    }
 
     OldIrql = KeAcquireDispatcherDatabaseLock();
 
index 70e19f7..0e3d7f8 100644 (file)
@@ -25,7 +25,7 @@ ULONG NtOSCSDVersion = BUILD_OSCSDVERSION(6, 0);
 EXPORTED ULONG NtBuildNumber = KERNEL_VERSION_BUILD;
 EXPORTED ULONG NtGlobalFlag = 0;
 EXPORTED CHAR  KeNumberProcessors;
-EXPORTED KAFFINITY KeActiveProcessors;
+EXPORTED KAFFINITY KeActiveProcessors = 1;
 EXPORTED LOADER_PARAMETER_BLOCK KeLoaderBlock;
 EXPORTED ULONG KeDcacheFlushCount = 0;
 EXPORTED ULONG KeIcacheFlushCount = 0;
index a384db6..23615ba 100644 (file)
@@ -213,7 +213,7 @@ PsInitProcessManagment(VOID)
 
    /* System threads may run on any processor. */
    RtlZeroMemory(PsInitialSystemProcess, sizeof(EPROCESS));
-   PsInitialSystemProcess->Pcb.Affinity = 0xFFFFFFFF;
+   PsInitialSystemProcess->Pcb.Affinity = KeActiveProcessors;
    PsInitialSystemProcess->Pcb.IopmOffset = 0xffff;
    PsInitialSystemProcess->Pcb.BasePriority = PROCESS_PRIO_NORMAL;
    PsInitialSystemProcess->Pcb.QuantumReset = 6;
index c42ee05..6b385a4 100644 (file)
@@ -1194,6 +1194,8 @@ NtSetInformationThread (IN HANDLE ThreadHandle,
                     SetInformationData[ThreadInformationClass].Size);
     }
 
+  /* FIXME: This is REALLY wrong. Some types don't need THREAD_SET_INFORMATION */
+  /* FIXME: We should also check for certain things before doing the reference */
   Status = ObReferenceObjectByHandle (ThreadHandle,
                                      THREAD_SET_INFORMATION,
                                      PsThreadType,
@@ -1218,7 +1220,19 @@ NtSetInformationThread (IN HANDLE ThreadHandle,
             break;
 
            case ThreadAffinityMask:
-            Status = KeSetAffinityThread(&Thread->Tcb, u.Affinity);
+               
+               /* Check if this is valid */
+               DPRINT1("%lx, %lx\n", Thread->ThreadsProcess->Pcb.Affinity, u.Affinity);
+               if ((Thread->ThreadsProcess->Pcb.Affinity & u.Affinity) !=
+                   u.Affinity)
+               {
+                   DPRINT1("Wrong affinity given\n");
+                   Status = STATUS_INVALID_PARAMETER;
+               }
+               else
+               {
+                       Status = KeSetAffinityThread(&Thread->Tcb, u.Affinity);
+               }
             break;
 
            case ThreadImpersonationToken: