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
!= KernelMode
) {
52 ProbeForWriteUlong(SuspendCount
);
55 Status
= _SEH_GetExceptionCode();
59 if(!NT_SUCCESS(Status
)) return Status
;
62 /* Get the Thread Object */
63 Status
= ObReferenceObjectByHandle(ThreadHandle
,
64 THREAD_SUSPEND_RESUME
,
69 if (!NT_SUCCESS(Status
)) {
74 /* Call the Kernel Function */
75 Prev
= KeResumeThread(&Thread
->Tcb
);
86 Status
= _SEH_GetExceptionCode();
91 /* Dereference and Return */
92 ObDereferenceObject ((PVOID
)Thread
);
97 * FUNCTION: Increments a thread's suspend count
99 * ThreadHandle = Handle to the thread that should be resumed
100 * PreviousSuspendCount = The resulting/previous suspend count.
102 * A thread will be suspended if its suspend count is greater than 0.
103 * This procedure maps to the win32 SuspendThread function. (
104 * documentation about the the suspend count can be found here aswell )
105 * The suspend count is not increased if it is greater than
106 * MAXIMUM_SUSPEND_COUNT.
111 NtSuspendThread(IN HANDLE ThreadHandle
,
112 IN PULONG PreviousSuspendCount OPTIONAL
)
116 KPROCESSOR_MODE PreviousMode
= ExGetPreviousMode();
117 NTSTATUS Status
= STATUS_SUCCESS
;
120 /* Check buffer validity */
121 if(PreviousSuspendCount
&& PreviousMode
!= KernelMode
)
125 ProbeForWriteUlong(PreviousSuspendCount
);
129 Status
= _SEH_GetExceptionCode();
132 if(!NT_SUCCESS(Status
)) return Status
;
135 /* Get the Thread Object */
136 Status
= ObReferenceObjectByHandle(ThreadHandle
,
137 THREAD_SUSPEND_RESUME
,
142 if (!NT_SUCCESS(Status
)) return Status
;
144 /* Guard with SEH because KeSuspendThread can raise an exception */
147 /* Make sure the thread isn't terminating */
148 if ((Thread
!= PsGetCurrentThread()) && (Thread
->Terminated
))
150 ObDereferenceObject(Thread
);
151 return STATUS_THREAD_IS_TERMINATING
;
154 /* Call the Kernel function */
155 Prev
= KeSuspendThread(&Thread
->Tcb
);
157 /* Return the Previous Count */
158 if (PreviousSuspendCount
) *PreviousSuspendCount
= Prev
;
162 Status
= _SEH_GetExceptionCode();
164 /* Don't fail if we merely couldn't write the handle back */
165 if (Status
!= STATUS_SUSPEND_COUNT_EXCEEDED
) Status
= STATUS_SUCCESS
;
169 ObDereferenceObject(Thread
);
179 NtSuspendProcess(IN HANDLE ProcessHandle
)
181 KPROCESSOR_MODE PreviousMode
;
187 PreviousMode
= ExGetPreviousMode();
189 Status
= ObReferenceObjectByHandle(ProcessHandle
,
190 PROCESS_SUSPEND_RESUME
,
195 if (NT_SUCCESS(Status
))
198 Status
= STATUS_NOT_IMPLEMENTED
;
199 DPRINT1("NtSuspendProcess not yet implemented!\n");
201 ObDereferenceObject(Process
);
213 NtResumeProcess(IN HANDLE ProcessHandle
)
215 KPROCESSOR_MODE PreviousMode
;
221 PreviousMode
= ExGetPreviousMode();
223 Status
= ObReferenceObjectByHandle(ProcessHandle
,
224 PROCESS_SUSPEND_RESUME
,
229 if (NT_SUCCESS(Status
))
232 Status
= STATUS_NOT_IMPLEMENTED
;
233 DPRINT1("NtResumeProcess not yet implemented!\n");
235 ObDereferenceObject(Process
);