/*
* 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
NTAPI
CsrInitializeNtSessionList(VOID)
{
- DPRINT("CSRSRV: %s called\n", __FUNCTION__);
-
/* Initialize the Session List */
InitializeListHead(&CsrNtSessionList);
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 */
ASSERT(Session->ReferenceCount != 0);
/* Dereference the Session Object */
- if (!(--Session->ReferenceCount))
+ if ((--Session->ReferenceCount) == 0)
{
/* Remove it from the list */
RemoveEntryList(&Session->SessionLink);
}
}
-/* SESSION MANAGER FUNCTIONS**************************************************/
+/* SESSION MANAGER FUNCTIONS **************************************************/
/*++
* @name CsrSbCreateSession
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;
/* 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
{
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);
return TRUE;
}
-PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
-{
- CsrSbCreateSession,
- CsrSbTerminateSession,
- CsrSbForeignSessionComplete,
- CsrSbCreateProcess,
- NULL
-};
-
/*++
* @name CsrSbApiHandleConnectionRequest
*
}
/*
- * 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;
/* 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;
}