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>
38 #include <reactos/buildno.h>
45 #define CSRP_MAX_ARGUMENT_COUNT 512
47 typedef struct _COMMAND_LINE_ARGUMENT
50 UNICODE_STRING Buffer
;
53 } COMMAND_LINE_ARGUMENT
, *PCOMMAND_LINE_ARGUMENT
;
55 /**********************************************************************
57 * CsrpParseCommandLine/3
59 static NTSTATUS STDCALL
60 CsrpParseCommandLine (HANDLE ProcessHeap
,
61 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
,
62 PCOMMAND_LINE_ARGUMENT Argument
)
65 INT afterlastspace
= 0;
68 DPRINT("CSR: %s called\n", __FUNCTION__
);
70 RtlZeroMemory (Argument
, sizeof (COMMAND_LINE_ARGUMENT
));
72 Argument
->Vector
= (PWSTR
*) RtlAllocateHeap (ProcessHeap
,
74 (CSRP_MAX_ARGUMENT_COUNT
* sizeof Argument
->Vector
[0]));
75 if(NULL
== Argument
->Vector
)
77 DPRINT("CSR: %s: no memory for Argument->Vector\n", __FUNCTION__
);
78 return STATUS_NO_MEMORY
;
81 Argument
->Buffer
.Length
=
82 Argument
->Buffer
.MaximumLength
=
83 RtlProcessParameters
->CommandLine
.Length
84 + sizeof Argument
->Buffer
.Buffer
[0]; /* zero terminated */
85 Argument
->Buffer
.Buffer
=
86 (PWSTR
) RtlAllocateHeap (ProcessHeap
,
88 Argument
->Buffer
.MaximumLength
);
89 if(NULL
== Argument
->Buffer
.Buffer
)
91 DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n", __FUNCTION__
);
92 return STATUS_NO_MEMORY
;
95 RtlCopyMemory (Argument
->Buffer
.Buffer
,
96 RtlProcessParameters
->CommandLine
.Buffer
,
97 RtlProcessParameters
->CommandLine
.Length
);
99 while (Argument
->Buffer
.Buffer
[i
])
101 if (Argument
->Buffer
.Buffer
[i
] == L
' ')
104 Argument
->Buffer
.Buffer
[i
] = L
'\0';
105 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
107 while (Argument
->Buffer
.Buffer
[i
] == L
' ')
119 if (Argument
->Buffer
.Buffer
[afterlastspace
] != L
'\0')
122 Argument
->Buffer
.Buffer
[i
] = L
'\0';
123 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
126 return STATUS_SUCCESS
;
129 /**********************************************************************
131 * CsrpFreeCommandLine/2
135 CsrpFreeCommandLine (HANDLE ProcessHeap
,
136 PCOMMAND_LINE_ARGUMENT Argument
)
138 DPRINT("CSR: %s called\n", __FUNCTION__
);
140 RtlFreeHeap (ProcessHeap
,
143 RtlFreeHeap (ProcessHeap
,
145 Argument
->Buffer
.Buffer
);
149 /* Native process' entry point */
151 VOID STDCALL
NtProcessStartup(PPEB Peb
)
153 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
= NULL
;
154 COMMAND_LINE_ARGUMENT CmdLineArg
= {0};
155 NTSTATUS Status
= STATUS_SUCCESS
;
157 PrintString("ReactOS Client/Server Run-Time %s (Build %s)\n",
159 KERNEL_VERSION_BUILD_STR
);
161 RtlProcessParameters
= RtlNormalizeProcessParams (Peb
->ProcessParameters
);
163 /*==================================================================
164 * Parse the command line: TODO actually parse the cl, because
165 * it is required to load hosted server DLLs.
166 *================================================================*/
167 Status
= CsrpParseCommandLine (Peb
->ProcessHeap
,
168 RtlProcessParameters
,
170 if(STATUS_SUCCESS
!= Status
)
172 DPRINT1("CSR: %s: CsrpParseCommandLine failed (Status=0x%08lx)\n",
173 __FUNCTION__
, Status
);
175 /*==================================================================
176 * Initialize the Win32 environment subsystem server.
177 *================================================================*/
178 if (CsrServerInitialization (CmdLineArg
.Count
, CmdLineArg
.Vector
) == TRUE
)
180 CsrpFreeCommandLine (Peb
->ProcessHeap
, & CmdLineArg
);
182 * Terminate the current thread only.
184 NtTerminateThread (NtCurrentThread(), 0);
188 DisplayString (L
"CSR: CsrServerInitialization failed.\n");
190 CsrpFreeCommandLine (Peb
->ProcessHeap
, & CmdLineArg
);
192 * Tell the SM we failed.
194 NtTerminateProcess (NtCurrentProcess(), 0);