mirror of
https://github.com/reactos/reactos.git
synced 2024-08-11 05:37:59 +00:00
[CSRSRV]: Update CsrAddStaticServerthread and CsrDestroyThread based on code from CSRSRV2. Main change is that ProtectHandle/UnProtectHandle is now called.
svn path=/trunk/; revision=55607
This commit is contained in:
parent
393487dbd2
commit
7428341ac4
|
@ -32,6 +32,84 @@ extern PCSRSS_PROCESS_DATA ProcessData[256];
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* 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
|
PCSR_THREAD
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrAllocateThread(IN PCSRSS_PROCESS_DATA CsrProcess)
|
CsrAllocateThread(IN PCSRSS_PROCESS_DATA CsrProcess)
|
||||||
|
@ -192,6 +270,8 @@ VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
||||||
{
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
/* Remove this thread */
|
/* Remove this thread */
|
||||||
CsrRemoveThread(CsrThread);
|
CsrRemoveThread(CsrThread);
|
||||||
|
|
||||||
|
@ -199,7 +279,12 @@ CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
||||||
//CsrReleaseProcessLock();
|
//CsrReleaseProcessLock();
|
||||||
|
|
||||||
/* Close the NT Thread Handle */
|
/* 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 */
|
/* De-allocate the CSR Thread Object */
|
||||||
CsrDeallocateThread(CsrThread);
|
CsrDeallocateThread(CsrThread);
|
||||||
|
@ -270,6 +355,30 @@ CsrCreateThread(IN PCSRSS_PROCESS_DATA CsrProcess,
|
||||||
return STATUS_SUCCESS;
|
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
|
PCSR_THREAD
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrAddStaticServerThread(IN HANDLE hThread,
|
CsrAddStaticServerThread(IN HANDLE hThread,
|
||||||
|
@ -282,11 +391,12 @@ CsrAddStaticServerThread(IN HANDLE hThread,
|
||||||
CsrAcquireProcessLock();
|
CsrAcquireProcessLock();
|
||||||
|
|
||||||
/* Allocate the Server Thread */
|
/* Allocate the Server Thread */
|
||||||
if ((CsrThread = CsrAllocateThread(CsrRootProcess)))
|
CsrThread = CsrAllocateThread(CsrRootProcess);
|
||||||
|
if (CsrThread)
|
||||||
{
|
{
|
||||||
/* Setup the Object */
|
/* Setup the Object */
|
||||||
// DPRINT1("New CSR thread created: %lx PID/TID: %lx/%lx\n", CsrThread, ClientId->UniqueProcess, ClientId->UniqueThread);
|
|
||||||
CsrThread->ThreadHandle = hThread;
|
CsrThread->ThreadHandle = hThread;
|
||||||
|
ProtectHandle(hThread);
|
||||||
CsrThread->ClientId = *ClientId;
|
CsrThread->ClientId = *ClientId;
|
||||||
CsrThread->Flags = ThreadFlags;
|
CsrThread->Flags = ThreadFlags;
|
||||||
|
|
||||||
|
@ -296,6 +406,10 @@ CsrAddStaticServerThread(IN HANDLE hThread,
|
||||||
/* Increment the thread count */
|
/* Increment the thread count */
|
||||||
CsrRootProcess->ThreadCount++;
|
CsrRootProcess->ThreadCount++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT1("CsrAddStaticServerThread: alloc failed for thread 0x%x\n", hThread);
|
||||||
|
}
|
||||||
|
|
||||||
/* Release the Process Lock and return */
|
/* Release the Process Lock and return */
|
||||||
CsrReleaseProcessLock();
|
CsrReleaseProcessLock();
|
||||||
|
|
Loading…
Reference in a new issue