Author: ion
Date: Wed Feb  8 22:05:53 2012
New Revision: 55501

URL: http://svn.reactos.org/svn/reactos?rev=55501&view=rev
Log:
[SMSS2]: Implement (not yet used) Session Management APIs.

Modified:
    trunk/reactos/base/system/smss2/smsessn.c

Modified: trunk/reactos/base/system/smss2/smsessn.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/smss2/smsessn.c?rev=55501&r1=55500&r2=55501&view=diff
==============================================================================
--- trunk/reactos/base/system/smss2/smsessn.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/smss2/smsessn.c [iso-8859-1] Wed Feb  8 22:05:53 
2012
@@ -14,6 +14,14 @@
 
 /* GLOBALS 
********************************************************************/
 
+typedef struct _SMP_SESSION
+{
+    LIST_ENTRY Entry;
+    ULONG SessionId;
+    PSMP_SUBSYSTEM Subsystem;
+    PSMP_SUBSYSTEM OtherSubsystem;
+} SMP_SESSION, *PSMP_SESSION;
+
 RTL_CRITICAL_SECTION SmpSessionListLock;
 LIST_ENTRY SmpSessionListHead;
 ULONG SmpNextSessionId;
@@ -22,6 +30,137 @@
 HANDLE SmpSessionsObjectDirectory;
 
 /* FUNCTIONS 
******************************************************************/
+
+BOOLEAN
+NTAPI
+SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
+{
+    PSMP_SUBSYSTEM Subsystem;
+    BOOLEAN FoundDuplicate = FALSE;
+    PLIST_ENTRY NextEntry;
+
+    /* Lock the subsystem database */
+    RtlEnterCriticalSection(&SmpKnownSubSysLock);
+
+    /* Scan each entry */
+    NextEntry = SmpKnownSubSysHead.Flink;
+    while (NextEntry != &SmpKnownSubSysHead)
+    {
+        /* Check if this entry has the same session ID */
+        Subsystem = CONTAINING_RECORD(NextEntry, SMP_SUBSYSTEM, Entry);
+        if (Subsystem->MuSessionId == MuSessionId)
+        {
+            /* Break out of here! */
+            FoundDuplicate = TRUE;
+            break;
+        }
+        
+        /* Keep going */
+        NextEntry = NextEntry->Flink;
+    }
+
+    /* Release the database and return the result */
+    RtlLeaveCriticalSection(&SmpKnownSubSysLock);
+    return FoundDuplicate;
+}
+
+PSMP_SESSION
+NTAPI
+SmpSessionIdToSession(IN ULONG SessionId)
+{
+    PSMP_SESSION Session, FoundSession = NULL;
+    PLIST_ENTRY NextEntry;
+
+    /* Loop the session list -- lock must already be held! */
+    NextEntry = SmpSessionListHead.Flink;
+    while (NextEntry != &SmpSessionListHead)
+    {
+        /* Check if this session's ID matches */
+        Session = CONTAINING_RECORD(NextEntry, SMP_SESSION, Entry);
+        if (Session->SessionId == SessionId)
+        {
+            /* Set this as the found session and break out */
+            FoundSession = Session;
+            break;
+        }
+
+        /* Keep going */
+        NextEntry = NextEntry->Flink;
+    }
+
+    /* Return the session that was found and exit */
+    return FoundSession;
+}
+
+VOID
+NTAPI
+SmpDeleteSession(IN ULONG SessionId)
+{
+    PSMP_SESSION Session;
+
+    /* Enter the lock and get the session structure */
+    RtlEnterCriticalSection(&SmpSessionListLock);
+    Session = SmpSessionIdToSession(SessionId);
+    if (Session)
+    {
+        /* Remove it from the list */
+        RemoveEntryList(&Session->Entry);
+        RtlLeaveCriticalSection(&SmpSessionListLock);
+
+        /* Now free the structure outside of the lock */
+        RtlFreeHeap(SmpHeap, 0, Session);
+    }
+    else
+    {
+        /* ID doesn't map to one of our structures, nothing to do... */
+        RtlLeaveCriticalSection(&SmpSessionListLock);
+    }
+}
+
+ULONG
+NTAPI
+SmpAllocateSessionId(IN PSMP_SUBSYSTEM Subsystem,
+                     IN PSMP_SUBSYSTEM OtherSubsystem)
+{
+    ULONG SessionId;
+    PSMP_SESSION Session;
+
+    /* Allocate a new ID while under the lock */
+    RtlEnterCriticalSection(&SmpSessionListLock);
+    SessionId = SmpNextSessionId++;
+
+    /* Check for overflow */
+    if (SmpNextSessionIdScanMode)
+    {
+        /* Break if it happened */
+        DbgPrint("SMSS: SessionId's Wrapped\n");
+        DbgBreakPoint();
+    }
+    else
+    {
+        /* Detect it for next time */
+        if (!SmpNextSessionId) SmpNextSessionIdScanMode = 1;
+    }
+
+    /* Allocate a session structure */
+    Session = RtlAllocateHeap(SmpHeap, 0, sizeof(SMP_SESSION));
+    if (Session)
+    {
+        /* Write the session data and insert it into the session list */
+        Session->Subsystem = Subsystem;
+        Session->SessionId = SessionId;
+        Session->OtherSubsystem = OtherSubsystem;
+        InsertTailList(&SmpSessionListHead, &Session->Entry);
+    }
+    else
+    {
+        DPRINT1("SMSS: Unable to keep track of session ID -- no memory 
available\n");
+    }
+
+    /* Release the session lock */
+    RtlLeaveCriticalSection(&SmpSessionListLock);
+    return SessionId;
+}
 
 NTSTATUS
 NTAPI
@@ -49,7 +188,7 @@
                 ProcessHandle, Status);
         *SessionId = 0;
     }
-    
+
     /* Return result */
     return Status;
 }


Reply via email to