From bc125c33147eab194cb138abfa47ace3aca4f505 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Fri, 12 Sep 2008 11:13:15 +0000 Subject: [PATCH] - MmDeleteKernelStack should take StackBase as the first parameter, not StackLimit (thus actually the need for the 2nd parameter - large stack size flag). Fix it, and fix callers. - Make KiSwitchKernelStack return the stack base instead of the stack limit, as part of the above change. - Don't increment priority when waking the thread in KeThawAllThreads. - Fix new thread priority calculation in KiDeferredReadyThread. - Fix double-semicolon typo in thrdini.c svn path=/trunk/; revision=36157 --- reactos/ntoskrnl/ke/i386/thrdini.c | 2 +- reactos/ntoskrnl/ke/i386/usercall_asm.S | 4 ++-- reactos/ntoskrnl/ke/thrdobj.c | 11 +++++++---- reactos/ntoskrnl/ke/thrdschd.c | 2 +- reactos/ntoskrnl/mm/procsup.c | 6 ++++-- reactos/ntoskrnl/ps/kill.c | 4 ++-- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/reactos/ntoskrnl/ke/i386/thrdini.c b/reactos/ntoskrnl/ke/i386/thrdini.c index 9428d6a0a8a..6c147ad8d6c 100644 --- a/reactos/ntoskrnl/ke/i386/thrdini.c +++ b/reactos/ntoskrnl/ke/i386/thrdini.c @@ -217,7 +217,7 @@ Ke386InitThreadWithContext(IN PKTHREAD Thread, /* And set up the Context Switch Frame */ CtxSwitchFrame->RetAddr = KiThreadStartup; CtxSwitchFrame->ApcBypassDisable = TRUE; - CtxSwitchFrame->ExceptionList = EXCEPTION_CHAIN_END;; + CtxSwitchFrame->ExceptionList = EXCEPTION_CHAIN_END; /* Save back the new value of the kernel stack. */ Thread->KernelStack = (PVOID)CtxSwitchFrame; diff --git a/reactos/ntoskrnl/ke/i386/usercall_asm.S b/reactos/ntoskrnl/ke/i386/usercall_asm.S index 61a4717bf15..4d177eb9223 100644 --- a/reactos/ntoskrnl/ke/i386/usercall_asm.S +++ b/reactos/ntoskrnl/ke/i386/usercall_asm.S @@ -420,7 +420,7 @@ NoStack: * @param StackLimit * Pointer to the new Stack Limit of the thread. * - * @return The previous Stack Limit of the thread. + * @return The previous Stack Base of the thread. * * @remark This routine should typically only be used when converting from a * non-GUI to a GUI Thread. The caller is responsible for freeing the @@ -470,7 +470,7 @@ _KeSwitchKernelStack@8: pop edi /* Save old stack base and get new limit/base */ - mov eax, [edx+KTHREAD_STACK_LIMIT] + mov eax, [edx+KTHREAD_STACK_BASE] mov ecx, [esp+12] mov esi, [esp+16] diff --git a/reactos/ntoskrnl/ke/thrdobj.c b/reactos/ntoskrnl/ke/thrdobj.c index e8b6dfaec97..86eaa580107 100644 --- a/reactos/ntoskrnl/ke/thrdobj.c +++ b/reactos/ntoskrnl/ke/thrdobj.c @@ -99,7 +99,7 @@ KeSetDisableBoostThread(IN OUT PKTHREAD Thread, ASSERT_THREAD(Thread); /* Check if we're enabling or disabling */ - if (Disable != FALSE) + if (Disable) { /* Set the bit */ return InterlockedBitTestAndSet(&Thread->ThreadFlags, 1); @@ -652,7 +652,7 @@ KeThawAllThreads(VOID) /* Signal the suspend semaphore and wake it */ Current->SuspendSemaphore.Header.SignalState++; - KiWaitTest(&Current->SuspendSemaphore, 1); + KiWaitTest(&Current->SuspendSemaphore, 0); /* Unlock the dispatcher */ KiReleaseDispatcherLockFromDpcLevel(); @@ -833,7 +833,7 @@ KeInitThread(IN OUT PKTHREAD Thread, if (AllocatedStack) { /* Delete the stack */ - MmDeleteKernelStack((PVOID)Thread->StackLimit, FALSE); + MmDeleteKernelStack((PVOID)Thread->StackBase, FALSE); Thread->InitialStack = NULL; } } @@ -875,7 +875,7 @@ NTAPI KeUninitThread(IN PKTHREAD Thread) { /* Delete the stack */ - MmDeleteKernelStack((PVOID)Thread->StackLimit, FALSE); + MmDeleteKernelStack((PVOID)Thread->StackBase, FALSE); Thread->InitialStack = NULL; } @@ -1157,6 +1157,9 @@ KeSetBasePriorityThread(IN PKTHREAD Thread, if (Thread->Saturation) OldIncrement = (HIGH_PRIORITY + 1) / 2 * Thread->Saturation; + /* Reset the saturation value */ + Thread->Saturation = 0; + /* Now check if saturation is being used for the new value */ if (abs(Increment) >= ((HIGH_PRIORITY + 1) / 2)) { diff --git a/reactos/ntoskrnl/ke/thrdschd.c b/reactos/ntoskrnl/ke/thrdschd.c index ff64d40cf5b..33d2bb2d578 100644 --- a/reactos/ntoskrnl/ke/thrdschd.c +++ b/reactos/ntoskrnl/ke/thrdschd.c @@ -55,7 +55,7 @@ KiDeferredReadyThread(IN PKTHREAD Thread) { /* Calculate the new priority based on the adjust increment */ OldPriority = min(Thread->AdjustIncrement + 1, - LOW_REALTIME_PRIORITY - 1); + LOW_REALTIME_PRIORITY - 3); /* Make sure we're not decreasing outside of the priority range */ ASSERT((Thread->PriorityDecrement >= 0) && diff --git a/reactos/ntoskrnl/mm/procsup.c b/reactos/ntoskrnl/mm/procsup.c index 38582e4d360..37b3dce8a12 100644 --- a/reactos/ntoskrnl/mm/procsup.c +++ b/reactos/ntoskrnl/mm/procsup.c @@ -140,15 +140,17 @@ MiFreeStackPage(PVOID Context, VOID STDCALL -MmDeleteKernelStack(PVOID Stack, +MmDeleteKernelStack(PVOID StackBase, BOOLEAN GuiStack) { + ULONG StackSize = GuiStack ? KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE; + /* Lock the Address Space */ MmLockAddressSpace(MmGetKernelAddressSpace()); /* Delete the Stack */ MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(), - Stack, + (PVOID)((ULONG_PTR)StackBase - StackSize), MiFreeStackPage, NULL); diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index 8dab39600ec..991ebe18cd2 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -188,7 +188,7 @@ PspReapRoutine(IN PVOID Context) Thread = CONTAINING_RECORD(NextEntry, ETHREAD, ReaperLink); /* Delete this entry's kernel stack */ - MmDeleteKernelStack((PVOID)Thread->Tcb.StackLimit, + MmDeleteKernelStack((PVOID)Thread->Tcb.StackBase, Thread->Tcb.LargeStack); Thread->Tcb.InitialStack = NULL; @@ -349,7 +349,7 @@ PspDeleteThread(IN PVOID ObjectBody) if (Thread->Tcb.InitialStack) { /* Release it */ - MmDeleteKernelStack((PVOID)Thread->Tcb.StackLimit, + MmDeleteKernelStack((PVOID)Thread->Tcb.StackBase, Thread->Tcb.LargeStack); }