[ros-diffs] [ion] 55650: [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 f...

ion at svn.reactos.org ion at svn.reactos.org
Thu Feb 16 21:47:01 UTC 2012


Author: ion
Date: Thu Feb 16 21:46:59 2012
New Revision: 55650

URL: http://svn.reactos.org/svn/reactos?rev=55650&view=rev
Log:
[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.

Modified:
    trunk/reactos/subsystems/win32/csrss/csrsrv/api/process.c
    trunk/reactos/subsystems/win32/csrss/csrsrv/init.c
    trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c
    trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c
    trunk/reactos/subsystems/win32/csrss/include/api.h

Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/api/process.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csrsrv/api/process.c?rev=55650&r1=55649&r2=55650&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/api/process.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/api/process.c [iso-8859-1] Thu Feb 16 21:46:59 2012
@@ -106,7 +106,9 @@
         Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
         NextEntry = NextEntry->Flink;
 
+        ASSERT(ProcessStructureListLocked());
         CsrThreadRefcountZero(Thread);
+        LOCK;
     }
 
     if (pProcessData->ClientViewBase)
@@ -233,17 +235,21 @@
    Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
    Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
    
+   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;
 }

Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/init.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csrsrv/init.c?rev=55650&r1=55649&r2=55650&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/init.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/init.c [iso-8859-1] Thu Feb 16 21:46:59 2012
@@ -783,9 +783,6 @@
                 return Status;
             }
 
-            /* Hackito ergo sum */
-            BasepFakeStaticServerData();
-
             /* Load us */
             Status = CsrLoadServerDll("CSRSS", NULL, CSR_SRV_SERVER);
         }
@@ -825,6 +822,10 @@
 
             /* Load it */
             if (CsrDebug & 1) DPRINT1("CSRSS: Should be loading ServerDll=%s:%s\n", ParameterValue, EntryPoint);
+
+            /* Hackito ergo sum */
+            BasepFakeStaticServerData();
+
             Status = STATUS_SUCCESS;
             if (!NT_SUCCESS(Status))
             {
@@ -1061,7 +1062,7 @@
                 __FUNCTION__, Status);
         return Status;
     }
-    
+
     /* Set up Session Support */
     Status = CsrInitializeNtSessionList();
     if (!NT_SUCCESS(Status))

Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c?rev=55650&r1=55649&r2=55650&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c [iso-8859-1] Thu Feb 16 21:46:59 2012
@@ -382,12 +382,141 @@
     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
 NTAPI
 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
 {
     /* Dereference the process */
-    //CsrLockedDereferenceProcess(CsrProcess);
+    CsrLockedDereferenceProcess(CsrProcess);
 
     /* Release the lock and return */
     CsrReleaseProcessLock();

Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c?rev=55650&r1=55649&r2=55650&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c [iso-8859-1] Thu Feb 16 21:46:59 2012
@@ -113,7 +113,7 @@
 
     /* Reference the Thread and Process */
     CsrThread->ReferenceCount++;
-   // CsrProcess->ReferenceCount++;
+    CsrProcess->ReferenceCount++;
 
     /* Set the Parent Process */
     CsrThread->Process = CsrProcess;
@@ -230,6 +230,8 @@
 NTAPI
 CsrRemoveThread(IN PCSR_THREAD CsrThread)
 {
+    ASSERT(ProcessStructureListLocked());
+
     /* Remove it from the List */
     RemoveEntryList(&CsrThread->Link);
 
@@ -246,10 +248,10 @@
         if (!(CsrThread->Process->Flags & CsrProcessLastThreadTerminated))
         {
             /* Let everyone know this process is about to lose the thread */
-            //CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
+            CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
 
             /* Reference the Process */
-            //CsrLockedDereferenceProcess(CsrThread->Process);
+            CsrLockedDereferenceProcess(CsrThread->Process);
         }
     }
 
@@ -261,13 +263,15 @@
 NTAPI
 CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
 {
+    PCSR_PROCESS CsrProcess = CsrThread->Process;
     NTSTATUS Status;
+    ASSERT(ProcessStructureListLocked());
 
     /* Remove this thread */
     CsrRemoveThread(CsrThread);
 
     /* Release the Process Lock */
-    //CsrReleaseProcessLock();
+    CsrReleaseProcessLock();
 
     /* Close the NT Thread Handle */
     if (CsrThread->ThreadHandle)
@@ -281,7 +285,7 @@
     CsrDeallocateThread(CsrThread);
 
     /* Remove a reference from the process */
-    //CsrDereferenceProcess(CsrProcess);
+    CsrDereferenceProcess(CsrProcess);
 }
 
 NTSTATUS

Modified: trunk/reactos/subsystems/win32/csrss/include/api.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/include/api.h?rev=55650&r1=55649&r2=55650&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/include/api.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/include/api.h [iso-8859-1] Thu Feb 16 21:46:59 2012
@@ -385,12 +385,20 @@
     IN OUT PULONG Reply
 );
 
+VOID
+NTAPI
+CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess);
+
+VOID
+NTAPI
+CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
+
 NTSTATUS
 NTAPI
 CsrLoadServerDll(IN PCHAR DllString,
                  IN PCHAR EntryPoint OPTIONAL,
                  IN ULONG ServerId);
-                 
+
 /* api/user.c */
 CSR_API(CsrRegisterServicesProcess);
 




More information about the Ros-diffs mailing list