Implemented NtResumeThread() and NtSuspendThread()

Cleanup

svn path=/trunk/; revision=1473
This commit is contained in:
Eric Kohl 2000-12-22 13:37:41 +00:00
parent 64ba922c19
commit 91bcb7413f
2 changed files with 110 additions and 18 deletions

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.24 2000/10/22 16:36:53 ekohl Exp $ /* $Id: create.c,v 1.25 2000/12/22 13:37:41 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -444,7 +444,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
{ {
Teb.Peb = Thread->ThreadsProcess->Peb; /* No PEB yet!! */ Teb.Peb = Thread->ThreadsProcess->Peb; /* No PEB yet!! */
} }
// DPRINT1("Teb.Peb %x\n", Teb.Peb); DPRINT("Teb.Peb %x\n", Teb.Peb);
/* store stack information from InitialTeb */ /* store stack information from InitialTeb */
if (InitialTeb != NULL) if (InitialTeb != NULL)
@ -494,13 +494,13 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
*TebPtr = (PNT_TEB)TebBase; *TebPtr = (PNT_TEB)TebBase;
} }
// DPRINT1 ("TEB allocated at %p\n", TebBase); DPRINT("TEB allocated at %p\n", TebBase);
return Status; return Status;
} }
NTSTATUS STDCALL NtCreateThread (PHANDLE ThreadHandle, NTSTATUS STDCALL NtCreateThread (PHANDLE ThreadHandle,
ACCESS_MASK DesiredAccess, ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_ATTRIBUTES ObjectAttributes,
HANDLE ProcessHandle, HANDLE ProcessHandle,
@ -588,8 +588,8 @@ NTSTATUS STDCALL NtCreateThread (PHANDLE ThreadHandle,
if (!CreateSuspended) if (!CreateSuspended)
{ {
DPRINT("Not creating suspended\n"); DPRINT("Not creating suspended\n");
PsUnfreezeThread(Thread, NULL); PsResumeThread(Thread);
} }
DPRINT("Thread %x\n", Thread); DPRINT("Thread %x\n", Thread);
DPRINT("ObGetReferenceCount(Thread) %d ObGetHandleCount(Thread) %x\n", DPRINT("ObGetReferenceCount(Thread) %d ObGetHandleCount(Thread) %x\n",
@ -648,8 +648,9 @@ NTSTATUS STDCALL PsCreateSystemThread(PHANDLE ThreadHandle,
*ClientId=Thread->Cid; *ClientId=Thread->Cid;
} }
PsUnfreezeThread(Thread, NULL); PsResumeThread(Thread);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.60 2000/12/10 23:42:01 dwelch Exp $ /* $Id: thread.c,v 1.61 2000/12/22 13:37:41 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -306,6 +306,52 @@ ULONG PsFreezeThread(PETHREAD Thread,
return(r); return(r);
} }
ULONG PsResumeThread(PETHREAD Thread)
{
KIRQL oldIrql;
ULONG SuspendCount;
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
if (Thread->Tcb.SuspendCount > 0)
{
Thread->Tcb.SuspendCount--;
SuspendCount = Thread->Tcb.SuspendCount;
Thread->Tcb.State = THREAD_STATE_RUNNABLE;
PsInsertIntoThreadList(Thread->Tcb.Priority, Thread);
}
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
return SuspendCount;
}
ULONG PsSuspendThread(PETHREAD Thread)
{
KIRQL oldIrql;
ULONG PreviousSuspendCount;
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
PreviousSuspendCount = Thread->Tcb.SuspendCount;
if (Thread->Tcb.SuspendCount < MAXIMUM_SUSPEND_COUNT)
{
Thread->Tcb.SuspendCount++;
}
if (PsGetCurrentThread() == Thread)
{
DbgPrint("Cannot suspend self\n");
KeBugCheck(0);
}
Thread->Tcb.State = THREAD_STATE_SUSPENDED;
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
return PreviousSuspendCount;
}
VOID PsInitThreadManagment(VOID) VOID PsInitThreadManagment(VOID)
/* /*
* FUNCTION: Initialize thread managment * FUNCTION: Initialize thread managment
@ -430,7 +476,7 @@ NTSTATUS STDCALL NtAlertThread (IN HANDLE ThreadHandle)
(VOID)PsUnfreezeThread(Thread, &ThreadStatus); (VOID)PsUnfreezeThread(Thread, &ThreadStatus);
ObDereferenceObject(Thread); ObDereferenceObject(Thread);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL NtOpenThread(OUT PHANDLE ThreadHandle, NTSTATUS STDCALL NtOpenThread(OUT PHANDLE ThreadHandle,
@ -449,13 +495,36 @@ NTSTATUS STDCALL NtResumeThread (IN HANDLE ThreadHandle,
* ThreadHandle = Handle to the thread that should be resumed * ThreadHandle = Handle to the thread that should be resumed
* ResumeCount = The resulting resume count. * ResumeCount = The resulting resume count.
* REMARK: * REMARK:
* A thread is resumed if its suspend count is 0. This procedure maps to * A thread is resumed if its suspend count is 0. This procedure maps to
* the win32 ResumeThread function. ( documentation about the the suspend count can be found here aswell ) * the win32 ResumeThread function. ( documentation about the the suspend
* count can be found here aswell )
* RETURNS: Status * RETURNS: Status
*/ */
{ {
UNIMPLEMENTED; PETHREAD Thread;
return(STATUS_UNSUCCESSFUL); NTSTATUS Status;
ULONG Count;
Status = ObReferenceObjectByHandle(ThreadHandle,
THREAD_SUSPEND_RESUME,
PsThreadType,
UserMode,
(PVOID*)&Thread,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Count = PsResumeThread(Thread);
if (SuspendCount != NULL)
{
*SuspendCount = Count;
}
ObDereferenceObject((PVOID)Thread);
return STATUS_SUCCESS;
} }
@ -467,7 +536,7 @@ NTSTATUS STDCALL NtSuspendThread (IN HANDLE ThreadHandle,
* ThreadHandle = Handle to the thread that should be resumed * ThreadHandle = Handle to the thread that should be resumed
* PreviousSuspendCount = The resulting/previous suspend count. * PreviousSuspendCount = The resulting/previous suspend count.
* REMARK: * REMARK:
* A thread will be suspended if its suspend count is greater than 0. * A thread will be suspended if its suspend count is greater than 0.
* This procedure maps to the win32 SuspendThread function. ( * This procedure maps to the win32 SuspendThread function. (
* documentation about the the suspend count can be found here aswell ) * documentation about the the suspend count can be found here aswell )
* The suspend count is not increased if it is greater than * The suspend count is not increased if it is greater than
@ -475,8 +544,30 @@ NTSTATUS STDCALL NtSuspendThread (IN HANDLE ThreadHandle,
* RETURNS: Status * RETURNS: Status
*/ */
{ {
UNIMPLEMENTED; PETHREAD Thread;
return(STATUS_UNSUCCESSFUL); NTSTATUS Status;
ULONG Count;
Status = ObReferenceObjectByHandle(ThreadHandle,
THREAD_SUSPEND_RESUME,
PsThreadType,
UserMode,
(PVOID*)&Thread,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Count = PsSuspendThread(Thread);
if (PreviousSuspendCount != NULL)
{
*PreviousSuspendCount = Count;
}
ObDereferenceObject((PVOID)Thread);
return STATUS_SUCCESS;
} }
@ -490,14 +581,14 @@ NTSTATUS STDCALL NtContinue(IN PCONTEXT Context,
{ {
DbgPrint("NtContinue called but TrapFrame was NULL\n"); DbgPrint("NtContinue called but TrapFrame was NULL\n");
KeBugCheck(0); KeBugCheck(0);
} }
KeContextToTrapFrame(Context, TrapFrame); KeContextToTrapFrame(Context, TrapFrame);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL NtYieldExecution(VOID) NTSTATUS STDCALL NtYieldExecution(VOID)
{ {
PsDispatchThread(THREAD_STATE_RUNNABLE); PsDispatchThread(THREAD_STATE_RUNNABLE);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }