From 84f943edc624d125af383a594f8178f66a41aa25 Mon Sep 17 00:00:00 2001 From: Phillip Susi Date: Fri, 7 Jul 2000 00:44:07 +0000 Subject: [PATCH] Fixed ps bug, proper termination of threads svn path=/trunk/; revision=1237 --- reactos/ntoskrnl/ke/apc.c | 92 ++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index c337c3b835a..fa965c17f7d 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -23,7 +23,10 @@ /* GLOBALS *******************************************************************/ -static KSPIN_LOCK PiApcLock; +KSPIN_LOCK PiApcLock; +extern KSPIN_LOCK PiThreadListLock; + +VOID PsTerminateCurrentThread(NTSTATUS ExitStatus); /* FUNCTIONS *****************************************************************/ @@ -58,49 +61,58 @@ BOOLEAN KiTestAlert(PKTHREAD Thread, KIRQL oldlvl; CONTEXT SavedContext; ULONG Top; + BOOL ret = FALSE; DPRINT("KiTestAlert(Thread %x, UserContext %x)\n"); - KeAcquireSpinLock(&PiApcLock, &oldlvl); - current_entry = Thread->ApcState.ApcListHead[1].Flink; - - if (current_entry == &Thread->ApcState.ApcListHead[1]) + while(1) { - KeReleaseSpinLock(&PiApcLock, oldlvl); - return(FALSE); + KeAcquireSpinLock(&PiApcLock, &oldlvl); + current_entry = Thread->ApcState.ApcListHead[1].Flink; + + if (current_entry == &Thread->ApcState.ApcListHead[1]) + { + KeReleaseSpinLock(&PiApcLock, oldlvl); + break; + } + ret = TRUE; + current_entry = RemoveHeadList(&Thread->ApcState.ApcListHead[1]); + Apc = CONTAINING_RECORD(current_entry, KAPC, ApcListEntry); + + DPRINT("Esp %x\n", Esp); + DPRINT("Apc->NormalContext %x\n", Apc->NormalContext); + DPRINT("Apc->SystemArgument1 %x\n", Apc->SystemArgument1); + DPRINT("Apc->SystemArgument2 %x\n", Apc->SystemArgument2); + DPRINT("UserContext->Eip %x\n", UserContext->Eip); + + Esp = (PULONG)UserContext->Esp; + + memcpy(&SavedContext, UserContext, sizeof(CONTEXT)); + + Esp = Esp - (sizeof(CONTEXT) + (5 * sizeof(ULONG))); + memcpy(Esp, &SavedContext, sizeof(CONTEXT)); + Top = sizeof(CONTEXT) / 4; + Esp[Top] = (ULONG)Apc->NormalRoutine; + Esp[Top + 1] = (ULONG)Apc->NormalContext; + Esp[Top + 2] = (ULONG)Apc->SystemArgument1; + Esp[Top + 3] = (ULONG)Apc->SystemArgument2; + Esp[Top + 4] = (ULONG)Esp - sizeof(CONTEXT); + UserContext->Eip = 0; // KiUserApcDispatcher + + KeReleaseSpinLock(&PiApcLock, oldlvl); + + /* + * Now call for the kernel routine for the APC, which will free + * the APC data structure + */ + KeCallKernelRoutineApc(Apc); } - - current_entry = RemoveHeadList(&Thread->ApcState.ApcListHead[1]); - Apc = CONTAINING_RECORD(current_entry, KAPC, ApcListEntry); - - DPRINT("Esp %x\n", Esp); - DPRINT("Apc->NormalContext %x\n", Apc->NormalContext); - DPRINT("Apc->SystemArgument1 %x\n", Apc->SystemArgument1); - DPRINT("Apc->SystemArgument2 %x\n", Apc->SystemArgument2); - DPRINT("UserContext->Eip %x\n", UserContext->Eip); - - Esp = (PULONG)UserContext->Esp; - - memcpy(&SavedContext, UserContext, sizeof(CONTEXT)); - - Esp = Esp - (sizeof(CONTEXT) + (5 * sizeof(ULONG))); - memcpy(Esp, &SavedContext, sizeof(CONTEXT)); - Top = sizeof(CONTEXT) / 4; - Esp[Top] = (ULONG)Apc->NormalRoutine; - Esp[Top + 1] = (ULONG)Apc->NormalContext; - Esp[Top + 2] = (ULONG)Apc->SystemArgument1; - Esp[Top + 3] = (ULONG)Apc->SystemArgument2; - Esp[Top + 4] = (ULONG)Esp - sizeof(CONTEXT); - UserContext->Eip = 0; // KiUserApcDispatcher - - KeReleaseSpinLock(&PiApcLock, oldlvl); - - /* - * Now call for the kernel routine for the APC, which will free - * the APC data structure - */ - KeCallKernelRoutineApc(Apc); - - return(TRUE); + KeAcquireSpinLock( &PiThreadListLock, &oldlvl ); + if( (CONTAINING_RECORD( Thread, ETHREAD, Tcb ))->DeadThread ) + { + KeReleaseSpinLock( &PiThreadListLock, oldlvl ); + PsTerminateCurrentThread( (CONTAINING_RECORD( Thread, ETHREAD, Tcb ))->ExitStatus ); + } + return ret; } VOID KeCallApcsThread(VOID)