3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ps/suspend.c
6 * PURPOSE: Thread managment
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
11 /* INCLUDES ******************************************************************/
15 #include <internal/debug.h>
19 KeResumeThread(PKTHREAD Thread
);
21 /* FUNCTIONS *****************************************************************/
24 * FUNCTION: Decrements a thread's resume count
26 * ThreadHandle = Handle to the thread that should be resumed
27 * ResumeCount = The resulting resume count.
32 NtResumeThread(IN HANDLE ThreadHandle
,
33 IN PULONG SuspendCount OPTIONAL
)
37 KPROCESSOR_MODE PreviousMode
;
38 NTSTATUS Status
= STATUS_SUCCESS
;
42 PreviousMode
= ExGetPreviousMode();
44 DPRINT("NtResumeThead(ThreadHandle %lx SuspendCount %p)\n",
45 ThreadHandle
, SuspendCount
);
47 /* Check buffer validity */
48 if(SuspendCount
&& PreviousMode
== UserMode
) {
52 ProbeForWrite(SuspendCount
,
57 Status
= _SEH_GetExceptionCode();
61 if(!NT_SUCCESS(Status
)) return Status
;
64 /* Get the Thread Object */
65 Status
= ObReferenceObjectByHandle(ThreadHandle
,
66 THREAD_SUSPEND_RESUME
,
71 if (!NT_SUCCESS(Status
)) {
76 /* Call the Kernel Function */
77 Prev
= KeResumeThread(&Thread
->Tcb
);
88 Status
= _SEH_GetExceptionCode();
93 /* Dereference and Return */
94 ObDereferenceObject ((PVOID
)Thread
);
99 * FUNCTION: Increments a thread's suspend count
101 * ThreadHandle = Handle to the thread that should be resumed
102 * PreviousSuspendCount = The resulting/previous suspend count.
104 * A thread will be suspended if its suspend count is greater than 0.
105 * This procedure maps to the win32 SuspendThread function. (
106 * documentation about the the suspend count can be found here aswell )
107 * The suspend count is not increased if it is greater than
108 * MAXIMUM_SUSPEND_COUNT.
113 NtSuspendThread(IN HANDLE ThreadHandle
,
114 IN PULONG PreviousSuspendCount OPTIONAL
)
118 KPROCESSOR_MODE PreviousMode
;
119 NTSTATUS Status
= STATUS_SUCCESS
;
123 PreviousMode
= ExGetPreviousMode();
125 /* Check buffer validity */
126 if(PreviousSuspendCount
&& PreviousMode
== UserMode
) {
130 ProbeForWrite(PreviousSuspendCount
,
135 Status
= _SEH_GetExceptionCode();
139 if(!NT_SUCCESS(Status
)) return Status
;
142 /* Get the Thread Object */
143 Status
= ObReferenceObjectByHandle(ThreadHandle
,
144 THREAD_SUSPEND_RESUME
,
149 if (!NT_SUCCESS(Status
)) {
154 /* Call the Kernel Function */
155 Prev
= KeSuspendThread(&Thread
->Tcb
);
158 if(PreviousSuspendCount
) {
162 *PreviousSuspendCount
= Prev
;
166 Status
= _SEH_GetExceptionCode();
171 /* Dereference and Return */
172 ObDereferenceObject((PVOID
)Thread
);