diff --git a/reactos/ChangeLog b/reactos/ChangeLog index 6df0549975f..c1a2a999b96 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,3 +1,24 @@ +2002-08-16 David Welch + + * ntoskrnl/mm/npool.c (ExAllocateWholePageBlock): Converted + to use PHYSICAL_ADDRESS type for page address. + +2002-08-16 David Welch + + * subsys/win32k/ntuser/class.c (W32kCreateClass): Corrected + typo when calculating the offset into the class object to + put the class name string. + +2002-08-16 David Welch + + * ntoskrnl/ps/thread.c (PsDispatchThreadNoLock): Don't call + the reaper function directly; set an event to wake up a seperate + reaper thread. + * ntoskrnl/ps/thread.c (PsReaperThreadMain): New function that + waits for a notification and then calls PsReapThreads. + * ntoskrnl/ps/thread.c (PsInitThreadManagement): Create the + reaper thread. + 2002-08-15 David Welch * lib/advapi32/misc/dllmain.c (DllMain): Removed debug message. diff --git a/reactos/ntoskrnl/include/internal/ps.h b/reactos/ntoskrnl/include/internal/ps.h index 225b772909f..38183833c99 100644 --- a/reactos/ntoskrnl/include/internal/ps.h +++ b/reactos/ntoskrnl/include/internal/ps.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: ps.h,v 1.39 2002/08/14 20:58:34 dwelch Exp $ +/* $Id: ps.h,v 1.40 2002/08/16 01:39:16 dwelch Exp $ * * FILE: ntoskrnl/ke/kthread.c * PURPOSE: Process manager definitions @@ -502,6 +502,8 @@ PsDispatchThread(ULONG NewThreadStatus); VOID PsInitialiseSuspendImplementation(VOID); +extern ULONG PiNrThreadsAwaitingReaping; + #endif /* ASSEMBLER */ #endif /* __INCLUDE_INTERNAL_PS_H */ diff --git a/reactos/ntoskrnl/mm/npool.c b/reactos/ntoskrnl/mm/npool.c index 87862dbe742..fad42d8cea9 100644 --- a/reactos/ntoskrnl/mm/npool.c +++ b/reactos/ntoskrnl/mm/npool.c @@ -1,4 +1,4 @@ -/* $Id: npool.c,v 1.58 2002/06/04 15:26:57 dwelch Exp $ +/* $Id: npool.c,v 1.59 2002/08/16 01:39:16 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1007,7 +1007,7 @@ PVOID STDCALL ExAllocateWholePageBlock(ULONG UserSize) { PVOID Address; - PVOID Page; + PHYSICAL_ADDRESS Page; ULONG i; ULONG Size; ULONG NrPages; @@ -1020,14 +1020,14 @@ ExAllocateWholePageBlock(ULONG UserSize) for (i = 0; i < NrPages; i++) { Page = MmAllocPage(MC_NPPOOL, 0); - if (Page == NULL) + if (Page.QuadPart == 0LL) { KeBugCheck(0); } MmCreateVirtualMapping(NULL, Address + (i * PAGESIZE), PAGE_READWRITE | PAGE_SYSTEM, - (ULONG)Page, + Page, TRUE); } diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index 190a6d8a8a7..ec356967481 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -1,4 +1,4 @@ -/* $Id: kill.c,v 1.54 2002/06/10 21:37:45 hbirr Exp $ +/* $Id: kill.c,v 1.55 2002/08/16 01:39:16 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -81,8 +81,6 @@ PsReapThreads(VOID) PETHREAD current; KIRQL oldIrql; -// DPRINT1("PsReapThreads()\n"); - KeAcquireSpinLock(&PiThreadListLock, &oldIrql); current_entry = PiThreadListHead.Flink; @@ -99,19 +97,15 @@ PsReapThreads(VOID) PEPROCESS Process = current->ThreadsProcess; NTSTATUS Status = current->ExitStatus; - DPRINT("PsProcessType %x\n", PsProcessType); - DPRINT("Reaping thread %x\n", current); - DPRINT("Pointer count %d\n", ObGetObjectPointerCount(Process)); + PiNrThreadsAwaitingReaping--; current->Tcb.State = THREAD_STATE_TERMINATED_2; RemoveEntryList(¤t->Tcb.ProcessThreadListEntry); if (IsListEmpty(&Process->ThreadListHead)) { - DPRINT("Last thread terminated, terminating process\n"); KeReleaseSpinLock( &PiThreadListLock, oldIrql ); PiTerminateProcess(Process, Status); KeAcquireSpinLock( &PiThreadListLock, &oldIrql ); } - DPRINT("Pointer count %d\n", ObGetObjectPointerCount(Process)); KeReleaseSpinLock(&PiThreadListLock, oldIrql); ObDereferenceObject(current); KeAcquireSpinLock(&PiThreadListLock, &oldIrql); @@ -161,7 +155,7 @@ PsTerminateCurrentThread(NTSTATUS ExitStatus) KeDispatcherObjectWake(&CurrentThread->Tcb.DispatcherHeader); KeReleaseDispatcherDatabaseLock(FALSE); - KeAcquireSpinLock(&PiThreadListLock, &oldIrql); + KeAcquireSpinLock(&PiThreadListLock, &oldIrql); PsDispatchThreadNoLock(THREAD_STATE_TERMINATED_1); KeBugCheck(0); } diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 32769ee97c1..5a4f1234adf 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -1,4 +1,4 @@ -/* $Id: thread.c,v 1.101 2002/08/14 20:58:38 dwelch Exp $ +/* $Id: thread.c,v 1.102 2002/08/16 01:39:16 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -49,6 +49,10 @@ static BOOLEAN DoneInitYet = FALSE; static PETHREAD IdleThreads[MAXIMUM_PROCESSORS]; ULONG PiNrThreads = 0; ULONG PiNrReadyThreads = 0; +static HANDLE PiReaperThreadHandle; +static KEVENT PiReaperThreadEvent; +static BOOL PiReaperThreadShouldTerminate = FALSE; +ULONG PiNrThreadsAwaitingReaping = 0; static GENERIC_MAPPING PiThreadMapping = {THREAD_READ, THREAD_WRITE, @@ -164,6 +168,30 @@ static PETHREAD PsScanThreadList (KPRIORITY Priority, ULONG Affinity) return(NULL); } +VOID STDCALL +PiWakeupReaperThread(VOID) +{ + KeSetEvent(&PiReaperThreadEvent, 0, FALSE); +} + +NTSTATUS STDCALL +PiReaperThreadMain(PVOID Ignored) +{ + while (1) + { + KeWaitForSingleObject(&PiReaperThreadEvent, + Executive, + KernelMode, + FALSE, + NULL); + if (PiReaperThreadShouldTerminate) + { + PsTerminateSystemThread(0); + } + PsReapThreads(); + } +} + VOID PsDispatchThreadNoLock (ULONG NewThreadStatus) { KPRIORITY CurrentPriority; @@ -182,6 +210,10 @@ VOID PsDispatchThreadNoLock (ULONG NewThreadStatus) PsInsertIntoThreadList(CurrentThread->Tcb.Priority, CurrentThread); } + if (CurrentThread->Tcb.State == THREAD_STATE_TERMINATED_1) + { + PiNrThreadsAwaitingReaping++; + } Affinity = 1 << KeGetCurrentProcessorNumber(); for (CurrentPriority = HIGH_PRIORITY; @@ -206,8 +238,11 @@ VOID PsDispatchThreadNoLock (ULONG NewThreadStatus) CurrentThread = Candidate; KeReleaseSpinLockFromDpcLevel(&PiThreadListLock); + if (PiNrThreadsAwaitingReaping > 0) + { + PiWakeupReaperThread(); + } KiArchContextSwitch(&CurrentThread->Tcb, &OldThread->Tcb); - PsReapThreads(); return; } } @@ -229,7 +264,7 @@ PsDispatchThread(ULONG NewThreadStatus) /* * Save wait IRQL */ - KeGetCurrentKPCR()->CurrentThread->WaitIrql = oldIrql; + KeGetCurrentKPCR()->CurrentThread->WaitIrql = oldIrql; PsDispatchThreadNoLock(NewThreadStatus); KeLowerIrql(oldIrql); } @@ -367,6 +402,7 @@ PsInitThreadManagment(VOID) PETHREAD FirstThread; ULONG i; HANDLE FirstThreadHandle; + NTSTATUS Status; KeInitializeSpinLock(&PiThreadListLock); for (i=0; i < MAXIMUM_PRIORITY; i++) @@ -409,6 +445,23 @@ PsInitThreadManagment(VOID) DPRINT("FirstThread %x\n",FirstThread); DoneInitYet = TRUE; + + /* + * Create the reaper thread + */ + KeInitializeEvent(&PiReaperThreadEvent, SynchronizationEvent, FALSE); + Status = PsCreateSystemThread(&PiReaperThreadHandle, + THREAD_ALL_ACCESS, + NULL, + NULL, + NULL, + PiReaperThreadMain, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("PS: Failed to create reaper thread.\n"); + KeBugCheck(0); + } } LONG STDCALL diff --git a/reactos/subsys/win32k/ntuser/class.c b/reactos/subsys/win32k/ntuser/class.c index e504eabf40c..c5e03443330 100644 --- a/reactos/subsys/win32k/ntuser/class.c +++ b/reactos/subsys/win32k/ntuser/class.c @@ -1,4 +1,4 @@ -/* $Id: class.c,v 1.9 2002/07/17 21:04:57 dwelch Exp $ +/* $Id: class.c,v 1.10 2002/08/16 01:39:17 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -188,7 +188,7 @@ W32kCreateClass(LPWNDCLASSEX lpwcx, { ClassObject->Class.lpszMenuName = namePtr; wcscpy (namePtr, lpwcx->lpszMenuName); - namePtr += wcslen (lpwcx->lpszMenuName + 1); + namePtr += wcslen (lpwcx->lpszMenuName) + 1; } ClassObject->Class.lpszClassName = namePtr; wcscpy (namePtr, lpwcx->lpszClassName); diff --git a/reactos/subsys/win32k/ntuser/winsta.c b/reactos/subsys/win32k/ntuser/winsta.c index 7df51591edc..da02635d161 100644 --- a/reactos/subsys/win32k/ntuser/winsta.c +++ b/reactos/subsys/win32k/ntuser/winsta.c @@ -1,4 +1,4 @@ -/* $Id: winsta.c,v 1.5 2002/07/17 21:04:57 dwelch Exp $ +/* $Id: winsta.c,v 1.6 2002/08/16 01:39:17 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -26,7 +26,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include /* GLOBALS *******************************************************************/