<html>
<head>
<style>
<!--
body { background-color:#ffffff }
.file { border:1px solid #eeeeee; margin-top:1em; margin-bottom:1em }
.pathname { font-family:monospace; float:right }
.fileheader { margin-bottom:.5em }
.diff { margin:0 }
.tasklist { padding:4px; border:1px dashed #000000; margin-top:1em }
.tasklist ul { margin-top:0; margin-bottom:0 }
tr.alt { background-color:#eeeeee }
#added { background-color:#ddffdd }
#addedchars { background-color:#99ff99; font-weight:bolder }
tr.alt #added { background-color:#ccf7cc }
#removed { background-color:#ffdddd }
#removedchars { background-color:#ff9999; font-weight:bolder }
tr.alt #removed { background-color:#f7cccc }
#info { color:#888888 }
#context { background-color:#eeeeee }
td {padding-left:.3em; padding-right:.3em }
tr.head { border-bottom-width:1px; border-bottom-style:solid }
tr.head td { padding:0; padding-top:.2em }
.task { background-color:#ffff00 }
.comment { padding:4px; border:1px dashed #000000; background-color:#ffffdd }
.error { color:red }
hr { border-width:0px; height:2px; background:black }
-->
</style>
</head>
<body>
<pre class="comment">CSR pre-init cleanup</pre><pre class="diff" id="context">Modified: trunk/reactos/subsys/csrss/api/wapi.c
Modified: trunk/reactos/subsys/csrss/csrss.c
Modified: trunk/reactos/subsys/csrss/include/api.h
Modified: trunk/reactos/subsys/csrss/init.c
</pre><hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/subsys/csrss/api/wapi.c</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/subsys/csrss/api/wapi.c        2005-02-25 21:22:05 UTC (rev 13747)
+++ trunk/reactos/subsys/csrss/api/wapi.c        2005-02-26 15:06:19 UTC (rev 13748)
@@ -2,7 +2,7 @@
</small></pre><pre class="diff" id="context"> *
* reactos/subsys/csrss/api/wapi.c
*
</pre><pre class="diff" id="removed">- * <span id="removedchars">Initialize the CSRSS subsystem server process.</span>
</pre><pre class="diff" id="added">+ * <span id="addedchars">CSRSS port message processing</span>
</pre><pre class="diff" id="context"> *
* ReactOS Operating System
*
@@ -147,14 +147,14 @@
</pre><pre class="diff" id="context">
/**********************************************************************
* NAME
</pre><pre class="diff" id="removed">- *        <span id="removedchars">Thread_Api</span>
</pre><pre class="diff" id="added">+ *        <span id="addedchars">ServerApiPortThread/1</span>
</pre><pre class="diff" id="context"> *
* DESCRIPTION
*         Handle connection requests from clients to the port
*         "\Windows\ApiPort".
*/
void STDCALL
</pre><pre class="diff" id="removed">-ServerApiPortTh<span id="removedchars">ead</span>(PVOID PortHandle)
</pre><pre class="diff" id="added">+ServerApiPortTh<span id="addedchars">read </span>(PVOID PortHandle)
</pre><pre class="diff" id="context"> {
NTSTATUS Status;
LPC_MAX_MESSAGE Request;
@@ -232,4 +232,51 @@
</pre><pre class="diff" id="context"> NtTerminateThread(NtCurrentThread(), Status);
}
</pre><pre class="diff" id="added">+/**********************************************************************
+ * NAME
+ *        ServerSbApiPortThread/1
+ *
+ * DESCRIPTION
+ *         Handle connection requests from SM to the port
+ *         "\Windows\SbApiPort".
+ */
+VOID STDCALL
+ServerSbApiPortThread (PVOID PortHandle)
+{
+        HANDLE hSbApiPortListen = (HANDLE) PortHandle;
+        HANDLE hConnectedPort = (HANDLE) 0;
+        LPC_MAX_MESSAGE Request = {{0}};
+        NTSTATUS Status = STATUS_SUCCESS;
+
+        while (TRUE)
+        {
+                Status = NtListenPort (hSbApiPortListen, & Request.Header);
+                if (!NT_SUCCESS(Status))
+                {
+                        DPRINT1("CSR: %s: NtListenPort(SB) failed\n", __FUNCTION__);
+                        break;
+                }
+                Status = NtAcceptConnectPort (& hConnectedPort,
+                                                hSbApiPortListen,
+                                                 NULL,
+                                                 TRUE,
+                                                 NULL,
+                                                 NULL);
+                if(!NT_SUCCESS(Status))
+                {
+                        DPRINT1("CSR: %s: NtAcceptConnectPort() failed\n", __FUNCTION__);
+                        break;
+                }
+                Status = NtCompleteConnectPort (hConnectedPort);
+                if(!NT_SUCCESS(Status))
+                {
+                        DPRINT1("CSR: %s: NtCompleteConnectPort() failed\n", __FUNCTION__);
+                        break;
+                }
+                /* TODO: create thread for the connected port */
+        }
+        NtClose (hSbApiPortListen);
+        NtTerminateThread (NtCurrentThread(), Status);
+}
+
</pre><pre class="diff" id="context"> /* EOF */
</pre></div>
<hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/subsys/csrss/csrss.c</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/subsys/csrss/csrss.c        2005-02-25 21:22:05 UTC (rev 13747)
+++ trunk/reactos/subsys/csrss/csrss.c        2005-02-26 15:06:19 UTC (rev 13748)
@@ -38,42 +38,75 @@
</small></pre><pre class="diff" id="context">
#include "api.h"
</pre><pre class="diff" id="removed">-/* Native process' entry point */
</pre><pre class="diff" id="added">+#define NDEBUG
+#include <debug.h>
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-VOID STDCALL NtProcessStartup(PPEB Peb)
</pre><pre class="diff" id="added">+#define CSRP_MAX_ARGUMENT_COUNT 512
+
+typedef struct _COMMAND_LINE_ARGUMENT
</pre><pre class="diff" id="context"> {
</pre><pre class="diff" id="removed">- PRTL_USER_PROCESS_PARAMETERS ProcParams;
- PWSTR ArgBuffer;
- PWSTR *argv;
- ULONG argc = 0;
- int i = 0;
- int afterlastspace = 0;
- OBJECT_ATTRIBUTES ObjectAttributes;
- HANDLE CsrssInitEvent;
- UNICODE_STRING UnicodeString;
-<span id="removedchars"> NTSTATUS Status</span>;
</pre><pre class="diff" id="added">+<span id="addedchars">        ULONG                Count</span>;
+        UNICODE_STRING        Buffer;
+        PWSTR                * Vector;
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-<span id="removedchars"> ProcParams = RtlNormalizeProcessParams (Peb->ProcessParameters)</span>;
</pre><pre class="diff" id="added">+<span id="addedchars">} COMMAND_LINE_ARGUMENT, *PCOMMAND_LINE_ARGUMENT</span>;
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- argv = (PWSTR *)RtlAllocateHeap (Peb->ProcessHeap,
- 0, 512 * sizeof(PWSTR));
- ArgBuffer = (PWSTR)RtlAllocateHeap (Peb->ProcessHeap,
- 0,
- ProcParams->CommandLine.Length + sizeof(WCHAR));
- memcpy (ArgBuffer,
- ProcParams->CommandLine.Buffer,
- ProcParams->CommandLine.Length + sizeof(WCHAR));
</pre><pre class="diff" id="added">+/**********************************************************************
+ * NAME                                                        PRIVATE
+ *         CsrpParseCommandLine/3
+ */
+static NTSTATUS STDCALL
+CsrpParseCommandLine (HANDLE ProcessHeap,
+                 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters,
+                 PCOMMAND_LINE_ARGUMENT Argument)
+{
+ INT i = 0;
+ INT afterlastspace = 0;
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- <span id="removedchars">while (ArgBuffer[i])</span>
</pre><pre class="diff" id="added">+
+ DPRINT("CSR: %s called\n", __FUNCTION__);
+
+ RtlZeroMemory (Argument, sizeof (COMMAND_LINE_ARGUMENT));
+
+ Argument->Vector = (PWSTR *) RtlAllocateHeap (ProcessHeap,
+                                                 0,
+                                                 (CSRP_MAX_ARGUMENT_COUNT * sizeof Argument->Vector[0]));
+ if(NULL == Argument->Vector)
+ {
+         DPRINT("CSR: %s: no memory for Argument->Vector\n", __FUNCTION__);
+         return STATUS_NO_MEMORY;
+ }
+
+ Argument->Buffer.Length =
+ Argument->Buffer.MaximumLength =
+         RtlProcessParameters->CommandLine.Length
+        + sizeof Argument->Buffer.Buffer [0]; /* zero terminated */
+ Argument->Buffer.Buffer =
+        (PWSTR) RtlAllocateHeap (ProcessHeap,
+                                 0,
+ Argument->Buffer.MaximumLength);
+ if(NULL == Argument->Buffer.Buffer)
+ {
+         DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n", __FUNCTION__);
+         return STATUS_NO_MEMORY;
+ }
+
+ RtlCopyMemory (Argument->Buffer.Buffer,
+                 RtlProcessParameters->CommandLine.Buffer,
+                 RtlProcessParameters->CommandLine.Length);
+
+ while (Argument->Buffer.Buffer [i])
</pre><pre class="diff" id="context"> {
</pre><pre class="diff" id="removed">-        if (ArgBuffer[i] == L' ')
</pre><pre class="diff" id="added">+        if (Arg<span id="addedchars">ument->Buffer.</span>Buffer[i] == L' ')
</pre><pre class="diff" id="context">          {
</pre><pre class="diff" id="removed">-         argc++;
-         ArgBuffer[i] = L'\0';
-         <span id="removedchars">argv[argc-1] = &(ArgBuffer[afterlastspace])</span>;
</pre><pre class="diff" id="added">+         <span id="addedchars">Argument->Count ++</span>;
+         Argument->Buffer.Buffer [i] = L'\0';
+         Argument->Vector [Argument->Count - 1] = & (Argument->Buffer.Buffer [afterlastspace]);
</pre><pre class="diff" id="context">          i++;
</pre><pre class="diff" id="removed">-         while (Arg<span id="removedchars">Buffer</span>[i] == L' ')
</pre><pre class="diff" id="added">+         while (Arg<span id="addedchars">ument->Buffer.Buffer </span>[i] == L' ')
+         {
</pre><pre class="diff" id="context">                 i++;
</pre><pre class="diff" id="added">+         }
</pre><pre class="diff" id="context">          afterlastspace = i;
         }
        else
@@ -82,56 +115,122 @@
</pre><pre class="diff" id="context">          }
}
</pre><pre class="diff" id="removed">- if (Arg<span id="removedchars">Buffer</span>[afterlastspace] != L'\0')
</pre><pre class="diff" id="added">+ if (Arg<span id="addedchars">ument->Buffer.Buffer </span>[afterlastspace] != L'\0')
</pre><pre class="diff" id="context"> {
</pre><pre class="diff" id="removed">-        argc++;
-        ArgBuffer[i] = L'\0';
-        <span id="removedchars">argv[argc-1] = &(ArgBuffer[afterlastspace])</span>;
</pre><pre class="diff" id="added">+        <span id="addedchars">Argument->Count ++</span>;
+        Argument->Buffer.Buffer [i] = L'\0';
+        Argument->Vector [Argument->Count - 1] = & (Argument->Buffer.Buffer [afterlastspace]);
</pre><pre class="diff" id="context"> }
</pre><pre class="diff" id="removed">-
- RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
</pre><pre class="diff" id="added">+
+ return STATUS_SUCCESS;
+}
+
+/**********************************************************************
+ * NAME                                                        PRIVATE
+ *         CsrpFreeCommandLine/2
+ */
+                
+static VOID STDCALL
+CsrpFreeCommandLine (HANDLE ProcessHeap,
+                 PCOMMAND_LINE_ARGUMENT Argument)
+{
+        DPRINT("CSR: %s called\n", __FUNCTION__);
+        
+        RtlFreeHeap (ProcessHeap,
+         0,
+                 Argument->Vector);
+        RtlFreeHeap (ProcessHeap,
+         0,
+         Argument->Buffer.Buffer);
+}
+
+
+/**********************************************************************
+ * NAME                                                        PRIVATE
+ *         CsrpOpenKeInitDoneEvent/0
+ */
+static NTSTATUS STDCALL
+CsrpOpenKeInitDoneEvent (PHANDLE CsrssInitEvent)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING EventName;
+
+ DPRINT("CSR: %s called\n", __FUNCTION__);
+
+ RtlInitUnicodeString(& EventName,
</pre><pre class="diff" id="context">                         L"\\CsrssInitDone");
</pre><pre class="diff" id="removed">- InitializeObjectAttributes(&ObjectAttributes,
-                         &UnicodeString,
-                         EVENT_ALL_ACCESS,
-                         0,
-                         NULL);
- <span id="removedchars">Status = NtOpenEvent(&CsrssInitEvent</span>,
</pre><pre class="diff" id="added">+ <span id="addedchars">InitializeObjectAttributes (& ObjectAttributes</span>,
+                                & EventName,
+                                EVENT_ALL_ACCESS,
+                                0,
+                                NULL);
+ return NtOpenEvent (CsrssInitEvent,
</pre><pre class="diff" id="context">                         EVENT_ALL_ACCESS,
</pre><pre class="diff" id="removed">-                        &ObjectAttributes);
</pre><pre class="diff" id="added">+                        &<span id="addedchars"> </span>ObjectAttributes);
+}
+
+/* Native process' entry point */
+
+VOID STDCALL NtProcessStartup(PPEB Peb)
+{
+ PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters = NULL;
+ COMMAND_LINE_ARGUMENT CmdLineArg = {0};
+ HANDLE CsrssInitEvent = (HANDLE) 0;
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ DPRINT("CSR: %s\n", __FUNCTION__);
+
+ RtlProcessParameters = RtlNormalizeProcessParams (Peb->ProcessParameters);
+
+ /*==================================================================
+ * Parse the command line.
+ *================================================================*/
+ Status = CsrpParseCommandLine (Peb->ProcessHeap,
+                                 RtlProcessParameters,
+                                 & CmdLineArg);
+ if(STATUS_SUCCESS != Status)
+ {
+         DbgPrint("CSR: CsrpParseCommandLine failed (Status=0x%08lx)\n",
+                Status);
+ }
+ /*
+ * Open the Ke notification event to notify we are OK after
+ * subsystem server initialization.
+ */
+ Status = CsrpOpenKeInitDoneEvent(& CsrssInitEvent);
</pre><pre class="diff" id="context"> if (!NT_SUCCESS(Status))
{
</pre><pre class="diff" id="removed">-        DbgPrint("CSR: <span id="removedchars">Failed to open csrss notification event\n");</span>
</pre><pre class="diff" id="added">+        DbgPrint("CSR: <span id="addedchars">CsrpOpenKeInitDoneEvent failed (Status=0x%08lx)\n",</span>
+                        Status);
</pre><pre class="diff" id="context"> }
</pre><pre class="diff" id="removed">- <span id="removedchars">if (CsrServerInitialization (argc, argv) == TRUE)</span>
</pre><pre class="diff" id="added">+ <span id="addedchars">/*==================================================================</span>
+ *        Initialize the Win32 environment subsystem server.
+ *================================================================*/
+ if (CsrServerInitialization (CmdLineArg.Count, CmdLineArg.Vector) == TRUE)
</pre><pre class="diff" id="context"> {
</pre><pre class="diff" id="added">+        /*=============================================================
+         * Tell Ke we are up and safe. If we fail to notify Ke, it will
+         * bugcheck the system with SESSION5_INITIALIZATION_FAILED.
+         * TODO: choose a better way to check user mode initialization
+         * is OK.
+         *===========================================================*/
+        NtSetEvent (CsrssInitEvent, NULL);
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-        NtSetEvent(CsrssInitEvent,
-                 NULL);
-        
-        RtlFreeHeap (Peb->ProcessHeap,
-         0, argv);
-        RtlFreeHeap (Peb->ProcessHeap,
-         0,
-         ArgBuffer);
-
-        /* terminate the current thread only */
-        <span id="removedchars">NtTerminateThread( NtCurrentThread(), 0 );</span>
</pre><pre class="diff" id="added">+        <span id="addedchars">CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);        </span>
+        /*
+         * Terminate the current thread only.
+         */
+        NtTerminateThread (NtCurrentThread(), 0);
</pre><pre class="diff" id="context"> }
else
{
</pre><pre class="diff" id="removed">-        DisplayString<span id="removedchars">( L"CSR: Subsystem initialization failed.\n" </span>);
</pre><pre class="diff" id="added">+        DisplayString<span id="addedchars"> (L"CSR: CsrServerInitialization failed.\n"</span>);
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-        RtlFreeHeap (Peb->ProcessHeap,
-         0, argv);
-        RtlFreeHeap (Peb->ProcessHeap,
-         0,
-         ArgBuffer);
-
</pre><pre class="diff" id="added">+        CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);        
</pre><pre class="diff" id="context">         /*
</pre><pre class="diff" id="removed">-         * Tell SM we failed.
</pre><pre class="diff" id="added">+         * Tell <span id="addedchars">the </span>SM we failed.
</pre><pre class="diff" id="context">          */
</pre><pre class="diff" id="removed">-        NtTerminateProcess<span id="removedchars">( NtCurrentProcess(), 0 </span>);
</pre><pre class="diff" id="added">+        NtTerminateProcess<span id="addedchars"> (NtCurrentProcess(), 0</span>);
</pre><pre class="diff" id="context"> }
}
</pre></div>
<hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/subsys/csrss/include/api.h</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/subsys/csrss/include/api.h        2005-02-25 21:22:05 UTC (rev 13747)
+++ trunk/reactos/subsys/csrss/include/api.h        2005-02-26 15:06:19 UTC (rev 13748)
@@ -96,7 +96,8 @@
</small></pre><pre class="diff" id="context"> VOID FASTCALL CsrApiCallHandler(PCSRSS_PROCESS_DATA ProcessData,
PCSRSS_API_REQUEST Request,
PCSRSS_API_REPLY Reply);
</pre><pre class="diff" id="removed">-VOID STDCALL ServerApiPortTh<span id="removedchars">ead</span>(PVOID PortHandle);
</pre><pre class="diff" id="added">+VOID STDCALL ServerApiPortTh<span id="addedchars">read </span>(PVOID PortHandle);
+VOID STDCALL ServerSbApiPortThread (PVOID PortHandle);
</pre><pre class="diff" id="context"> VOID Console_Api( DWORD Ignored );
extern HANDLE CsrssApiHeap;
</pre></div>
<hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/subsys/csrss/init.c</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/subsys/csrss/init.c        2005-02-25 21:22:05 UTC (rev 13747)
+++ trunk/reactos/subsys/csrss/init.c        2005-02-26 15:06:19 UTC (rev 13748)
@@ -335,7 +335,7 @@
</small></pre><pre class="diff" id="context"> 0,
NULL,
NULL,
</pre><pre class="diff" id="removed">- (PTHREAD_START_ROUTINE)ServerApiPortThead,
</pre><pre class="diff" id="added">+ (PTHREAD_START_ROUTINE)ServerApiPortTh<span id="addedchars">r</span>ead,
</pre><pre class="diff" id="context"> ApiPortHandle,
NULL,
NULL);
</pre>
</div>
</body>
</html>