Thread/Process Termination/Repeaing Rewrite + Fixes
[reactos.git] / reactos / ntoskrnl / ps / suspend.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ps/suspend.c
6 * PURPOSE: Thread managment
7 *
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 ULONG
18 STDCALL
19 KeResumeThread(PKTHREAD Thread);
20
21 ULONG
22 STDCALL
23 KeSuspendThread(PKTHREAD Thread);
24 /* FUNCTIONS *****************************************************************/
25
26 /*
27 * FUNCTION: Decrements a thread's resume count
28 * ARGUMENTS:
29 * ThreadHandle = Handle to the thread that should be resumed
30 * ResumeCount = The resulting resume count.
31 * RETURNS: Status
32 */
33 NTSTATUS
34 STDCALL
35 NtResumeThread(IN HANDLE ThreadHandle,
36 IN PULONG SuspendCount OPTIONAL)
37 {
38 PETHREAD Thread;
39 NTSTATUS Status;
40
41 PAGED_CODE();
42
43 DPRINT1("NtResumeThead(ThreadHandle %lx SuspendCount %p)\n",
44 ThreadHandle, SuspendCount);
45
46 /* Get the Thread Object */
47 Status = ObReferenceObjectByHandle(ThreadHandle,
48 THREAD_SUSPEND_RESUME,
49 PsThreadType,
50 KeGetPreviousMode(),
51 (PVOID*)&Thread,
52 NULL);
53 if (!NT_SUCCESS(Status)) {
54
55 return Status;
56 }
57
58 /* Call the Kernel Function */
59 *SuspendCount = KeResumeThread(&Thread->Tcb);
60
61 /* Dereference and Return */
62 ObDereferenceObject ((PVOID)Thread);
63 return STATUS_SUCCESS;
64 }
65
66 /*
67 * FUNCTION: Increments a thread's suspend count
68 * ARGUMENTS:
69 * ThreadHandle = Handle to the thread that should be resumed
70 * PreviousSuspendCount = The resulting/previous suspend count.
71 * REMARK:
72 * A thread will be suspended if its suspend count is greater than 0.
73 * This procedure maps to the win32 SuspendThread function. (
74 * documentation about the the suspend count can be found here aswell )
75 * The suspend count is not increased if it is greater than
76 * MAXIMUM_SUSPEND_COUNT.
77 * RETURNS: Status
78 */
79 NTSTATUS
80 STDCALL
81 NtSuspendThread(IN HANDLE ThreadHandle,
82 IN PULONG PreviousSuspendCount OPTIONAL)
83 {
84 PETHREAD Thread;
85 NTSTATUS Status;
86
87 PAGED_CODE();
88
89 /* Get the Thread Object */
90 Status = ObReferenceObjectByHandle(ThreadHandle,
91 THREAD_SUSPEND_RESUME,
92 PsThreadType,
93 KeGetPreviousMode(),
94 (PVOID*)&Thread,
95 NULL);
96 if (!NT_SUCCESS(Status)) {
97
98 return Status;
99 }
100
101 /* Call the Kernel Function */
102 *PreviousSuspendCount = KeSuspendThread(&Thread->Tcb);
103
104 /* Dereference and Return */
105 ObDereferenceObject((PVOID)Thread);
106 return STATUS_SUCCESS;
107 }
108
109 /* EOF */