ReactOS 0.4.15-dev-7842-g558ab78
session.c File Reference
#include "srv.h"
#include <debug.h>
Include dependency graph for session.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI CsrInitializeNtSessionList (VOID)
 
PCSR_NT_SESSION NTAPI CsrAllocateNtSession (IN ULONG SessionId)
 
VOID NTAPI CsrReferenceNtSession (IN PCSR_NT_SESSION Session)
 
VOID NTAPI CsrDereferenceNtSession (IN PCSR_NT_SESSION Session, IN NTSTATUS ExitStatus)
 
BOOLEAN NTAPI CsrSbCreateSession (IN PSB_API_MSG ApiMessage)
 
BOOLEAN NTAPI CsrSbForeignSessionComplete (IN PSB_API_MSG ApiMessage)
 
BOOLEAN NTAPI CsrSbTerminateSession (IN PSB_API_MSG ApiMessage)
 
BOOLEAN NTAPI CsrSbCreateProcess (IN PSB_API_MSG ApiMessage)
 
NTSTATUS NTAPI CsrSbApiHandleConnectionRequest (IN PSB_API_MSG Message)
 
VOID NTAPI CsrSbApiRequestThread (IN PVOID Parameter)
 

Variables

RTL_CRITICAL_SECTION CsrNtSessionLock
 
LIST_ENTRY CsrNtSessionList
 
PSB_API_ROUTINE CsrServerSbApiDispatch [SbpMaxApiNumber - SbpCreateSession]
 
PCHAR CsrServerSbApiName [SbpMaxApiNumber - SbpCreateSession]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file session.c.

Function Documentation

◆ CsrAllocateNtSession()

PCSR_NT_SESSION NTAPI CsrAllocateNtSession ( IN ULONG  SessionId)

Definition at line 77 of file session.c.

78{
79 PCSR_NT_SESSION NtSession;
80
81 /* Allocate an NT Session Object */
83 if (NtSession)
84 {
85 /* Setup the Session Object */
86 NtSession->SessionId = SessionId;
87 NtSession->ReferenceCount = 1;
88
89 /* Insert it into the Session List */
93 }
94 else
95 {
96 ASSERT(NtSession != NULL);
97 }
98
99 /* Return the Session (or NULL) */
100 return NtSession;
101}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
ULONG SessionId
Definition: dllmain.c:28
#define InsertHeadList(ListHead, Entry)
#define ASSERT(a)
Definition: mode.c:44
ULONG SessionId
Definition: csrsrv.h:33
LIST_ENTRY SessionLink
Definition: csrsrv.h:32
ULONG ReferenceCount
Definition: csrsrv.h:31
#define CsrAcquireNtSessionLock()
Definition: api.h:27
HANDLE CsrHeap
Definition: init.c:25
#define CsrReleaseNtSessionLock()
Definition: api.h:30
LIST_ENTRY CsrNtSessionList
Definition: session.c:19

Referenced by CsrSbCreateSession().

◆ CsrDereferenceNtSession()

VOID NTAPI CsrDereferenceNtSession ( IN PCSR_NT_SESSION  Session,
IN NTSTATUS  ExitStatus 
)

Definition at line 156 of file session.c.

158{
159 /* Acquire the lock */
161
162 /* Sanity checks */
163 ASSERT(!IsListEmpty(&Session->SessionLink));
164 ASSERT(Session->SessionId != 0);
165 ASSERT(Session->ReferenceCount != 0);
166
167 /* Dereference the Session Object */
168 if ((--Session->ReferenceCount) == 0)
169 {
170 /* Remove it from the list */
171 RemoveEntryList(&Session->SessionLink);
172
173 /* Release the lock */
175
176 /* Tell SM that we're done here */
177 SmSessionComplete(CsrSmApiPort, Session->SessionId, ExitStatus);
178
179 /* Free the Session Object */
180 RtlFreeHeap(CsrHeap, 0, Session);
181 }
182 else
183 {
184 /* Release the lock, the Session is still active */
186 }
187}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:867
NTSTATUS NTAPI SmSessionComplete(_In_ HANDLE SmApiPort, _In_ ULONG SessionId, _In_ NTSTATUS SessionStatus)
This function is called by an environment subsystem server to tell the SM it has terminated the sessi...
Definition: smclient.c:220
HANDLE CsrSmApiPort
Definition: init.c:31

Referenced by CsrProcessRefcountZero().

◆ CsrInitializeNtSessionList()

NTSTATUS NTAPI CsrInitializeNtSessionList ( VOID  )

Definition at line 53 of file session.c.

54{
55 /* Initialize the Session List */
57
58 /* Initialize the Session Lock */
60}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
RTL_CRITICAL_SECTION CsrNtSessionLock
Definition: session.c:18

Referenced by CsrServerInitialization().

◆ CsrReferenceNtSession()

VOID NTAPI CsrReferenceNtSession ( IN PCSR_NT_SESSION  Session)

Definition at line 118 of file session.c.

119{
120 /* Acquire the lock */
122
123 /* Sanity checks */
124 ASSERT(!IsListEmpty(&Session->SessionLink));
125 ASSERT(Session->SessionId != 0);
126 ASSERT(Session->ReferenceCount != 0);
127
128 /* Increase the reference count */
129 Session->ReferenceCount++;
130
131 /* Release the lock */
133}

Referenced by CsrCreateProcess().

◆ CsrSbApiHandleConnectionRequest()

NTSTATUS NTAPI CsrSbApiHandleConnectionRequest ( IN PSB_API_MSG  Message)

Definition at line 434 of file session.c.

435{
437 REMOTE_PORT_VIEW RemotePortView;
438 HANDLE hPort;
439
440 /* Set the Port View Structure Length */
441 RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
442
443 /* Accept the connection */
445 NULL,
446 &Message->h,
447 TRUE,
448 NULL,
449 &RemotePortView);
450 if (!NT_SUCCESS(Status))
451 {
452 DPRINT1("CSRSS: Sb Accept Connection failed %lx\n", Status);
453 return Status;
454 }
455
456 /* Complete the Connection */
458 if (!NT_SUCCESS(Status))
459 {
460 DPRINT1("CSRSS: Sb Complete Connection failed %lx\n",Status);
461 }
462
463 /* Return status */
464 return Status;
465}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtAcceptConnectPort(OUT PHANDLE PortHandle, IN PVOID PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage, IN BOOLEAN AcceptConnection, IN OUT PPORT_VIEW ServerView OPTIONAL, OUT PREMOTE_PORT_VIEW ClientView OPTIONAL)
Definition: complete.c:40
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:423
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR Message[]
Definition: register.c:74
Status
Definition: gdiplustypes.h:25
struct _REMOTE_PORT_VIEW REMOTE_PORT_VIEW

Referenced by CsrSbApiRequestThread().

◆ CsrSbApiRequestThread()

VOID NTAPI CsrSbApiRequestThread ( IN PVOID  Parameter)

Definition at line 484 of file session.c.

485{
487 SB_API_MSG ReceiveMsg;
488 PSB_API_MSG ReplyMsg = NULL;
489 PVOID PortContext;
490 ULONG MessageType;
491
492 /* Start the loop */
493 while (TRUE)
494 {
495 /* Wait for a message to come in */
497 &PortContext,
498 &ReplyMsg->h,
499 &ReceiveMsg.h);
500
501 /* Check if we didn't get success */
502 if (Status != STATUS_SUCCESS)
503 {
504 /* If we only got a warning, keep going */
505 if (NT_SUCCESS(Status)) continue;
506
507 /* We failed big time, so start out fresh */
508 ReplyMsg = NULL;
509 DPRINT1("CSRSS: ReceivePort failed - Status == %X\n", Status);
510 continue;
511 }
512
513 /* Save the message type */
514 MessageType = ReceiveMsg.h.u2.s2.Type;
515
516 /* Check if this is a connection request */
517 if (MessageType == LPC_CONNECTION_REQUEST)
518 {
519 /* Handle connection request */
521
522 /* Start over */
523 ReplyMsg = NULL;
524 continue;
525 }
526
527 /* Check if the port died */
528 if (MessageType == LPC_PORT_CLOSED)
529 {
530 /* Close the handle if we have one */
531 if (PortContext) NtClose((HANDLE)PortContext);
532
533 /* Client died, start over */
534 ReplyMsg = NULL;
535 continue;
536 }
537 else if (MessageType == LPC_CLIENT_DIED)
538 {
539 /* Client died, start over */
540 ReplyMsg = NULL;
541 continue;
542 }
543
544 /*
545 * It's an API Message, check if it's within limits. If it's not,
546 * the NT Behaviour is to set this to the Maximum API.
547 */
548 if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
549 {
550 ReceiveMsg.ApiNumber = SbpMaxApiNumber;
551 DPRINT1("CSRSS: %lx is invalid Sb ApiNumber\n", ReceiveMsg.ApiNumber);
552 }
553
554 /* Reuse the message */
555 ReplyMsg = &ReceiveMsg;
556
557 /* Make sure that the message is supported */
558 if (ReceiveMsg.ApiNumber < SbpMaxApiNumber)
559 {
560 /* Call the API */
561 if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
562 {
563 DPRINT1("CSRSS: %s Session Api called and failed\n",
564 CsrServerSbApiName[ReceiveMsg.ApiNumber]);
565
566 /* It failed, so return nothing */
567 ReplyMsg = NULL;
568 }
569 }
570 else
571 {
572 /* We don't support this API Number */
574 }
575 }
576}
#define LPC_CLIENT_DIED
Definition: port.c:98
#define LPC_CONNECTION_REQUEST
Definition: port.c:102
#define LPC_PORT_CLOSED
Definition: port.c:97
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_SUCCESS
Definition: shellext.h:65
@ SbpMaxApiNumber
Definition: smmsg.h:151
NTSTATUS ReturnValue
Definition: smmsg.h:239
SB_API_NUMBER ApiNumber
Definition: smmsg.h:238
PORT_MESSAGE h
Definition: smmsg.h:232
HANDLE CsrSbApiPort
Definition: init.c:29
NTSTATUS NTAPI CsrSbApiHandleConnectionRequest(IN PSB_API_MSG Message)
Definition: session.c:434
PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession]
Definition: session.c:21
PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession]
Definition: session.c:29
uint32_t ULONG
Definition: typedefs.h:59

Referenced by CsrSbApiPortInitialize().

◆ CsrSbCreateProcess()

BOOLEAN NTAPI CsrSbCreateProcess ( IN PSB_API_MSG  ApiMessage)

Definition at line 410 of file session.c.

411{
412 ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
413 return TRUE;
414}

◆ CsrSbCreateSession()

BOOLEAN NTAPI CsrSbCreateSession ( IN PSB_API_MSG  ApiMessage)

Definition at line 208 of file session.c.

209{
210 PSB_CREATE_SESSION_MSG CreateSession = &ApiMessage->u.CreateSession;
213 PCSR_THREAD CsrThread;
214 PCSR_SERVER_DLL ServerDll;
215 PVOID ProcessData;
217 KERNEL_USER_TIMES KernelTimes;
218 ULONG i;
219
220 /* Save the Process and Thread Handles */
221 hProcess = CreateSession->ProcessInfo.ProcessHandle;
222 hThread = CreateSession->ProcessInfo.ThreadHandle;
223
224 /* Lock the Processes */
226
227 /* Allocate a new process */
229 if (!CsrProcess)
230 {
231 /* Fail */
232 ApiMessage->ReturnValue = STATUS_NO_MEMORY;
234 return TRUE;
235 }
236
237 /* Set the Exception Port for us */
240 &CsrApiPort,
241 sizeof(CsrApiPort));
242
243 /* Check for success */
244 if (!NT_SUCCESS(Status))
245 {
246 /* Fail the request */
249
250 /* Strange as it seems, NTSTATUSes are actually returned */
252 }
253
254 /* Get the Create Time */
257 &KernelTimes,
258 sizeof(KernelTimes),
259 NULL);
260
261 /* Check for success */
262 if (!NT_SUCCESS(Status))
263 {
264 /* Fail the request */
267
268 /* Strange as it seems, NTSTATUSes are actually returned */
269 return (BOOLEAN)Status;
270 }
271
272 /* Allocate a new Thread */
273 CsrThread = CsrAllocateThread(CsrProcess);
274 if (!CsrThread)
275 {
276 /* Fail the request */
279
280 ApiMessage->ReturnValue = STATUS_NO_MEMORY;
281 return TRUE;
282 }
283
284 /* Setup the Thread Object */
285 CsrThread->CreateTime = KernelTimes.CreateTime;
286 CsrThread->ClientId = CreateSession->ProcessInfo.ClientId;
287 CsrThread->ThreadHandle = hThread;
289 CsrThread->Flags = 0;
290
291 /* Insert it into the Process List */
292 Status = CsrInsertThread(CsrProcess, CsrThread);
293 if (!NT_SUCCESS(Status))
294 {
295 /* Bail out */
297 CsrDeallocateThread(CsrThread);
299
300 /* Strange as it seems, NTSTATUSes are actually returned */
301 return (BOOLEAN)Status;
302 }
303
304 /* Setup Process Data */
305 CsrProcess->ClientId = CreateSession->ProcessInfo.ClientId;
306 CsrProcess->ProcessHandle = hProcess;
307 CsrProcess->NtSession = CsrAllocateNtSession(CreateSession->SessionId);
308
309 /* Set the Process Priority */
311
312 /* Get the first data location */
313 ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
314
315 /* Loop every DLL */
316 for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
317 {
318 /* Get the current Server */
319 ServerDll = CsrLoadedServerDll[i];
320
321 /* Check if the DLL is loaded and has Process Data */
322 if (ServerDll && ServerDll->SizeOfProcessData)
323 {
324 /* Write the pointer to the data */
325 CsrProcess->ServerData[i] = ProcessData;
326
327 /* Move to the next data location */
328 ProcessData = (PVOID)((ULONG_PTR)ProcessData +
329 ServerDll->SizeOfProcessData);
330 }
331 else
332 {
333 /* Nothing for this Process */
334 CsrProcess->ServerData[i] = NULL;
335 }
336 }
337
338 /* Insert the Process */
340
341 /* Activate the Thread */
342 ApiMessage->ReturnValue = NtResumeThread(hThread, NULL);
343
344 /* Release lock and return */
346 return TRUE;
347}
unsigned char BOOLEAN
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1107
@ ThreadTimes
Definition: compat.h:936
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ ProcessExceptionPort
Definition: winternl.h:864
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63
HANDLE hThread
Definition: wizard.c:28
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2624
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG SizeOfProcessData
Definition: csrsrv.h:234
ULONG Flags
Definition: csrsrv.h:72
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
HANDLE ThreadHandle
Definition: csrsrv.h:71
CLIENT_ID ClientId
Definition: csrsrv.h:68
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
HANDLE CsrApiPort
Definition: connect.c:27
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:189
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
VOID NTAPI CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:366
VOID NTAPI CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:297
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
#define CsrAcquireProcessLock()
Definition: api.h:12
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20
#define CsrReleaseProcessLock()
Definition: api.h:15
PCSR_NT_SESSION NTAPI CsrAllocateNtSession(IN ULONG SessionId)
Definition: session.c:77
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
PKPROCESS CsrProcess
Definition: videoprt.c:39

◆ CsrSbForeignSessionComplete()

BOOLEAN NTAPI CsrSbForeignSessionComplete ( IN PSB_API_MSG  ApiMessage)

Definition at line 365 of file session.c.

366{
367 /* Deprecated/Unimplemented in NT */
368 ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
369 return TRUE;
370}

◆ CsrSbTerminateSession()

BOOLEAN NTAPI CsrSbTerminateSession ( IN PSB_API_MSG  ApiMessage)

Definition at line 388 of file session.c.

389{
390 ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
391 return TRUE;
392}

Variable Documentation

◆ CsrNtSessionList

LIST_ENTRY CsrNtSessionList

Definition at line 19 of file session.c.

Referenced by CsrAllocateNtSession(), and CsrInitializeNtSessionList().

◆ CsrNtSessionLock

RTL_CRITICAL_SECTION CsrNtSessionLock

Definition at line 18 of file session.c.

Referenced by CsrInitializeNtSessionList().

◆ CsrServerSbApiDispatch

Initial value:
=
{
}
BOOLEAN NTAPI CsrSbTerminateSession(IN PSB_API_MSG ApiMessage)
Definition: session.c:388
BOOLEAN NTAPI CsrSbCreateProcess(IN PSB_API_MSG ApiMessage)
Definition: session.c:410
BOOLEAN NTAPI CsrSbForeignSessionComplete(IN PSB_API_MSG ApiMessage)
Definition: session.c:365
BOOLEAN NTAPI CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
Definition: session.c:208

Definition at line 21 of file session.c.

Referenced by CsrSbApiRequestThread().

◆ CsrServerSbApiName

PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession]
Initial value:
=
{
"SbCreateSession",
"SbTerminateSession",
"SbForeignSessionComplete",
"SbCreateProcess"
}

Definition at line 29 of file session.c.

Referenced by CsrSbApiRequestThread().