Author: ion Date: Thu Sep 12 09:02:48 2013 New Revision: 60059
URL: http://svn.reactos.org/svn/reactos?rev=60059&view=rev Log: [NTOSKRNL]: Implement ThreadIsTermination info class in NtQueryInformationThread. [CSRSRV]: CsrInsertThread should call this API to make sure the thread isn't dead already. Update the callers to handle this possible failure. This behavior was obeserved in Windows' CSRSRV.DLL. It now works in ReactOS as well.
Modified: trunk/reactos/ntoskrnl/ps/query.c trunk/reactos/subsystems/win32/csrsrv/api.h trunk/reactos/subsystems/win32/csrsrv/procsup.c trunk/reactos/subsystems/win32/csrsrv/session.c trunk/reactos/subsystems/win32/csrsrv/thredsup.c
Modified: trunk/reactos/ntoskrnl/ps/query.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/query.c?rev=600... ============================================================================== --- trunk/reactos/ntoskrnl/ps/query.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ps/query.c [iso-8859-1] Thu Sep 12 09:02:48 2013 @@ -2412,6 +2412,7 @@ (PTHREAD_BASIC_INFORMATION)ThreadInformation; PKERNEL_USER_TIMES ThreadTime = (PKERNEL_USER_TIMES)ThreadInformation; KIRQL OldIrql; + ULONG ThreadTerminated; PAGED_CODE();
/* Check if we were called from user mode */ @@ -2659,6 +2660,31 @@ Status = _SEH2_GetExceptionCode(); } _SEH2_END; + break; + + case ThreadIsTerminated: + + /* Set the return length*/ + Length = sizeof(ThreadTerminated); + + if (ThreadInformationLength != Length) + { + Status = STATUS_INFO_LENGTH_MISMATCH; + break; + } + + ThreadTerminated = PsIsThreadTerminating(Thread); + + _SEH2_TRY + { + *(PULONG)ThreadInformation = ThreadTerminated ? 1 : 0; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = _SEH2_GetExceptionCode(); + } + _SEH2_END; + break;
/* Anything else */
Modified: trunk/reactos/subsystems/win32/csrsrv/api.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/api... ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/api.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/api.h [iso-8859-1] Thu Sep 12 09:02:48 2013 @@ -137,10 +137,14 @@ NTAPI UnProtectHandle(IN HANDLE ObjectHandle);
-VOID +NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread); + +VOID +NTAPI +CsrDeallocateThread(IN PCSR_THREAD CsrThread);
VOID NTAPI
Modified: trunk/reactos/subsystems/win32/csrsrv/procsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/pro... ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/procsup.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/procsup.c [iso-8859-1] Thu Sep 12 09:02:48 2013 @@ -690,7 +690,15 @@ CsrThread->Flags = 0;
/* Insert the Thread into the Process */ - CsrInsertThread(CsrProcess, CsrThread); + Status = CsrInsertThread(CsrProcess, CsrThread); + if (!NT_SUCCESS(Status)) + { + /* Bail out */ + CsrDeallocateProcess(CsrProcess); + CsrDeallocateThread(CsrThread); + CsrReleaseProcessLock(); + return Status; + }
/* Reference the session */ CsrReferenceNtSession(NtSession);
Modified: trunk/reactos/subsystems/win32/csrsrv/session.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/ses... ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/session.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/session.c [iso-8859-1] Thu Sep 12 09:02:48 2013 @@ -289,7 +289,15 @@ CsrThread->Flags = 0;
/* Insert it into the Process List */ - CsrInsertThread(CsrProcess, CsrThread); + Status = CsrInsertThread(CsrProcess, CsrThread); + if (!NT_SUCCESS(Status)) + { + /* Bail out */ + CsrDeallocateProcess(CsrProcess); + CsrDeallocateThread(CsrThread); + CsrReleaseProcessLock(); + return Status; + }
/* Setup Process Data */ CsrProcess->ClientId = CreateSession->ProcessInfo.ClientId;
Modified: trunk/reactos/subsystems/win32/csrsrv/thredsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/thr... ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/thredsup.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/thredsup.c [iso-8859-1] Thu Sep 12 09:02:48 2013 @@ -292,13 +292,24 @@ * @remarks None. * *--*/ -VOID +NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread) { ULONG i; + NTSTATUS Status; + ULONG ThreadInfo; // ASSERT(ProcessStructureListLocked()); + + /* Make sure the thread isn't already dead by the time we got this */ + Status = NtQueryInformationThread(Thread->ThreadHandle, + ThreadIsTerminated, + &ThreadInfo, + sizeof(ThreadInfo), + NULL); + if (!NT_SUCCESS(Status)) return Status; + if (ThreadInfo == TRUE) return STATUS_THREAD_IS_TERMINATING;
/* Insert it into the Regular List */ InsertTailList(&Process->ThreadList, &Thread->Link); @@ -311,6 +322,7 @@
/* Insert it there too */ InsertHeadList(&CsrThreadHashTable[i], &Thread->HashLinks); + return STATUS_SUCCESS; }
/*++ @@ -623,7 +635,15 @@ CsrThread->Flags = 0;
/* Insert the Thread into the Process */ - CsrInsertThread(CsrProcess, CsrThread); + Status = CsrInsertThread(CsrProcess, CsrThread); + if (!NT_SUCCESS(Status)) + { + /* Bail out */ + if (CsrThread->ThreadHandle != hThread) NtClose(CsrThread->ThreadHandle); + CsrUnlockProcess(CsrProcess); + CsrDeallocateThread(CsrThread); + return Status; + }
/* Release the lock and return */ CsrUnlockProcess(CsrProcess); @@ -720,7 +740,14 @@ CsrThread->Flags = 0;
/* Insert the Thread into the Process */ - CsrInsertThread(CsrProcess, CsrThread); + Status = CsrInsertThread(CsrProcess, CsrThread); + if (!NT_SUCCESS(Status)) + { + /* Bail out */ + CsrUnlockProcess(CsrProcess); + CsrDeallocateThread(CsrThread); + return Status; + }
/* Release the lock and return */ CsrReleaseProcessLock();