ReactOS  0.4.14-dev-49-gfb4591c
smsessn.c File Reference
#include "smss.h"
#include <debug.h>
Include dependency graph for smsessn.c:

Go to the source code of this file.

Classes

struct  _SMP_SESSION
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _SMP_SESSION SMP_SESSION
 
typedef struct _SMP_SESSIONPSMP_SESSION
 

Functions

BOOLEAN NTAPI SmpCheckDuplicateMuSessionId (IN ULONG MuSessionId)
 
PSMP_SESSION NTAPI SmpSessionIdToSession (IN ULONG SessionId)
 
VOID NTAPI SmpDeleteSession (IN ULONG SessionId)
 
ULONG NTAPI SmpAllocateSessionId (IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
 
NTSTATUS NTAPI SmpGetProcessMuSessionId (IN HANDLE ProcessHandle, OUT PULONG SessionId)
 
NTSTATUS NTAPI SmpSetProcessMuSessionId (IN HANDLE ProcessHandle, IN ULONG SessionId)
 

Variables

RTL_CRITICAL_SECTION SmpSessionListLock
 
LIST_ENTRY SmpSessionListHead
 
ULONG SmpNextSessionId
 
ULONG SmpNextSessionIdScanMode
 
BOOLEAN SmpDbgSsLoaded
 
HANDLE SmpSessionsObjectDirectory
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file smsessn.c.

Typedef Documentation

◆ PSMP_SESSION

◆ SMP_SESSION

Function Documentation

◆ SmpAllocateSessionId()

ULONG NTAPI SmpAllocateSessionId ( IN PSMP_SUBSYSTEM  Subsystem,
IN PSMP_SUBSYSTEM  OtherSubsystem 
)

Definition at line 123 of file smsessn.c.

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 }
#define DbgPrint
Definition: loader.c:25
PSMP_SUBSYSTEM Subsystem
Definition: smsessn.c:22
ULONG SessionId
Definition: dllmain.c:28
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define InsertTailList(ListHead, Entry)
void DbgBreakPoint()
Definition: mach.c:553
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
LIST_ENTRY SmpSessionListHead
Definition: smsessn.c:27
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
ULONG SessionId
Definition: smsessn.c:21
PSMP_SUBSYSTEM OtherSubsystem
Definition: smsessn.c:23
ULONG SmpNextSessionIdScanMode
Definition: smsessn.c:29
#define DPRINT1
Definition: precomp.h:8
ULONG SmpNextSessionId
Definition: smsessn.c:28
unsigned int ULONG
Definition: retypes.h:1
LIST_ENTRY Entry
Definition: smsessn.c:20

Referenced by SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpCheckDuplicateMuSessionId()

BOOLEAN NTAPI SmpCheckDuplicateMuSessionId ( IN ULONG  MuSessionId)

Definition at line 37 of file smsessn.c.

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 }
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
unsigned char BOOLEAN
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
ULONG MuSessionId
Definition: smss.h:67
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

Referenced by SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpDeleteSession()

VOID NTAPI SmpDeleteSession ( IN ULONG  SessionId)

Definition at line 98 of file smsessn.c.

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 }
ULONG SessionId
Definition: dllmain.c:28
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PSMP_SESSION NTAPI SmpSessionIdToSession(IN ULONG SessionId)
Definition: smsessn.c:70
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
LIST_ENTRY Entry
Definition: smsessn.c:20

Referenced by SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpGetProcessMuSessionId()

NTSTATUS NTAPI SmpGetProcessMuSessionId ( IN HANDLE  ProcessHandle,
OUT PULONG  SessionId 
)

Definition at line 168 of file smsessn.c.

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 }
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by SmpHandleConnectionRequest(), and SmpSbCreateSession().

◆ SmpSessionIdToSession()

PSMP_SESSION NTAPI SmpSessionIdToSession ( IN ULONG  SessionId)

Definition at line 70 of file smsessn.c.

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 }
ULONG SessionId
Definition: dllmain.c:28
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
LIST_ENTRY SmpSessionListHead
Definition: smsessn.c:27
ULONG SessionId
Definition: smsessn.c:21
base of all file and directory entries
Definition: entries.h:82

Referenced by SmpDeleteSession().

◆ SmpSetProcessMuSessionId()

NTSTATUS NTAPI SmpSetProcessMuSessionId ( IN HANDLE  ProcessHandle,
IN ULONG  SessionId 
)

Definition at line 199 of file smsessn.c.

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 }
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
#define DPRINT1
Definition: precomp.h:8
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by SmpExecuteImage().

Variable Documentation

◆ SmpDbgSsLoaded

BOOLEAN SmpDbgSsLoaded

Definition at line 30 of file smsessn.c.

Referenced by SmpInit(), and SmpSbCreateSession().

◆ SmpNextSessionId

ULONG SmpNextSessionId

Definition at line 28 of file smsessn.c.

Referenced by SmpAllocateSessionId(), and SmpInit().

◆ SmpNextSessionIdScanMode

ULONG SmpNextSessionIdScanMode

Definition at line 29 of file smsessn.c.

Referenced by SmpAllocateSessionId(), and SmpInit().

◆ SmpSessionListHead

LIST_ENTRY SmpSessionListHead

Definition at line 27 of file smsessn.c.

Referenced by SmpAllocateSessionId(), SmpInit(), and SmpSessionIdToSession().

◆ SmpSessionListLock

RTL_CRITICAL_SECTION SmpSessionListLock

Definition at line 26 of file smsessn.c.

Referenced by SmpAllocateSessionId(), SmpDeleteSession(), and SmpInit().

◆ SmpSessionsObjectDirectory

HANDLE SmpSessionsObjectDirectory

Definition at line 31 of file smsessn.c.

Referenced by SmpLoadDataFromRegistry().