[REACTOS]
[reactos.git] / reactos / subsystems / win32 / csrsrv / session.c
similarity index 92%
rename from reactos/subsystems/win32/csrss/csrsrv/session.c
rename to reactos/subsystems/win32/csrsrv/session.c
index 361b3c3..7970290 100644 (file)
@@ -1,33 +1,40 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS CSR Sub System
- * FILE:            subsystems/win32/csrss/csrsrv/session.c
+ * PROJECT:         ReactOS Client/Server Runtime SubSystem
+ * FILE:            subsystems/win32/csrsrv/session.c
  * PURPOSE:         CSR Server DLL Session Implementation
  * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
  */
 
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
 
 #include "srv.h"
 
 #define NDEBUG
 #include <debug.h>
 
-/* DATA **********************************************************************/
+/* DATA ***********************************************************************/
 
 RTL_CRITICAL_SECTION CsrNtSessionLock;
 LIST_ENTRY CsrNtSessionList;
 
-PCHAR CsrServerSbApiName[5] =
+PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession] =
+{
+    CsrSbCreateSession,
+    CsrSbTerminateSession,
+    CsrSbForeignSessionComplete,
+    CsrSbCreateProcess
+};
+
+PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession] =
 {
     "SbCreateSession",
     "SbTerminateSession",
     "SbForeignSessionComplete",
-    "SbCreateProcess",
-    "Unknown Csr Sb Api Number"
+    "SbCreateProcess"
 };
 
-/* PRIVATE FUNCTIONS *********************************************************/
+/* PRIVATE FUNCTIONS **********************************************************/
 
 /*++
  * @name CsrInitializeNtSessionList
@@ -45,8 +52,6 @@ NTSTATUS
 NTAPI
 CsrInitializeNtSessionList(VOID)
 {
-    DPRINT("CSRSRV: %s called\n", __FUNCTION__);
-
     /* Initialize the Session List */
     InitializeListHead(&CsrNtSessionList);
 
@@ -74,7 +79,7 @@ CsrAllocateNtSession(IN ULONG SessionId)
     PCSR_NT_SESSION NtSession;
 
     /* Allocate an NT Session Object */
-    NtSession = RtlAllocateHeap(CsrHeap, 0, sizeof(CSR_NT_SESSION));
+    NtSession = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, sizeof(CSR_NT_SESSION));
     if (NtSession)
     {
         /* Setup the Session Object */
@@ -160,7 +165,7 @@ CsrDereferenceNtSession(IN PCSR_NT_SESSION Session,
     ASSERT(Session->ReferenceCount != 0);
 
     /* Dereference the Session Object */
-    if (!(--Session->ReferenceCount))
+    if ((--Session->ReferenceCount) == 0)
     {
         /* Remove it from the list */
         RemoveEntryList(&Session->SessionLink);
@@ -181,7 +186,7 @@ CsrDereferenceNtSession(IN PCSR_NT_SESSION Session,
     }
 }
 
-/* SESSION MANAGER FUNCTIONS**************************************************/
+/* SESSION MANAGER FUNCTIONS **************************************************/
 
 /*++
  * @name CsrSbCreateSession
@@ -205,11 +210,12 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
     PSB_CREATE_SESSION_MSG CreateSession = &ApiMessage->CreateSession;
     HANDLE hProcess, hThread;
     PCSR_PROCESS CsrProcess;
+    PCSR_THREAD CsrThread;
+    PCSR_SERVER_DLL ServerDll;
+    PVOID ProcessData;
     NTSTATUS Status;
     KERNEL_USER_TIMES KernelTimes;
-    PCSR_THREAD CsrThread;
-    //PVOID ProcessData;
-    //ULONG i;
+    ULONG i;
 
     /* Save the Process and Thread Handles */
     hProcess = CreateSession->ProcessInfo.ProcessHandle;
@@ -292,22 +298,25 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
 
     /* Set the Process Priority */
     CsrSetBackgroundPriority(CsrProcess);
-#if 0
+
     /* Get the first data location */
     ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
 
     /* Loop every DLL */
     for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
     {
+        /* Get the current Server */
+        ServerDll = CsrLoadedServerDll[i];
+
         /* Check if the DLL is loaded and has Process Data */
-        if (CsrLoadedServerDll[i] && CsrLoadedServerDll[i]->SizeOfProcessData)
+        if (ServerDll && ServerDll->SizeOfProcessData)
         {
             /* Write the pointer to the data */
             CsrProcess->ServerData[i] = ProcessData;
 
             /* Move to the next data location */
             ProcessData = (PVOID)((ULONG_PTR)ProcessData +
-                                  CsrLoadedServerDll[i]->SizeOfProcessData);
+                                  ServerDll->SizeOfProcessData);
         }
         else
         {
@@ -315,12 +324,9 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
             CsrProcess->ServerData[i] = NULL;
         }
     }
-#else
-    /* HACKZ: should go in BaseSrv part of CreateCallback done in Insert below */
-    RtlInitializeCriticalSection(&CsrProcess->HandleTableLock);
-#endif
+
     /* Insert the Process */
-    CsrInsertProcess(NULL, NULL, CsrProcess);
+    CsrInsertProcess(NULL, CsrProcess);
 
     /* Activate the Thread */
     ApiMessage->ReturnValue = NtResumeThread(hThread, NULL);
@@ -397,15 +403,6 @@ CsrSbCreateProcess(IN PSB_API_MSG ApiMessage)
     return TRUE;
 }
 
-PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
-{
-    CsrSbCreateSession,
-    CsrSbTerminateSession,
-    CsrSbForeignSessionComplete,
-    CsrSbCreateProcess,
-    NULL
-};
-
 /*++
  * @name CsrSbApiHandleConnectionRequest
  *
@@ -535,14 +532,14 @@ CsrSbApiRequestThread(IN PVOID Parameter)
         }
 
         /*
-         * It's an API Message, check if it's within limits. If it's not, the
-         * NT Behaviour is to set this to the Maximum API.
+         * It's an API Message, check if it's within limits. If it's not,
+         * the NT Behaviour is to set this to the Maximum API.
          */
         if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
         {
             ReceiveMsg.ApiNumber = SbpMaxApiNumber;
             DPRINT1("CSRSS: %lx is invalid Sb ApiNumber\n", ReceiveMsg.ApiNumber);
-         }
+        }
 
         /* Reuse the message */
         ReplyMsg = &ReceiveMsg;
@@ -553,6 +550,9 @@ CsrSbApiRequestThread(IN PVOID Parameter)
             /* Call the API */
             if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
             {
+                DPRINT1("CSRSS: %s Session Api called and failed\n",
+                        CsrServerSbApiName[ReceiveMsg.ApiNumber]);
+
                 /* It failed, so return nothing */
                 ReplyMsg = NULL;
             }