3 * csrss.c - Client/Server Runtime subsystem
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
24 * --------------------------------------------------------------------
26 * 19990417 (Emanuele Aliberti)
27 * Do nothing native application skeleton
28 * 19990528 (Emanuele Aliberti)
29 * Compiled successfully with egcs 1.1.2
30 * 19990605 (Emanuele Aliberti)
31 * First standalone run under ReactOS (it
32 * actually does nothing but running).
34 #include <ddk/ntddk.h>
35 #include <ntdll/rtl.h>
36 #include <csrss/csrss.h>
37 #include <rosrtl/string.h>
44 #define CSRP_MAX_ARGUMENT_COUNT 512
46 typedef struct _COMMAND_LINE_ARGUMENT
49 UNICODE_STRING Buffer
;
52 } COMMAND_LINE_ARGUMENT
, *PCOMMAND_LINE_ARGUMENT
;
54 /**********************************************************************
56 * CsrpParseCommandLine/3
58 static NTSTATUS STDCALL
59 CsrpParseCommandLine (HANDLE ProcessHeap
,
60 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
,
61 PCOMMAND_LINE_ARGUMENT Argument
)
64 INT afterlastspace
= 0;
67 DPRINT("CSR: %s called\n", __FUNCTION__
);
69 RtlZeroMemory (Argument
, sizeof (COMMAND_LINE_ARGUMENT
));
71 Argument
->Vector
= (PWSTR
*) RtlAllocateHeap (ProcessHeap
,
73 (CSRP_MAX_ARGUMENT_COUNT
* sizeof Argument
->Vector
[0]));
74 if(NULL
== Argument
->Vector
)
76 DPRINT("CSR: %s: no memory for Argument->Vector\n", __FUNCTION__
);
77 return STATUS_NO_MEMORY
;
80 Argument
->Buffer
.Length
=
81 Argument
->Buffer
.MaximumLength
=
82 RtlProcessParameters
->CommandLine
.Length
83 + sizeof Argument
->Buffer
.Buffer
[0]; /* zero terminated */
84 Argument
->Buffer
.Buffer
=
85 (PWSTR
) RtlAllocateHeap (ProcessHeap
,
87 Argument
->Buffer
.MaximumLength
);
88 if(NULL
== Argument
->Buffer
.Buffer
)
90 DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n", __FUNCTION__
);
91 return STATUS_NO_MEMORY
;
94 RtlCopyMemory (Argument
->Buffer
.Buffer
,
95 RtlProcessParameters
->CommandLine
.Buffer
,
96 RtlProcessParameters
->CommandLine
.Length
);
98 while (Argument
->Buffer
.Buffer
[i
])
100 if (Argument
->Buffer
.Buffer
[i
] == L
' ')
103 Argument
->Buffer
.Buffer
[i
] = L
'\0';
104 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
106 while (Argument
->Buffer
.Buffer
[i
] == L
' ')
118 if (Argument
->Buffer
.Buffer
[afterlastspace
] != L
'\0')
121 Argument
->Buffer
.Buffer
[i
] = L
'\0';
122 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
125 return STATUS_SUCCESS
;
128 /**********************************************************************
130 * CsrpFreeCommandLine/2
134 CsrpFreeCommandLine (HANDLE ProcessHeap
,
135 PCOMMAND_LINE_ARGUMENT Argument
)
137 DPRINT("CSR: %s called\n", __FUNCTION__
);
139 RtlFreeHeap (ProcessHeap
,
142 RtlFreeHeap (ProcessHeap
,
144 Argument
->Buffer
.Buffer
);
148 /**********************************************************************
150 * CsrpOpenSmInitDoneEvent/0
152 static NTSTATUS STDCALL
153 CsrpOpenSmInitDoneEvent (PHANDLE CsrssInitEvent
)
155 OBJECT_ATTRIBUTES ObjectAttributes
;
156 UNICODE_STRING EventName
;
158 DPRINT("CSR: %s called\n", __FUNCTION__
);
160 RtlInitUnicodeString(& EventName
,
162 InitializeObjectAttributes (& ObjectAttributes
,
167 return NtOpenEvent (CsrssInitEvent
,
172 /* Native process' entry point */
174 VOID STDCALL
NtProcessStartup(PPEB Peb
)
176 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
= NULL
;
177 COMMAND_LINE_ARGUMENT CmdLineArg
= {0};
178 HANDLE CsrssInitEvent
= (HANDLE
) 0;
179 NTSTATUS Status
= STATUS_SUCCESS
;
181 DPRINT("CSR: %s\n", __FUNCTION__
);
183 RtlProcessParameters
= RtlNormalizeProcessParams (Peb
->ProcessParameters
);
185 /*==================================================================
186 * Parse the command line.
187 *================================================================*/
188 Status
= CsrpParseCommandLine (Peb
->ProcessHeap
,
189 RtlProcessParameters
,
191 if(STATUS_SUCCESS
!= Status
)
193 DbgPrint("CSR: CsrpParseCommandLine failed (Status=0x%08lx)\n",
197 * Open the SM notification event to notify we are OK after
198 * subsystem server initialization.
200 Status
= CsrpOpenSmInitDoneEvent(& CsrssInitEvent
);
201 if (!NT_SUCCESS(Status
))
203 DbgPrint("CSR: CsrpOpenSmInitDoneEvent failed (Status=0x%08lx)\n",
206 /*==================================================================
207 * Initialize the Win32 environment subsystem server.
208 *================================================================*/
209 if (CsrServerInitialization (CmdLineArg
.Count
, CmdLineArg
.Vector
) == TRUE
)
211 /*=============================================================
212 * Tell SM we are up and safe. If we fail to notify SM, it will
213 * die and the kernel will bugcheck with
214 * SESSION5_INITIALIZATION_FAILED.
215 * TODO: this won't be necessary, because CSR will call SM
216 * API SM_SESSION_COMPLETE.
217 *===========================================================*/
218 NtSetEvent (CsrssInitEvent
, NULL
);
220 CsrpFreeCommandLine (Peb
->ProcessHeap
, & CmdLineArg
);
222 * Terminate the current thread only.
224 NtTerminateThread (NtCurrentThread(), 0);
228 DisplayString (L
"CSR: CsrServerInitialization failed.\n");
230 CsrpFreeCommandLine (Peb
->ProcessHeap
, & CmdLineArg
);
232 * Tell the SM we failed.
234 NtTerminateProcess (NtCurrentProcess(), 0);