Author: ion
Date: Wed Feb 15 15:05:35 2012
New Revision: 55607
URL:
http://svn.reactos.org/svn/reactos?rev=55607&view=rev
Log:
[CSRSRV]: Update CsrAddStaticServerthread and CsrDestroyThread based on code from CSRSRV2.
Main change is that ProtectHandle/UnProtectHandle is now called.
Modified:
trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c [iso-8859-1] Wed Feb 15
15:05:35 2012
@@ -6,7 +6,7 @@
* PROGRAMMERS: ReactOS Portable Systems Group
* Alex Ionescu
*/
-
+
/* INCLUDES *******************************************************************/
#include <srv.h>
@@ -32,6 +32,84 @@
/* FUNCTIONS ******************************************************************/
+/*++
+ * @name ProtectHandle
+ * @implemented NT5.2
+ *
+ * The ProtectHandle routine protects an object handle against closure.
+ *
+ * @return TRUE or FALSE.
+ *
+ * @remarks None.
+ *
+ *--*/
+BOOLEAN
+NTAPI
+ProtectHandle(IN HANDLE ObjectHandle)
+{
+ NTSTATUS Status;
+ OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo;
+
+ /* Query current state */
+ Status = NtQueryObject(ObjectHandle,
+ ObjectHandleFlagInformation,
+ &HandleInfo,
+ sizeof(HandleInfo),
+ NULL);
+ if (NT_SUCCESS(Status))
+ {
+ /* Enable protect from close */
+ HandleInfo.ProtectFromClose = TRUE;
+ Status = NtSetInformationObject(ObjectHandle,
+ ObjectHandleFlagInformation,
+ &HandleInfo,
+ sizeof(HandleInfo));
+ if (NT_SUCCESS(Status)) return TRUE;
+ }
+
+ /* We failed to or set the state */
+ return FALSE;
+}
+
+/*++
+ * @name UnProtectHandle
+ * @implemented NT5.2
+ *
+ * The UnProtectHandle routine unprotects an object handle against closure.
+ *
+ * @return TRUE or FALSE.
+ *
+ * @remarks None.
+ *
+ *--*/
+BOOLEAN
+NTAPI
+UnProtectHandle(IN HANDLE ObjectHandle)
+{
+ NTSTATUS Status;
+ OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo;
+
+ /* Query current state */
+ Status = NtQueryObject(ObjectHandle,
+ ObjectHandleFlagInformation,
+ &HandleInfo,
+ sizeof(HandleInfo),
+ NULL);
+ if (NT_SUCCESS(Status))
+ {
+ /* Disable protect from close */
+ HandleInfo.ProtectFromClose = FALSE;
+ Status = NtSetInformationObject(ObjectHandle,
+ ObjectHandleFlagInformation,
+ &HandleInfo,
+ sizeof(HandleInfo));
+ if (NT_SUCCESS(Status)) return TRUE;
+ }
+
+ /* We failed to or set the state */
+ return FALSE;
+}
+
PCSR_THREAD
NTAPI
CsrAllocateThread(IN PCSRSS_PROCESS_DATA CsrProcess)
@@ -64,7 +142,7 @@
/* Hash the Thread */
i = CsrHashThread(ClientId->UniqueThread);
-
+
/* Set the list pointers */
ListHead = &CsrThreadHashTable[i];
NextEntry = ListHead->Flink;
@@ -192,6 +270,8 @@
NTAPI
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
{
+ NTSTATUS Status;
+
/* Remove this thread */
CsrRemoveThread(CsrThread);
@@ -199,8 +279,13 @@
//CsrReleaseProcessLock();
/* Close the NT Thread Handle */
- if (CsrThread->ThreadHandle) NtClose(CsrThread->ThreadHandle);
-
+ if (CsrThread->ThreadHandle)
+ {
+ UnProtectHandle(CsrThread->ThreadHandle);
+ Status = NtClose(CsrThread->ThreadHandle);
+ ASSERT(NT_SUCCESS(Status));
+ }
+
/* De-allocate the CSR Thread Object */
CsrDeallocateThread(CsrThread);
@@ -270,6 +355,30 @@
return STATUS_SUCCESS;
}
+/*++
+ * @name CsrAddStaticServerThread
+ * @implemented NT4
+ *
+ * The CsrAddStaticServerThread routine adds a new CSR Thread to the
+ * CSR Server Process (CsrRootProcess).
+ *
+ * @param hThread
+ * Handle to an existing NT Thread to which to associate this
+ * CSR Thread.
+ *
+ * @param ClientId
+ * Pointer to the Client ID structure of the NT Thread to associate
+ * with this CSR Thread.
+ *
+ * @param ThreadFlags
+ * Initial CSR Thread Flags to associate to this CSR Thread. Usually
+ * CsrThreadIsServerThread.
+ *
+ * @return Pointer to the newly allocated CSR Thread.
+ *
+ * @remarks None.
+ *
+ *--*/
PCSR_THREAD
NTAPI
CsrAddStaticServerThread(IN HANDLE hThread,
@@ -282,11 +391,12 @@
CsrAcquireProcessLock();
/* Allocate the Server Thread */
- if ((CsrThread = CsrAllocateThread(CsrRootProcess)))
+ CsrThread = CsrAllocateThread(CsrRootProcess);
+ if (CsrThread)
{
/* Setup the Object */
-// DPRINT1("New CSR thread created: %lx PID/TID: %lx/%lx\n", CsrThread,
ClientId->UniqueProcess, ClientId->UniqueThread);
CsrThread->ThreadHandle = hThread;
+ ProtectHandle(hThread);
CsrThread->ClientId = *ClientId;
CsrThread->Flags = ThreadFlags;
@@ -295,6 +405,10 @@
/* Increment the thread count */
CsrRootProcess->ThreadCount++;
+ }
+ else
+ {
+ DPRINT1("CsrAddStaticServerThread: alloc failed for thread 0x%x\n",
hThread);
}
/* Release the Process Lock and return */