mirror of
https://github.com/reactos/reactos.git
synced 2025-01-01 03:54:02 +00:00
[KERNEL32/CSRSRV]: Handle ExitProcess CSRSS message and implement CsrDestroyProcess to do so. Also implement CsrDestroyThread for future purposes.
svn path=/trunk/; revision=55717
This commit is contained in:
parent
860a4e8855
commit
0181638af5
5 changed files with 82 additions and 21 deletions
|
@ -1753,6 +1753,7 @@ ExitProcess(IN UINT uExitCode)
|
|||
LdrShutdownProcess();
|
||||
|
||||
/* Notify Base Server of process termination */
|
||||
CsrRequest.Data.TerminateProcessRequest.uExitCode = uExitCode;
|
||||
CsrClientCallServer(&CsrRequest,
|
||||
NULL,
|
||||
MAKE_CSR_API(TERMINATE_PROCESS, CSR_NATIVE),
|
||||
|
|
|
@ -80,7 +80,7 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
ULONG Dummy;
|
||||
UINT uExitCode;
|
||||
} CSRSS_TERMINATE_PROCESS, *PCSRSS_TERMINATE_PROCESS;
|
||||
|
||||
typedef struct
|
||||
|
@ -713,6 +713,7 @@ typedef struct _CSR_API_MESSAGE
|
|||
{
|
||||
CSRSS_CREATE_PROCESS CreateProcessRequest;
|
||||
CSRSS_CREATE_THREAD CreateThreadRequest;
|
||||
CSRSS_TERMINATE_PROCESS TerminateProcessRequest;
|
||||
CSRSS_CONNECT_PROCESS ConnectRequest;
|
||||
CSRSS_WRITE_CONSOLE WriteConsoleRequest;
|
||||
CSRSS_READ_CONSOLE ReadConsoleRequest;
|
||||
|
|
|
@ -245,26 +245,12 @@ CSR_API(CsrSrvCreateThread)
|
|||
|
||||
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)
|
||||
|
|
|
@ -310,6 +310,75 @@ CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
|||
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
|
||||
*
|
||||
|
|
|
@ -420,6 +420,10 @@ NTAPI
|
|||
CsrDestroyProcess(IN PCLIENT_ID Cid,
|
||||
IN NTSTATUS ExitStatus);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrDestroyThread(IN PCLIENT_ID Cid);
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread);
|
||||
|
|
Loading…
Reference in a new issue