ReactOS 0.4.15-dev-7961-gdcf9eb0
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
18typedef struct _SMP_SESSION
19{
25
32
33/* FUNCTIONS ******************************************************************/
34
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
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
96VOID
99{
100 PSMP_SESSION Session;
101
102 /* Enter the lock and get the session structure */
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
121ULONG
122NTAPI
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 UNIMPLEMENTED_DBGBREAK("SMSS: SessionId's Wrapped\n");
138 }
139 else
140 {
141 /* Detect it for next time */
142 if (!SmpNextSessionId)
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
167NTAPI
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
198NTAPI
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}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG SessionId
Definition: dllmain.c:28
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
Status
Definition: gdiplustypes.h:25
@ ProcessSessionInformation
Definition: winternl.h:880
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
PVOID SmpHeap
Definition: sminit.c:25
NTSTATUS NTAPI SmpGetProcessMuSessionId(IN HANDLE ProcessHandle, OUT PULONG SessionId)
Definition: smsessn.c:168
LIST_ENTRY SmpSessionListHead
Definition: smsessn.c:27
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
Definition: smsessn.c:37
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
BOOLEAN SmpNextSessionIdScanMode
Definition: smsessn.c:29
NTSTATUS NTAPI SmpSetProcessMuSessionId(IN HANDLE ProcessHandle, IN ULONG SessionId)
Definition: smsessn.c:199
ULONG NTAPI SmpAllocateSessionId(IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
Definition: smsessn.c:123
struct _SMP_SESSION SMP_SESSION
VOID NTAPI SmpDeleteSession(IN ULONG SessionId)
Definition: smsessn.c:98
HANDLE SmpSessionsObjectDirectory
Definition: smsessn.c:31
BOOLEAN SmpDbgSsLoaded
Definition: smsessn.c:30
struct _SMP_SESSION * PSMP_SESSION
PSMP_SESSION NTAPI SmpSessionIdToSession(IN ULONG SessionId)
Definition: smsessn.c:70
ULONG SmpNextSessionId
Definition: smsessn.c:28
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PSMP_SUBSYSTEM Subsystem
Definition: smsessn.c:22
LIST_ENTRY Entry
Definition: smsessn.c:20
PSMP_SUBSYSTEM OtherSubsystem
Definition: smsessn.c:23
ULONG SessionId
Definition: smsessn.c:21
ULONG MuSessionId
Definition: smss.h:72
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40