Some preliminary work on the SM to make it manage environment servers.
authorEmanuele Aliberti <ea@iol.it>
Sun, 6 Feb 2005 21:55:07 +0000 (21:55 +0000)
committerEmanuele Aliberti <ea@iol.it>
Sun, 6 Feb 2005 21:55:07 +0000 (21:55 +0000)
svn path=/trunk/; revision=13449

reactos/subsys/smss/client.c [new file with mode: 0644]
reactos/subsys/smss/debug.c [new file with mode: 0644]
reactos/subsys/smss/init.c
reactos/subsys/smss/makefile
reactos/subsys/smss/smapi.c
reactos/subsys/smss/smss.c
reactos/subsys/smss/smss.h

diff --git a/reactos/subsys/smss/client.c b/reactos/subsys/smss/client.c
new file mode 100644 (file)
index 0000000..def3407
--- /dev/null
@@ -0,0 +1,116 @@
+/* $Id: smss.c 12852 2005-01-06 13:58:04Z mf $\r
+ *\r
+ * client.c - Session Manager client Management\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+#define NTOS_MODE_USER\r
+#include <ntos.h>\r
+#include <sm/api.h>\r
+#include "smss.h"\r
+\r
+/* Private ADT */\r
+\r
+typedef struct _SM_CLIENT_DATA\r
+{\r
+       USHORT  SubsystemId;\r
+       BOOL    Initialized;\r
+       HANDLE  ServerProcess;\r
+       HANDLE  ApiPort;\r
+       HANDLE  SbApiPort;\r
+       struct _SM_CLIENT_DATA * Next;\r
+       \r
+} SM_CLIENT_DATA, *PSM_CLIENT_DATA;\r
+\r
+\r
+struct _SM_CLIENT_DIRECTORY\r
+{\r
+       RTL_CRITICAL_SECTION  Lock;\r
+       ULONG                 Count;\r
+       PSM_CLIENT_DATA       Client;\r
+\r
+} SmpClientDirectory;\r
+\r
+/**********************************************************************\r
+ *     SmpInitializeClientManagement/0\r
+ */\r
+VOID STDCALL\r
+SmpInitializeClientManagement (VOID)\r
+{\r
+       RtlInitializeCriticalSection(& SmpClientDirectory.Lock);\r
+       SmpClientDirectory.Count = 0;\r
+       SmpClientDirectory.Client = NULL;\r
+}\r
+\r
+/**********************************************************************\r
+ *     SmpCreateClient/1\r
+ */\r
+NTSTATUS STDCALL\r
+SmpCreateClient(SM_PORT_MESSAGE Request)\r
+{\r
+       PSM_CLIENT_DATA pClient = NULL;\r
+\r
+       /*\r
+        * Allocate the storage for client data\r
+        */\r
+       pClient = RtlAllocateHeap (SmpHeap,\r
+                                  HEAP_ZERO_MEMORY,\r
+                                  sizeof (SM_CLIENT_DATA));\r
+       if (NULL == pClient) return STATUS_NO_MEMORY;\r
+       /*\r
+        * Initialize the client data\r
+        */\r
+       // TODO\r
+       /*\r
+        * Insert the new descriptor in the\r
+        * client directory.\r
+        */\r
+       RtlEnterCriticalSection (& SmpClientDirectory.Lock);\r
+       if (NULL == SmpClientDirectory.Client)\r
+       {\r
+               SmpClientDirectory.Client = pClient;\r
+       } else {\r
+               PSM_CLIENT_DATA pCD = NULL;\r
+\r
+               for (pCD=SmpClientDirectory.Client;\r
+                       (NULL != pCD->Next);\r
+                       pCD = pCD->Next);\r
+               pCD->Next = pClient;\r
+       }\r
+       ++ SmpClientDirectory.Count;\r
+       RtlLeaveCriticalSection (& SmpClientDirectory.Lock);\r
+       return STATUS_SUCCESS;\r
+}\r
+\r
+/**********************************************************************\r
+ *     SmpDestroyClient/1\r
+ */\r
+NTSTATUS STDCALL\r
+SmpDestroyClient (ULONG SubsystemId)\r
+{\r
+       RtlEnterCriticalSection (& SmpClientDirectory.Lock);\r
+       /* TODO */\r
+       RtlLeaveCriticalSection (& SmpClientDirectory.Lock);\r
+       return STATUS_SUCCESS;\r
+}\r
+\r
+/* EOF */\r
diff --git a/reactos/subsys/smss/debug.c b/reactos/subsys/smss/debug.c
new file mode 100644 (file)
index 0000000..e199361
--- /dev/null
@@ -0,0 +1,92 @@
+/* $Id: smss.c 12852 2005-01-06 13:58:04Z mf $\r
+ *\r
+ * client.c - Session Manager client Management\r
+ * \r
+ * ReactOS Operating System\r
+ * \r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING.LIB. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA.  \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+#define NTOS_MODE_USER\r
+#include <ntos.h>\r
+#include <rosrtl/string.h>\r
+#include <sm/api.h>\r
+#include "smss.h"\r
+\r
+/* GLOBALS ***********************************************************/\r
+\r
+HANDLE DbgSsApiPort = INVALID_HANDLE_VALUE;\r
+HANDLE DbgUiApiPort = INVALID_HANDLE_VALUE;\r
+\r
+/* FUNCTIONS *********************************************************/\r
+\r
+NTSTATUS STDCALL\r
+SmpInitializeDbgSs (VOID)\r
+{\r
+  NTSTATUS Status;\r
+  UNICODE_STRING UnicodeString;\r
+  OBJECT_ATTRIBUTES ObjectAttributes;\r
+\r
+\r
+  /* Create the \DbgSsApiPort object (LPC) */\r
+  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,\r
+                      L"\\DbgSsApiPort");\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &UnicodeString,\r
+                            PORT_ALL_ACCESS,\r
+                            NULL,\r
+                            NULL);\r
+\r
+  Status = NtCreatePort(&DbgSsApiPort,\r
+                       &ObjectAttributes,\r
+                       0,\r
+                       0,\r
+                       0);\r
+\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      return(Status);\r
+    }\r
+  DbgPrint("SMSS: %s: \\DbgSsApiPort created\n",__FUNCTION__);\r
+\r
+  /* Create the \DbgUiApiPort object (LPC) */\r
+  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,\r
+                      L"\\DbgUiApiPort");\r
+  InitializeObjectAttributes(&ObjectAttributes,\r
+                            &UnicodeString,\r
+                            PORT_ALL_ACCESS,\r
+                            NULL,\r
+                            NULL);\r
+\r
+  Status = NtCreatePort(&DbgUiApiPort,\r
+                       &ObjectAttributes,\r
+                       0,\r
+                       0,\r
+                       0);\r
+  if (!NT_SUCCESS(Status))\r
+    {\r
+      return(Status);\r
+    }\r
+  DbgPrint("SMSS: %s: \\DbgUiApiPort created\n",__FUNCTION__);\r
+\r
+  return STATUS_SUCCESS;\r
+}\r
+\r
+/* EOF */\r
+\r
index a71ae79..83ce1e2 100644 (file)
@@ -33,7 +33,7 @@
 #include <ntdll/rtl.h>
 #include <ntdll/ldr.h>
 #include <rosrtl/string.h>
-
+#include <sm/api.h>
 #include "smss.h"
 
 #define NDEBUG
@@ -41,8 +41,7 @@
 
 /* GLOBALS ******************************************************************/
 
-HANDLE DbgSsApiPort = INVALID_HANDLE_VALUE;
-HANDLE DbgUiApiPort = INVALID_HANDLE_VALUE;
+HANDLE SmpHeap = NULL;
 
 PWSTR SmSystemEnvironment = NULL;
 
@@ -824,6 +823,20 @@ InitSessionManager(HANDLE Children[])
   HANDLE CsrssInitEvent;
   WCHAR UnicodeBuffer[MAX_PATH];
 
+  /* Create our own heap */
+  SmpHeap = RtlCreateHeap(HEAP_GROWABLE,
+                          NULL,
+                          65536,
+                          65536,
+                          NULL,
+                          NULL);
+  if (NULL == SmpHeap)
+    {
+      DbgPrint("SMSS: %s: failed to create private heap, aborting\n",__FUNCTION__);
+      return STATUS_UNSUCCESSFUL;
+    }
+
+
   /* Create object directories */
   Status = SmCreateObjectDirectories();
   if (!NT_SUCCESS(Status))
@@ -832,8 +845,8 @@ InitSessionManager(HANDLE Children[])
       return(Status);
     }
 
-  /* Create the SmApiPort object (LPC) */
-  Status = SmCreateApiPort();
+  /* Create the \SmApiPort object (LPC) */
+  Status = SmpCreateApiPort();
   if (!NT_SUCCESS(Status))
     {
       DPRINT1("SM: Failed to create SmApiPort (Status %lx)\n", Status);
@@ -916,6 +929,13 @@ InitSessionManager(HANDLE Children[])
     }
 #endif
 
+  /*
+   * Initialize SM client management:
+   * this MUST be done before any
+   * subsystem server is run.
+   */
+  SmpInitializeClientManagement();
+
   DPRINT("SM: loading subsystems\n");
 
   /* Load the subsystems */
@@ -1043,50 +1063,15 @@ InitSessionManager(HANDLE Children[])
     }
   Children[CHILD_WINLOGON] = ProcessInfo.ProcessHandle;
 
-  /* Create the \DbgSsApiPort object (LPC) */
-  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
-                      L"\\DbgSsApiPort");
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &UnicodeString,
-                            PORT_ALL_ACCESS,
-                            NULL,
-                            NULL);
-
-  Status = NtCreatePort(&DbgSsApiPort,
-                       &ObjectAttributes,
-                       0,
-                       0,
-                       0);
-
+  /* Initialize the DBGSS */
+  Status = SmpInitializeDbgSs();
   if (!NT_SUCCESS(Status))
     {
+      DisplayString(L"SM: DbgSs initialization failed!\n");
+      NtTerminateProcess(Children[CHILD_WINLOGON],0);
+      NtTerminateProcess(Children[CHILD_CSRSS],0);
       return(Status);
     }
-#ifndef NDEBUG
-  DisplayString(L"SM: DbgSsApiPort created...\n");
-#endif
-
-  /* Create the \DbgUiApiPort object (LPC) */
-  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
-                      L"\\DbgUiApiPort");
-  InitializeObjectAttributes(&ObjectAttributes,
-                            &UnicodeString,
-                            PORT_ALL_ACCESS,
-                            NULL,
-                            NULL);
-
-  Status = NtCreatePort(&DbgUiApiPort,
-                       &ObjectAttributes,
-                       0,
-                       0,
-                       0);
-  if (!NT_SUCCESS(Status))
-    {
-      return(Status);
-    }
-#ifndef NDEBUG
-  DisplayString (L"SM: DbgUiApiPort created...\n");
-#endif
 
   return(STATUS_SUCCESS);
 }
index ad4bd92..92ecef1 100644 (file)
@@ -15,7 +15,7 @@ TARGET_CFLAGS = -D__NTAPP__
 # require os code to explicitly request A/W version of structs/functions
 TARGET_CFLAGS += -D_DISABLE_TIDENTS -Wall -Werror
 
-TARGET_OBJECTS = $(TARGET_NAME).o init.o smapi.o
+TARGET_OBJECTS = $(TARGET_NAME).o init.o smapi.o client.o debug.o
 
 include $(PATH_TO_TOP)/rules.mak
 
index 3a2f468..0abb4a7 100644 (file)
@@ -5,10 +5,12 @@
  *
  */
 
-#include <ddk/ntddk.h>
-#include <ntdll/rtl.h>
+/*#include <ddk/ntddk.h>
+#include <ntdll/rtl.h>*/
+#define NTOS_MODE_USER
+#include <ntos.h>
+#include <sm/api.h>
 #include <rosrtl/string.h>
-
 #include "smss.h"
 
 #define NDEBUG
 
 static HANDLE SmApiPort = INVALID_HANDLE_VALUE;
 
-/* FUNCTIONS ****************************************************************/
+/* SM API **********************************************************************/
+
+#define SMAPI(n) \
+NTSTATUS FASTCALL n (PSM_PORT_MESSAGE Request)
+
+SMAPI(SmInvalid)
+{
+       DbgPrint("SMSS: %s called\n",__FUNCTION__);
+       Request->Status = STATUS_NOT_IMPLEMENTED;
+       return STATUS_SUCCESS;
+}
+
+SMAPI(SmCompSes)
+{
+       DbgPrint("SMSS: %s called\n",__FUNCTION__);
+       Request->Status = STATUS_NOT_IMPLEMENTED;
+       return STATUS_SUCCESS;
+}
+SMAPI(SmExecPgm)
+{
+       DbgPrint("SMSS: %s called\n",__FUNCTION__);
+       Request->Status = STATUS_NOT_IMPLEMENTED;
+       return STATUS_SUCCESS;
+}
+
+/* SM API Table */
+typedef NTSTATUS (FASTCALL * SM_PORT_API)(PSM_PORT_MESSAGE);
+
+SM_PORT_API SmApi [] =
+{
+       SmInvalid,      /* unused */
+       SmCompSes,
+       SmInvalid,      /* obsolete */
+       SmInvalid,      /* unknown */
+       SmExecPgm
+};
+
 
+/**********************************************************************
+ * NAME
+ *     SmpHandleConnectionRequest/2
+ *
+ * REMARKS
+ *     Quoted in http://support.microsoft.com/kb/258060/EN-US/
+ */
+NTSTATUS STDCALL
+SmpHandleConnectionRequest (HANDLE Port, PSM_PORT_MESSAGE Request)
+{
+       DbgPrint("SMSS: %s called\n",__FUNCTION__);
+       return STATUS_SUCCESS;
+}
 
+/**********************************************************************
+ * NAME
+ *     SmpApiThread/1
+ *
+ * DESCRIPTION
+ *     Entry point for the listener thread of LPC port "\SmApiPort".
+ */
 VOID STDCALL
-SmApiThread(HANDLE Port)
+SmpApiThread(HANDLE Port)
 {
-  NTSTATUS Status;
-  ULONG Unknown;
-  PLPC_MESSAGE Reply = NULL;
-  LPC_MESSAGE Message;
+       NTSTATUS        Status = STATUS_SUCCESS;
+       ULONG           Unknown = 0;
+       PLPC_MESSAGE    Reply = NULL;
+       SM_PORT_MESSAGE Request = {{0}};
 
-#ifndef NDEBUG
-  DisplayString(L"SmApiThread: running\n");
-#endif
+       DbgPrint("SMSS: %s running.\n",__FUNCTION__);
 
-  while (TRUE)
-    {
-#ifndef NDEBUG
-      DisplayString(L"SmApiThread: waiting for message\n");
-#endif
-
-      Status = NtReplyWaitReceivePort(Port,
-                                     &Unknown,
-                                     Reply,
-                                     &Message);
-      if (NT_SUCCESS(Status))
+       while (TRUE)
        {
-#ifndef NDEBUG
-         DisplayString(L"SmApiThread: message received\n");
-#endif
-
-         if (Message.MessageType == LPC_CONNECTION_REQUEST)
-           {
-//           SmHandleConnectionRequest (Port, &Message);
-             Reply = NULL;
-           }
-         else if (Message.MessageType == LPC_DEBUG_EVENT)
-           {
-//           DbgSsHandleKmApiMsg (&Message, 0);
-             Reply = NULL;
-           }
-         else if (Message.MessageType == LPC_PORT_CLOSED)
-           {
-             Reply = NULL;
-           }
-         else
-           {
-//           Reply = &Message;
-           }
+               DbgPrint("SMSS: %s: waiting for message\n",__FUNCTION__);
+
+               Status = NtReplyWaitReceivePort(Port,
+                                               & Unknown,
+                                               Reply,
+                                               (PLPC_MESSAGE) & Request);
+               if (NT_SUCCESS(Status))
+               {
+                       DbgPrint("SMSS: %s: message received\n",__FUNCTION__);
+
+                       switch (Request.Header.MessageType)
+                       {
+                       case LPC_CONNECTION_REQUEST:
+                               SmpHandleConnectionRequest (Port, &Request);
+                               Reply = NULL;
+                               break;
+                       case LPC_DEBUG_EVENT:
+//                             DbgSsHandleKmApiMsg (&Request, 0);
+                               Reply = NULL;
+                               break;
+                       case LPC_PORT_CLOSED:
+                             Reply = NULL;
+                             break;
+                       default:
+                               if ((Request.ApiIndex) &&
+                                       (Request.ApiIndex < (sizeof SmApi / sizeof SmApi[0])))
+                               {
+                                       Status = SmApi[Request.ApiIndex](&Request);
+                                       Reply = (PLPC_MESSAGE) & Request;
+                               } else {
+                                       Request.Status = STATUS_NOT_IMPLEMENTED;
+                                       Reply = (PLPC_MESSAGE) & Request;
+                               }
+                       }
+               }
        }
-    }
 }
 
-
+/**********************************************************************
+ * NAME
+ *     SmpCreateApiPort/0
+ *
+ * DECRIPTION
+ */
 NTSTATUS
-SmCreateApiPort(VOID)
+SmpCreateApiPort(VOID)
 {
   OBJECT_ATTRIBUTES ObjectAttributes;
   UNICODE_STRING UnicodeString;
@@ -103,7 +166,7 @@ SmCreateApiPort(VOID)
                      0,
                      NULL,
                      NULL,
-                     (PTHREAD_START_ROUTINE)SmApiThread,
+                     (PTHREAD_START_ROUTINE)SmpApiThread,
                      (PVOID)SmApiPort,
                      NULL,
                      NULL);
@@ -114,7 +177,7 @@ SmCreateApiPort(VOID)
                      0,
                      NULL,
                      NULL,
-                     (PTHREAD_START_ROUTINE)SmApiThread,
+                     (PTHREAD_START_ROUTINE)SmpApiThread,
                      (PVOID)SmApiPort,
                      NULL,
                      NULL);
index 42673e7..c51b662 100644 (file)
@@ -27,7 +27,7 @@
  *             Compiled successfully with egcs 1.1.2
  */
 #include <ddk/ntddk.h>
-
+#include <sm/api.h>
 #include "smss.h"
 
 #define NDEBUG
index 295f1a3..79b730a 100644 (file)
@@ -1,4 +1,3 @@
-
 #ifndef _SMSS_H_INCLUDED_
 #define _SMSS_H_INCLUDED_
 
@@ -15,6 +14,9 @@
 /* FUNCTIONS ***********/
 
 /* init.c */
+
+extern HANDLE SmpHeap;
+
 NTSTATUS
 InitSessionManager(HANDLE Children[]);
 
@@ -23,16 +25,32 @@ InitSessionManager(HANDLE Children[]);
 void DisplayString (LPCWSTR lpwString);
 void PrintString (char* fmt,...);
 
-
 /* smapi.c */
 
 NTSTATUS
-SmCreateApiPort(VOID);
+SmpCreateApiPort(VOID);
+
+VOID STDCALL
+SmpApiThread(HANDLE Port);
+
+/* client.c */
 
 VOID STDCALL
-SmApiThread(HANDLE Port);
+SmpInitializeClientManagement(VOID);
+
+NTSTATUS STDCALL
+SmpCreateClient(SM_PORT_MESSAGE);
+
+NTSTATUS STDCALL
+SmpDestroyClient(ULONG);
+
+/* debug.c */
 
+extern HANDLE DbgSsApiPort;
+extern HANDLE DbgUiApiPort;
 
+NTSTATUS STDCALL
+SmpInitializeDbgSs(VOID);
 
 #endif /* _SMSS_H_INCLUDED_ */