CSRSS: register CSRSS to manage IMAGE_SUBSYSTEM_WINDOWS_CUI (experimental).
Modified: trunk/reactos/subsys/csrss/api/wapi.c
Modified: trunk/reactos/subsys/csrss/init.c
Deleted: trunk/reactos/subsys/csrss/lpcstub.c
Modified: trunk/reactos/subsys/csrss/makefile

Modified: trunk/reactos/subsys/csrss/api/wapi.c
--- trunk/reactos/subsys/csrss/api/wapi.c	2005-02-19 22:30:27 UTC (rev 13652)
+++ trunk/reactos/subsys/csrss/api/wapi.c	2005-02-19 22:56:59 UTC (rev 13653)
@@ -178,7 +178,7 @@
 	Status = NtAcceptConnectPort(&ServerPort,
 				     PortHandle,
 				     NULL,
-				     1,
+				     TRUE,
 				     0,
 				     &LpcRead);
 	if (!NT_SUCCESS(Status))

Modified: trunk/reactos/subsys/csrss/init.c
--- trunk/reactos/subsys/csrss/init.c	2005-02-19 22:30:27 UTC (rev 13652)
+++ trunk/reactos/subsys/csrss/init.c	2005-02-19 22:56:59 UTC (rev 13653)
@@ -17,11 +17,12 @@
 #include <ntdll/ldr.h>
 #include <win32k/win32k.h>
 #include <rosrtl/string.h>
+#include <sm/helper.h>
 
 #include "api.h"
 #include "csrplugin.h"
 
-#define NDEBUG
+//#define NDEBUG
 #include <debug.h>
 
 /* GLOBALS ******************************************************************/
@@ -218,7 +219,38 @@
     { 0, 0, 0, NULL }
   };
 
+/**********************************************************************
+ * NAME
+ * 	CsrpRegisterSubsystem/0
+ *
+ * DESCRIPTION
+ * 	Register CSRSS in the SM to manage IMAGE_SUBSYSTEM_WINDOWS_CUI 
+ * 	processes (environment subsystem server).
+ *
+ * RETURN VALUE
+ * 	STATUS_SUCCESS on success.
+ */
+static NTSTATUS FASTCALL
+CsrpRegisterSubsystem(PHANDLE hSmApiPort)
+{
+	NTSTATUS Status = STATUS_SUCCESS;
+	UNICODE_STRING SbApiPortName;
 
+	RtlInitUnicodeString (& SbApiPortName, L"\\Windows\\SbApiPort");
+	Status = SmConnectApiPort (& SbApiPortName,
+				   (HANDLE)-1, //unused
+				   IMAGE_SUBSYSTEM_WINDOWS_CUI,
+				   hSmApiPort);
+	if(!NT_SUCCESS(Status))
+	{
+		DPRINT("CSR: unable to connect to the SM (Status=0x%lx)\n", Status);
+		return Status;
+	}
+	DisplayString(L"CSR: registered with SM\n");
+	return Status;	
+}
+
+
 /**********************************************************************
  * NAME
  * 	CsrServerInitialization
@@ -238,10 +270,21 @@
 	)
 {
   NTSTATUS Status;
+  HANDLE hSmApiPort = (HANDLE) 0;
   OBJECT_ATTRIBUTES ObAttributes;
   UNICODE_STRING PortName;
   HANDLE ApiPortHandle;
+//  HANDLE hSbApiPort = (HANDLE) 0;
 
+DisplayString(L"CSR: CsrServerInitialization\n");
+
+  Status = CsrpRegisterSubsystem(& hSmApiPort);
+  if (! NT_SUCCESS(Status))
+    {
+      DPRINT1("CSR: Unable to register subsystem (Status: %x)\n", Status);
+      return FALSE;
+    }
+
   Status = CsrParseCommandLine (ArgumentCount, ArgumentArray);
   if (! NT_SUCCESS(Status))
     {
@@ -269,7 +312,7 @@
       return Status;
     }
 
-  /* NEW NAMED PORT: \ApiPort */
+  /* NEW NAMED PORT: \Windows\ApiPort */
   RtlRosInitUnicodeStringFromLiteral(&PortName, L"\\Windows\\ApiPort");
   InitializeObjectAttributes(&ObAttributes,
                              &PortName,
@@ -283,7 +326,7 @@
                         0);
   if (! NT_SUCCESS(Status))
     {
-      DPRINT1("CSR: Unable to create \\ApiPort (Status %x)\n", Status);
+      DPRINT1("CSR: Unable to create \\Windows\\ApiPort (Status %x)\n", Status);
       return FALSE;
     }
   Status = RtlCreateUserThread(NtCurrentProcess(),
@@ -302,6 +345,9 @@
       NtClose(ApiPortHandle);
       return FALSE;
     }
+
+  /* TODO: create \Windows\SbApiPort */
+  
   Status = CsrClientConnectToServer();
   if (!NT_SUCCESS(Status))
     {
@@ -315,7 +361,15 @@
       return FALSE;
     }
 
-  return CallInitComplete();
+  if (CallInitComplete())
+  {
+#if 0
+	  Status = SmCompleteSession (hSmApiPort,hSbApiPort,ApiPortHandle);
+#endif
+	  NtClose (hSmApiPort);
+	  return TRUE;
+  }
+  return FALSE;
 }
 
 /* EOF */

Deleted: trunk/reactos/subsys/csrss/lpcstub.c
--- trunk/reactos/subsys/csrss/lpcstub.c	2005-02-19 22:30:27 UTC (rev 13652)
+++ trunk/reactos/subsys/csrss/lpcstub.c	2005-02-19 22:56:59 UTC (rev 13653)
@@ -1,42 +0,0 @@
-/* $Id$
- *
- * lpcstub.c
- *
- * ReactOS Operating System
- *
- *
- */
-#include <ddk/ntddk.h>
-#include "api.h"
-
-
-/* CUI & GUI Win32(tm) API port */
-
-LPC_RETURN_CODE
-PortDispatcher_Api(
-	PLPC_REQUEST_REPLY	pLpcRequestReply
-	)
-{
-	switch (pLpcRequestReply->Function)
-	{
-		case CSRSS_API_PROCESS_CREATE:
-			return CSRSS_CreateProcess(pLpcRequestReply);
-		case CSRSS_API_PROCESS_TERMINATE:
-			return CSRSS_TerminateProcess(pLpcRequestReply);
-	}
-	return LPC_ERROR_INVALID_FUNCTION;
-}
-
-
-/* The \SbApi dispatcher: what is this port for? */
-
-LPC_RETURN_CODE
-PortDispatcher_SbApi(
-	PLPC_REQUEST_REPLY	pLpcRequestReply
-	)
-{
-	return LPC_ERROR_INVALID_FUNCTION;
-}
-
-
-/* EOF */

Modified: trunk/reactos/subsys/csrss/makefile
--- trunk/reactos/subsys/csrss/makefile	2005-02-19 22:30:27 UTC (rev 13652)
+++ trunk/reactos/subsys/csrss/makefile	2005-02-19 22:56:59 UTC (rev 13653)
@@ -9,7 +9,7 @@
 
 TARGET_NAME = csrss
 
-TARGET_SDKLIBS = rosrtl.a ntdll.a 
+TARGET_SDKLIBS = rosrtl.a ntdll.a smdll.a
 
 TARGET_INSTALLDIR = system32