mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 12:06:52 +00:00
[CSRSRV]: Call the fake BaseSrv Init function during Server DLL load, not during SharedSection load, to be closer to where it should be.
[CSRSRV]: Enable some disabled code-paths and fix some locking patterns to be closer to what the code should look/be like. Correct ref count management is one of the things where regressions could show up later, so trying to nail these down now. svn path=/trunk/; revision=55650
This commit is contained in:
parent
142db9abdf
commit
9f969348ab
5 changed files with 160 additions and 12 deletions
|
@ -106,7 +106,9 @@ NTSTATUS WINAPI CsrFreeProcessData(HANDLE Pid)
|
||||||
Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
|
Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
|
||||||
NextEntry = NextEntry->Flink;
|
NextEntry = NextEntry->Flink;
|
||||||
|
|
||||||
|
ASSERT(ProcessStructureListLocked());
|
||||||
CsrThreadRefcountZero(Thread);
|
CsrThreadRefcountZero(Thread);
|
||||||
|
LOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pProcessData->ClientViewBase)
|
if (pProcessData->ClientViewBase)
|
||||||
|
@ -233,17 +235,21 @@ CSR_API(CsrTerminateProcess)
|
||||||
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
|
||||||
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
|
||||||
|
|
||||||
|
LOCK;
|
||||||
|
|
||||||
NextEntry = ProcessData->ThreadList.Flink;
|
NextEntry = ProcessData->ThreadList.Flink;
|
||||||
while (NextEntry != &ProcessData->ThreadList)
|
while (NextEntry != &ProcessData->ThreadList)
|
||||||
{
|
{
|
||||||
Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
|
Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
|
||||||
NextEntry = NextEntry->Flink;
|
NextEntry = NextEntry->Flink;
|
||||||
|
|
||||||
|
ASSERT(ProcessStructureListLocked());
|
||||||
CsrThreadRefcountZero(Thread);
|
CsrThreadRefcountZero(Thread);
|
||||||
|
LOCK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNLOCK;
|
||||||
ProcessData->Flags |= CsrProcessTerminated;
|
ProcessData->Flags |= CsrProcessTerminated;
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -783,9 +783,6 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hackito ergo sum */
|
|
||||||
BasepFakeStaticServerData();
|
|
||||||
|
|
||||||
/* Load us */
|
/* Load us */
|
||||||
Status = CsrLoadServerDll("CSRSS", NULL, CSR_SRV_SERVER);
|
Status = CsrLoadServerDll("CSRSS", NULL, CSR_SRV_SERVER);
|
||||||
}
|
}
|
||||||
|
@ -825,6 +822,10 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
|
||||||
|
|
||||||
/* Load it */
|
/* Load it */
|
||||||
if (CsrDebug & 1) DPRINT1("CSRSS: Should be loading ServerDll=%s:%s\n", ParameterValue, EntryPoint);
|
if (CsrDebug & 1) DPRINT1("CSRSS: Should be loading ServerDll=%s:%s\n", ParameterValue, EntryPoint);
|
||||||
|
|
||||||
|
/* Hackito ergo sum */
|
||||||
|
BasepFakeStaticServerData();
|
||||||
|
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
@ -1061,7 +1062,7 @@ CsrServerInitialization(IN ULONG ArgumentCount,
|
||||||
__FUNCTION__, Status);
|
__FUNCTION__, Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up Session Support */
|
/* Set up Session Support */
|
||||||
Status = CsrInitializeNtSessionList();
|
Status = CsrInitializeNtSessionList();
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
|
|
@ -382,12 +382,141 @@ Quickie:
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*++
|
||||||
|
* @name CsrProcessRefcountZero
|
||||||
|
*
|
||||||
|
* The CsrProcessRefcountZero routine is executed when a CSR Process has lost
|
||||||
|
* all its active references. It removes and de-allocates the CSR Process.
|
||||||
|
*
|
||||||
|
* @param CsrProcess
|
||||||
|
* Pointer to the CSR Process that is to be deleted.
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*
|
||||||
|
* @remarks Do not call this routine. It is reserved for the internal
|
||||||
|
* thread management routines when a CSR Process has lost all
|
||||||
|
* its references.
|
||||||
|
*
|
||||||
|
* This routine is called with the Process Lock held.
|
||||||
|
*
|
||||||
|
*--*/
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
|
||||||
|
{
|
||||||
|
ASSERT(ProcessStructureListLocked());
|
||||||
|
|
||||||
|
/* Remove the Process from the list */
|
||||||
|
CsrRemoveProcess(CsrProcess);
|
||||||
|
|
||||||
|
/* Check if there's a session */
|
||||||
|
if (CsrProcess->NtSession)
|
||||||
|
{
|
||||||
|
/* Dereference the Session */
|
||||||
|
//CsrDereferenceNtSession(CsrProcess->NtSession, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close the Client Port if there is one */
|
||||||
|
if (CsrProcess->ClientPort) NtClose(CsrProcess->ClientPort);
|
||||||
|
|
||||||
|
/* Close the process handle */
|
||||||
|
NtClose(CsrProcess->ProcessHandle);
|
||||||
|
|
||||||
|
/* Free the Proces Object */
|
||||||
|
CsrDeallocateProcess(CsrProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*++
|
||||||
|
* @name CsrLockedDereferenceProcess
|
||||||
|
*
|
||||||
|
* The CsrLockedDereferenceProcess dereferences a CSR Process while the
|
||||||
|
* Process Lock is already being held.
|
||||||
|
*
|
||||||
|
* @param CsrProcess
|
||||||
|
* Pointer to the CSR Process to be dereferenced.
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*
|
||||||
|
* @remarks This routine will return with the Process Lock held.
|
||||||
|
*
|
||||||
|
*--*/
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
|
||||||
|
{
|
||||||
|
LONG LockCount;
|
||||||
|
|
||||||
|
/* Decrease reference count */
|
||||||
|
LockCount = --CsrProcess->ReferenceCount;
|
||||||
|
ASSERT(LockCount >= 0);
|
||||||
|
if (!LockCount)
|
||||||
|
{
|
||||||
|
/* Call the generic cleanup code */
|
||||||
|
DPRINT1("Should kill process: %p\n", CsrProcess);
|
||||||
|
//CsrProcessRefcountZero(CsrProcess);
|
||||||
|
CsrAcquireProcessLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*++
|
||||||
|
* @name CsrDereferenceProcess
|
||||||
|
* @implemented NT4
|
||||||
|
*
|
||||||
|
* The CsrDereferenceProcess routine removes a reference from a CSR Process.
|
||||||
|
*
|
||||||
|
* @param CsrThread
|
||||||
|
* Pointer to the CSR Process to dereference.
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*
|
||||||
|
* @remarks If the reference count has reached zero (ie: the CSR Process has
|
||||||
|
* no more active references), it will be deleted.
|
||||||
|
*
|
||||||
|
*--*/
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess)
|
||||||
|
{
|
||||||
|
LONG LockCount;
|
||||||
|
|
||||||
|
/* Acquire process lock */
|
||||||
|
CsrAcquireProcessLock();
|
||||||
|
|
||||||
|
/* Decrease reference count */
|
||||||
|
LockCount = --CsrProcess->ReferenceCount;
|
||||||
|
ASSERT(LockCount >= 0);
|
||||||
|
if (!LockCount)
|
||||||
|
{
|
||||||
|
/* Call the generic cleanup code */
|
||||||
|
CsrProcessRefcountZero(CsrProcess);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Just release the lock */
|
||||||
|
CsrReleaseProcessLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*++
|
||||||
|
* @name CsrUnlockProcess
|
||||||
|
* @implemented NT4
|
||||||
|
*
|
||||||
|
* The CsrUnlockProcess undoes a previous CsrLockProcessByClientId operation.
|
||||||
|
*
|
||||||
|
* @param CsrProcess
|
||||||
|
* Pointer to a previously locked CSR Process.
|
||||||
|
*
|
||||||
|
* @return STATUS_SUCCESS.
|
||||||
|
*
|
||||||
|
* @remarks This routine must be called with the Process Lock held.
|
||||||
|
*
|
||||||
|
*--*/
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
|
CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
|
||||||
{
|
{
|
||||||
/* Dereference the process */
|
/* Dereference the process */
|
||||||
//CsrLockedDereferenceProcess(CsrProcess);
|
CsrLockedDereferenceProcess(CsrProcess);
|
||||||
|
|
||||||
/* Release the lock and return */
|
/* Release the lock and return */
|
||||||
CsrReleaseProcessLock();
|
CsrReleaseProcessLock();
|
||||||
|
|
|
@ -113,7 +113,7 @@ CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
|
||||||
|
|
||||||
/* Reference the Thread and Process */
|
/* Reference the Thread and Process */
|
||||||
CsrThread->ReferenceCount++;
|
CsrThread->ReferenceCount++;
|
||||||
// CsrProcess->ReferenceCount++;
|
CsrProcess->ReferenceCount++;
|
||||||
|
|
||||||
/* Set the Parent Process */
|
/* Set the Parent Process */
|
||||||
CsrThread->Process = CsrProcess;
|
CsrThread->Process = CsrProcess;
|
||||||
|
@ -230,6 +230,8 @@ VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrRemoveThread(IN PCSR_THREAD CsrThread)
|
CsrRemoveThread(IN PCSR_THREAD CsrThread)
|
||||||
{
|
{
|
||||||
|
ASSERT(ProcessStructureListLocked());
|
||||||
|
|
||||||
/* Remove it from the List */
|
/* Remove it from the List */
|
||||||
RemoveEntryList(&CsrThread->Link);
|
RemoveEntryList(&CsrThread->Link);
|
||||||
|
|
||||||
|
@ -246,10 +248,10 @@ CsrRemoveThread(IN PCSR_THREAD CsrThread)
|
||||||
if (!(CsrThread->Process->Flags & CsrProcessLastThreadTerminated))
|
if (!(CsrThread->Process->Flags & CsrProcessLastThreadTerminated))
|
||||||
{
|
{
|
||||||
/* Let everyone know this process is about to lose the thread */
|
/* Let everyone know this process is about to lose the thread */
|
||||||
//CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
|
CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
|
||||||
|
|
||||||
/* Reference the Process */
|
/* Reference the Process */
|
||||||
//CsrLockedDereferenceProcess(CsrThread->Process);
|
CsrLockedDereferenceProcess(CsrThread->Process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,13 +263,15 @@ VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
||||||
{
|
{
|
||||||
|
PCSR_PROCESS CsrProcess = CsrThread->Process;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
ASSERT(ProcessStructureListLocked());
|
||||||
|
|
||||||
/* Remove this thread */
|
/* Remove this thread */
|
||||||
CsrRemoveThread(CsrThread);
|
CsrRemoveThread(CsrThread);
|
||||||
|
|
||||||
/* Release the Process Lock */
|
/* Release the Process Lock */
|
||||||
//CsrReleaseProcessLock();
|
CsrReleaseProcessLock();
|
||||||
|
|
||||||
/* Close the NT Thread Handle */
|
/* Close the NT Thread Handle */
|
||||||
if (CsrThread->ThreadHandle)
|
if (CsrThread->ThreadHandle)
|
||||||
|
@ -281,7 +285,7 @@ CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
|
||||||
CsrDeallocateThread(CsrThread);
|
CsrDeallocateThread(CsrThread);
|
||||||
|
|
||||||
/* Remove a reference from the process */
|
/* Remove a reference from the process */
|
||||||
//CsrDereferenceProcess(CsrProcess);
|
CsrDereferenceProcess(CsrProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
|
|
@ -385,12 +385,20 @@ CsrSrvSetPriorityClass(
|
||||||
IN OUT PULONG Reply
|
IN OUT PULONG Reply
|
||||||
);
|
);
|
||||||
|
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess);
|
||||||
|
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CsrLoadServerDll(IN PCHAR DllString,
|
CsrLoadServerDll(IN PCHAR DllString,
|
||||||
IN PCHAR EntryPoint OPTIONAL,
|
IN PCHAR EntryPoint OPTIONAL,
|
||||||
IN ULONG ServerId);
|
IN ULONG ServerId);
|
||||||
|
|
||||||
/* api/user.c */
|
/* api/user.c */
|
||||||
CSR_API(CsrRegisterServicesProcess);
|
CSR_API(CsrRegisterServicesProcess);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue