mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
Free the user stack in PsReapThreads.
svn path=/trunk/; revision=3801
This commit is contained in:
parent
56964fad03
commit
d4386d7b53
1 changed files with 38 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: kill.c,v 1.57 2002/09/08 10:23:40 chorns Exp $
|
/* $Id: kill.c,v 1.58 2002/11/27 20:54:37 hbirr Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -96,17 +96,48 @@ PsReapThreads(VOID)
|
||||||
{
|
{
|
||||||
PEPROCESS Process = current->ThreadsProcess;
|
PEPROCESS Process = current->ThreadsProcess;
|
||||||
NTSTATUS Status = current->ExitStatus;
|
NTSTATUS Status = current->ExitStatus;
|
||||||
|
BOOLEAN Last;
|
||||||
|
|
||||||
PiNrThreadsAwaitingReaping--;
|
PiNrThreadsAwaitingReaping--;
|
||||||
current->Tcb.State = THREAD_STATE_TERMINATED_2;
|
current->Tcb.State = THREAD_STATE_TERMINATED_2;
|
||||||
RemoveEntryList(¤t->Tcb.ProcessThreadListEntry);
|
RemoveEntryList(¤t->Tcb.ProcessThreadListEntry);
|
||||||
if (IsListEmpty(&Process->ThreadListHead))
|
Last = IsListEmpty(&Process->ThreadListHead);
|
||||||
{
|
|
||||||
KeReleaseSpinLock( &PiThreadListLock, oldIrql );
|
|
||||||
PiTerminateProcess(Process, Status);
|
|
||||||
KeAcquireSpinLock( &PiThreadListLock, &oldIrql );
|
|
||||||
}
|
|
||||||
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
|
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
|
||||||
|
|
||||||
|
if (Last)
|
||||||
|
{
|
||||||
|
PiTerminateProcess(Process, Status);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (current->Tcb.Teb)
|
||||||
|
{
|
||||||
|
/* If this is not the last thread for the process than free the memory
|
||||||
|
from user stack and teb. */
|
||||||
|
NTSTATUS Status;
|
||||||
|
ULONG Length;
|
||||||
|
ULONG Offset;
|
||||||
|
PVOID DeallocationStack;
|
||||||
|
HANDLE ProcessHandle;
|
||||||
|
Status = ObCreateHandle(PsGetCurrentProcess(), Process, PROCESS_ALL_ACCESS, FALSE, &ProcessHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("ObCreateHandle failed, status = %x\n", Status);
|
||||||
|
KeBugCheck(0);
|
||||||
|
}
|
||||||
|
Offset = FIELD_OFFSET(TEB, DeallocationStack);
|
||||||
|
Length = 0;
|
||||||
|
NtReadVirtualMemory(ProcessHandle, (PVOID)current->Tcb.Teb + Offset,
|
||||||
|
(PVOID)&DeallocationStack, sizeof(PVOID), &Length);
|
||||||
|
if (DeallocationStack && Length == sizeof(PVOID))
|
||||||
|
{
|
||||||
|
NtFreeVirtualMemory(ProcessHandle, &DeallocationStack, &Length, MEM_RELEASE);
|
||||||
|
}
|
||||||
|
Length = PAGE_SIZE;
|
||||||
|
NtFreeVirtualMemory(ProcessHandle, (PVOID*)¤t->Tcb.Teb, &Length, MEM_RELEASE);
|
||||||
|
NtClose(ProcessHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
ObDereferenceObject(current);
|
ObDereferenceObject(current);
|
||||||
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
|
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
|
||||||
current_entry = PiThreadListHead.Flink;
|
current_entry = PiThreadListHead.Flink;
|
||||||
|
|
Loading…
Reference in a new issue