ReactOS  0.4.14-dev-552-g2fad488
smsessn.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Windows-Compatible Session Manager
3  * LICENSE: BSD 2-Clause License
4  * FILE: base/system/smss/smsessn.c
5  * PURPOSE: Main SMSS Code
6  * PROGRAMMERS: Alex Ionescu
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "smss.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* GLOBALS ********************************************************************/
17 
18 typedef struct _SMP_SESSION
19 {
25 
32 
33 /* FUNCTIONS ******************************************************************/
34 
35 BOOLEAN
36 NTAPI
38 {
39  PSMP_SUBSYSTEM Subsystem;
40  BOOLEAN FoundDuplicate = FALSE;
41  PLIST_ENTRY NextEntry;
42 
43  /* Lock the subsystem database */
45 
46  /* Scan each entry */
47  NextEntry = SmpKnownSubSysHead.Flink;
48  while (NextEntry != &SmpKnownSubSysHead)
49  {
50  /* Check if this entry has the same session ID */
51  Subsystem = CONTAINING_RECORD(NextEntry, SMP_SUBSYSTEM, Entry);
52  if (Subsystem->MuSessionId == MuSessionId)
53  {
54  /* Break out of here! */
55  FoundDuplicate = TRUE;
56  break;
57  }
58 
59  /* Keep going */
60  NextEntry = NextEntry->Flink;
61  }
62 
63  /* Release the database and return the result */
65  return FoundDuplicate;
66 }
67 
69 NTAPI
71 {
72  PSMP_SESSION Session, FoundSession = NULL;
73  PLIST_ENTRY NextEntry;
74 
75  /* Loop the session list -- lock must already be held! */
76  NextEntry = SmpSessionListHead.Flink;
77  while (NextEntry != &SmpSessionListHead)
78  {
79  /* Check if this session's ID matches */
80  Session = CONTAINING_RECORD(NextEntry, SMP_SESSION, Entry);
81  if (Session->SessionId == SessionId)
82  {
83  /* Set this as the found session and break out */
84  FoundSession = Session;
85  break;
86  }
87 
88  /* Keep going */
89  NextEntry = NextEntry->Flink;
90  }
91 
92  /* Return the session that was found and exit */
93  return FoundSession;
94 }
95 
96 VOID
97 NTAPI
99 {
100  PSMP_SESSION Session;
101 
102  /* Enter the lock and get the session structure */
104  Session = SmpSessionIdToSession(SessionId);
105  if (Session)
106  {
107  /* Remove it from the list */
108  RemoveEntryList(&Session->Entry);
110 
111  /* Now free the structure outside of the lock */
112  RtlFreeHeap(SmpHeap, 0, Session);
113  }
114  else
115  {
116  /* ID doesn't map to one of our structures, nothing to do... */
118  }
119 }
120 
121 ULONG
122 NTAPI
124  IN PSMP_SUBSYSTEM OtherSubsystem)
125 {
127  PSMP_SESSION Session;
128 
129  /* Allocate a new ID while under the lock */
132 
133  /* Check for overflow */
135  {
136  /* Break if it happened */
137  DbgPrint("SMSS: SessionId's Wrapped\n");
138  DbgBreakPoint();
139  }
140  else
141  {
142  /* Detect it for next time */
144  }
145 
146  /* Allocate a session structure */
147  Session = RtlAllocateHeap(SmpHeap, 0, sizeof(SMP_SESSION));
148  if (Session)
149  {
150  /* Write the session data and insert it into the session list */
151  Session->Subsystem = Subsystem;
152  Session->SessionId = SessionId;
153  Session->OtherSubsystem = OtherSubsystem;
155  }
156  else
157  {
158  DPRINT1("SMSS: Unable to keep track of session ID -- no memory available\n");
159  }
160 
161  /* Release the session lock */
163  return SessionId;
164 }
165 
166 NTSTATUS
167 NTAPI
170 {
172  ULONG ProcessSession;
173 
174  /* Query the kernel for the session ID */
177  &ProcessSession,
178  sizeof(ProcessSession),
179  NULL);
180  if (NT_SUCCESS(Status))
181  {
182  /* Copy it back into the buffer */
183  *SessionId = ProcessSession;
184  }
185  else
186  {
187  /* Failure -- assume session zero */
188  DPRINT1("SMSS: GetProcessMuSessionId, Process=%p, Status=%x\n",
190  *SessionId = 0;
191  }
192 
193  /* Return result */
194  return Status;
195 }
196 
197 NTSTATUS
198 NTAPI
201 {
203 
204  /* Tell the kernel about the session ID */
207  &SessionId,
208  sizeof(SessionId));
209  if (!NT_SUCCESS(Status))
210  {
211  DPRINT1("SMSS: SetProcessMuSessionId, Process=%p, Status=%x\n",
213  }
214 
215  /* Return */
216  return Status;
217 }
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
Definition: smsessn.c:37
ULONG NTAPI SmpAllocateSessionId(IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
Definition: smsessn.c:123
#define DbgPrint
Definition: loader.c:25
PSMP_SUBSYSTEM Subsystem
Definition: smsessn.c:22
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
VOID NTAPI SmpDeleteSession(IN ULONG SessionId)
Definition: smsessn.c:98
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define InsertTailList(ListHead, Entry)
void DbgBreakPoint()
Definition: mach.c:553
NTSTATUS NTAPI SmpSetProcessMuSessionId(IN HANDLE ProcessHandle, IN ULONG SessionId)
Definition: smsessn.c:199
NTSTATUS NTAPI SmpGetProcessMuSessionId(IN HANDLE ProcessHandle, OUT PULONG SessionId)
Definition: smsessn.c:168
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PSMP_SESSION NTAPI SmpSessionIdToSession(IN ULONG SessionId)
Definition: smsessn.c:70
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: typedefs.h:117
LIST_ENTRY SmpSessionListHead
Definition: smsessn.c:27
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
Status
Definition: gdiplustypes.h:24
ULONG SessionId
Definition: smsessn.c:21
ULONG MuSessionId
Definition: smss.h:67
BOOLEAN SmpDbgSsLoaded
Definition: smsessn.c:30
struct _SMP_SESSION SMP_SESSION
PSMP_SUBSYSTEM OtherSubsystem
Definition: smsessn.c:23
HANDLE SmpSessionsObjectDirectory
Definition: smsessn.c:31
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
ULONG SmpNextSessionIdScanMode
Definition: smsessn.c:29
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
ULONG SmpNextSessionId
Definition: smsessn.c:28
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
struct _SMP_SESSION * PSMP_SESSION
LIST_ENTRY Entry
Definition: smsessn.c:20
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
base of all file and directory entries
Definition: entries.h:82
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19