diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index 98f2f6a6d58..f9cd90efe25 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -326,6 +326,14 @@ KeInsertQueueApc (PKAPC Apc, } TargetThread = Apc->Thread; + + if (TargetThread->State == THREAD_STATE_TERMINATED_1 || + TargetThread->State == THREAD_STATE_TERMINATED_2) + { + KeReleaseSpinLock(&PiApcLock, oldlvl); + return(FALSE); + } + if (Apc->ApcMode == KernelMode) { InsertTailList(&TargetThread->ApcState.ApcListHead[0], diff --git a/reactos/ntoskrnl/ps/debug.c b/reactos/ntoskrnl/ps/debug.c index 2387ec77f6c..29b09071511 100644 --- a/reactos/ntoskrnl/ps/debug.c +++ b/reactos/ntoskrnl/ps/debug.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: debug.c,v 1.10 2003/06/16 19:19:30 hbirr Exp $ +/* $Id: debug.c,v 1.11 2003/07/21 21:36:01 dwelch Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/ps/debug.c @@ -245,21 +245,26 @@ NtGetContextThread(IN HANDLE ThreadHandle, NULL, KernelMode, (PVOID)&Context); - KeInsertQueueApc(&Apc, - (PVOID)&Event, - (PVOID)&AStatus, - IO_NO_INCREMENT); - Status = KeWaitForSingleObject(&Event, - 0, - UserMode, - FALSE, - NULL); - if (NT_SUCCESS(Status) && ! NT_SUCCESS(AStatus)) + if (!KeInsertQueueApc(&Apc, + (PVOID)&Event, + (PVOID)&AStatus, + IO_NO_INCREMENT)) { - Status = AStatus; + Status = STATUS_THREAD_IS_TERMINATING; + } + else + { + Status = KeWaitForSingleObject(&Event, + 0, + UserMode, + FALSE, + NULL); + if (NT_SUCCESS(Status) && !NT_SUCCESS(AStatus)) + { + Status = AStatus; + } } } - if (NT_SUCCESS(Status)) { Status = MmCopyToCaller(UnsafeContext, &Context, sizeof(Context)); @@ -346,18 +351,24 @@ NtSetContextThread(IN HANDLE ThreadHandle, NULL, KernelMode, (PVOID)&Context); - KeInsertQueueApc(&Apc, - (PVOID)&Event, - (PVOID)&AStatus, - IO_NO_INCREMENT); - Status = KeWaitForSingleObject(&Event, - 0, - UserMode, - FALSE, - NULL); - if (NT_SUCCESS(Status) && ! NT_SUCCESS(AStatus)) + if (!KeInsertQueueApc(&Apc, + (PVOID)&Event, + (PVOID)&AStatus, + IO_NO_INCREMENT)) { - Status = AStatus; + Status = STATUS_THREAD_IS_TERMINATING; + } + else + { + Status = KeWaitForSingleObject(&Event, + 0, + UserMode, + FALSE, + NULL); + if (NT_SUCCESS(Status) && !NT_SUCCESS(AStatus)) + { + Status = AStatus; + } } } diff --git a/reactos/ntoskrnl/ps/suspend.c b/reactos/ntoskrnl/ps/suspend.c index 878a15d4ae1..cc00e3c2f2e 100644 --- a/reactos/ntoskrnl/ps/suspend.c +++ b/reactos/ntoskrnl/ps/suspend.c @@ -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: suspend.c,v 1.11 2003/06/05 23:36:35 gdalsnes Exp $ +/* $Id: suspend.c,v 1.12 2003/07/21 21:36:01 dwelch Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/ps/suspend.c @@ -110,10 +110,15 @@ PsSuspendThread(PETHREAD Thread, PULONG PreviousSuspendCount) Thread->Tcb.SuspendCount++; if (!Thread->Tcb.SuspendApc.Inserted) { - KeInsertQueueApc(&Thread->Tcb.SuspendApc, - NULL, - NULL, - IO_NO_INCREMENT); + if (!KeInsertQueueApc(&Thread->Tcb.SuspendApc, + NULL, + NULL, + IO_NO_INCREMENT)) + { + Thread->Tcb.SuspendCount--; + ExReleaseFastMutex(&SuspendMutex); + return(STATUS_THREAD_IS_TERMINATING); + } } ExReleaseFastMutex(&SuspendMutex); if (PreviousSuspendCount != NULL)