From 61ffdb35166293f48dff1a7eb27b0f2d5134b90b Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Tue, 9 Aug 2005 08:50:57 +0000 Subject: [PATCH] - Last patch was incomplete, apologies. SVN @ 5AM = bad idea. - 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 | 6 ++++++ reactos/ntoskrnl/ke/kthread.c | 7 ++++++- reactos/ntoskrnl/ke/main.c | 2 +- reactos/ntoskrnl/ps/psmgr.c | 2 +- reactos/ntoskrnl/ps/query.c | 16 +++++++++++++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index ebef9d0a241..507d5b2a864 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -226,6 +226,12 @@ LONG STDCALL KeQueryBasePriorityThread(IN PKTHREAD Thread); +VOID +STDCALL +KiSetPriorityThread(PKTHREAD Thread, + KPRIORITY Priority, + PBOOLEAN Released); + VOID STDCALL KeStackAttachProcess ( diff --git a/reactos/ntoskrnl/ke/kthread.c b/reactos/ntoskrnl/ke/kthread.c index ce2c14d1ee2..4b41b63b7c4 100644 --- a/reactos/ntoskrnl/ke/kthread.c +++ b/reactos/ntoskrnl/ke/kthread.c @@ -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(); diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index 70e19f7c8c2..0e3d7f8b8cb 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -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; diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index a384db69d49..23615badafb 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -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; diff --git a/reactos/ntoskrnl/ps/query.c b/reactos/ntoskrnl/ps/query.c index c42ee050a70..6b385a4cd87 100644 --- a/reactos/ntoskrnl/ps/query.c +++ b/reactos/ntoskrnl/ps/query.c @@ -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: