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).
36 #define NTOS_MODE_USER
37 #include <ndk/ntndk.h>
38 #include <csrss/csrss.h>
39 #include <rosrtl/string.h>
40 #include <reactos/buildno.h>
47 #define CSRP_MAX_ARGUMENT_COUNT 512
49 typedef struct _COMMAND_LINE_ARGUMENT
52 UNICODE_STRING Buffer
;
55 } COMMAND_LINE_ARGUMENT
, *PCOMMAND_LINE_ARGUMENT
;
57 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
= NULL
;
59 /**********************************************************************
61 * CsrpParseCommandLine/3
63 static NTSTATUS STDCALL
64 CsrpParseCommandLine (HANDLE ProcessHeap
,
65 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
,
66 PCOMMAND_LINE_ARGUMENT Argument
)
69 INT afterlastspace
= 0;
72 DPRINT("CSR: %s called\n", __FUNCTION__
);
74 RtlZeroMemory (Argument
, sizeof (COMMAND_LINE_ARGUMENT
));
76 Argument
->Vector
= (PWSTR
*) RtlAllocateHeap (ProcessHeap
,
78 (CSRP_MAX_ARGUMENT_COUNT
* sizeof Argument
->Vector
[0]));
79 if(NULL
== Argument
->Vector
)
81 DPRINT("CSR: %s: no memory for Argument->Vector\n", __FUNCTION__
);
82 return STATUS_NO_MEMORY
;
85 Argument
->Buffer
.Length
=
86 Argument
->Buffer
.MaximumLength
=
87 RtlProcessParameters
->CommandLine
.Length
88 + sizeof Argument
->Buffer
.Buffer
[0]; /* zero terminated */
89 Argument
->Buffer
.Buffer
=
90 (PWSTR
) RtlAllocateHeap (ProcessHeap
,
92 Argument
->Buffer
.MaximumLength
);
93 if(NULL
== Argument
->Buffer
.Buffer
)
95 DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n", __FUNCTION__
);
96 return STATUS_NO_MEMORY
;
99 RtlCopyMemory (Argument
->Buffer
.Buffer
,
100 RtlProcessParameters
->CommandLine
.Buffer
,
101 RtlProcessParameters
->CommandLine
.Length
);
103 while (Argument
->Buffer
.Buffer
[i
])
105 if (Argument
->Buffer
.Buffer
[i
] == L
' ')
108 Argument
->Buffer
.Buffer
[i
] = L
'\0';
109 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
111 while (Argument
->Buffer
.Buffer
[i
] == L
' ')
123 if (Argument
->Buffer
.Buffer
[afterlastspace
] != L
'\0')
126 Argument
->Buffer
.Buffer
[i
] = L
'\0';
127 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
130 return STATUS_SUCCESS
;
133 /**********************************************************************
135 * CsrpFreeCommandLine/2
139 CsrpFreeCommandLine (HANDLE ProcessHeap
,
140 PCOMMAND_LINE_ARGUMENT Argument
)
142 DPRINT("CSR: %s called\n", __FUNCTION__
);
144 RtlFreeHeap (ProcessHeap
,
147 RtlFreeHeap (ProcessHeap
,
149 Argument
->Buffer
.Buffer
);
153 /* Native process' entry point */
155 VOID STDCALL
NtProcessStartup(PPEB Peb
)
157 COMMAND_LINE_ARGUMENT CmdLineArg
= {0};
158 NTSTATUS Status
= STATUS_SUCCESS
;
160 PrintString("ReactOS Client/Server Run-Time %s (Build %s)\n",
162 KERNEL_VERSION_BUILD_STR
);
164 RtlProcessParameters
= RtlNormalizeProcessParams (Peb
->ProcessParameters
);
166 /*==================================================================
167 * Parse the command line: TODO actually parse the cl, because
168 * it is required to load hosted server DLLs.
169 *================================================================*/
170 Status
= CsrpParseCommandLine (Peb
->ProcessHeap
,
171 RtlProcessParameters
,
173 if(STATUS_SUCCESS
!= Status
)
175 DPRINT1("CSR: %s: CsrpParseCommandLine failed (Status=0x%08lx)\n",
176 __FUNCTION__
, Status
);
178 /*==================================================================
179 * Initialize the Win32 environment subsystem server.
180 *================================================================*/
181 if (CsrServerInitialization (CmdLineArg
.Count
, CmdLineArg
.Vector
) == TRUE
)
183 CsrpFreeCommandLine (Peb
->ProcessHeap
, & CmdLineArg
);
185 * Terminate the current thread only.
187 NtTerminateThread (NtCurrentThread(), 0);
191 DisplayString (L
"CSR: CsrServerInitialization failed.\n");
193 CsrpFreeCommandLine (Peb
->ProcessHeap
, & CmdLineArg
);
195 * Tell the SM we failed.
197 NtTerminateProcess (NtCurrentProcess(), 0);