typedef struct
{
- ULONG Dummy;
+ UINT uExitCode;
} CSRSS_TERMINATE_PROCESS, *PCSRSS_TERMINATE_PROCESS;
typedef struct
{
CSRSS_CREATE_PROCESS CreateProcessRequest;
CSRSS_CREATE_THREAD CreateThreadRequest;
+ CSRSS_TERMINATE_PROCESS TerminateProcessRequest;
CSRSS_CONNECT_PROCESS ConnectRequest;
CSRSS_WRITE_CONSOLE WriteConsoleRequest;
CSRSS_READ_CONSOLE ReadConsoleRequest;
CSR_API(CsrTerminateProcess)
{
- PLIST_ENTRY NextEntry;
- PCSR_THREAD Thread;
-
- LOCK;
-
- NextEntry = ProcessData->ThreadList.Flink;
- while (NextEntry != &ProcessData->ThreadList)
- {
- Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
- NextEntry = NextEntry->Flink;
-
- ASSERT(ProcessStructureListLocked());
- CsrThreadRefcountZero(Thread);
- LOCK;
-
- }
-
- UNLOCK;
- ProcessData->Flags |= CsrProcessTerminated;
- return STATUS_SUCCESS;
+ PCSR_THREAD CsrThread = NtCurrentTeb()->CsrClientThread;
+ ASSERT(CsrThread != NULL);
+
+ /* Remove the CSR_THREADs and CSR_PROCESS */
+ return CsrDestroyProcess(&CsrThread->ClientId,
+ (NTSTATUS)Request->Data.TerminateProcessRequest.uExitCode);
}
CSR_API(CsrConnectProcess)
CsrDereferenceProcess(CsrProcess);
}
+/*++
+ * @name CsrDestroyThread
+ * @implemented NT4
+ *
+ * The CsrDestroyThread routine destroys the CSR Thread corresponding to
+ * a given Thread ID.
+ *
+ * @param Cid
+ * Pointer to the Client ID Structure corresponding to the CSR
+ * Thread which is about to be destroyed.
+ *
+ * @return STATUS_SUCCESS in case of success, STATUS_THREAD_IS_TERMINATING
+ * if the CSR Thread is already terminating.
+ *
+ * @remarks None.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrDestroyThread(IN PCLIENT_ID Cid)
+{
+ CLIENT_ID ClientId = *Cid;
+ PCSR_THREAD CsrThread;
+ PCSR_PROCESS CsrProcess;
+
+ /* Acquire lock */
+ CsrAcquireProcessLock();
+
+ /* Find the thread */
+ CsrThread = CsrLocateThreadByClientId(&CsrProcess,
+ &ClientId);
+
+ /* Make sure we got one back, and that it's not already gone */
+ if (!CsrThread || CsrThread->Flags & CsrThreadTerminated)
+ {
+ /* Release the lock and return failure */
+ CsrReleaseProcessLock();
+ return STATUS_THREAD_IS_TERMINATING;
+ }
+
+ /* Set the terminated flag */
+ CsrThread->Flags |= CsrThreadTerminated;
+
+ /* Acquire the Wait Lock */
+ CsrAcquireWaitLock();
+
+ /* Do we have an active wait block? */
+ if (CsrThread->WaitBlock)
+ {
+ /* Notify waiters of termination */
+ CsrNotifyWaitBlock(CsrThread->WaitBlock,
+ NULL,
+ NULL,
+ NULL,
+ CsrProcessTerminating,
+ TRUE);
+ }
+
+ /* Release the Wait Lock */
+ CsrReleaseWaitLock();
+
+ /* Dereference the thread */
+ CsrLockedDereferenceThread(CsrThread);
+
+ /* Release the Process Lock and return success */
+ CsrReleaseProcessLock();
+ return STATUS_SUCCESS;
+}
+
/*++
* @name CsrLockedDereferenceThread
*