1 /* $Id: init.c,v 1.18 2000/06/29 23:35:51 dwelch Exp $
3 * init.c - Session Manager initialization
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 * 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 * 19990530 (Emanuele Aliberti)
27 * Compiled successfully with egcs 1.1.2
30 #include <ntdll/rtl.h>
37 /* uncomment to run csrss.exe */
40 /* GLOBAL VARIABLES *********************************************************/
42 HANDLE SmApiPort
= INVALID_HANDLE_VALUE
;
43 HANDLE DbgSsApiPort
= INVALID_HANDLE_VALUE
;
44 HANDLE DbgUiApiPort
= INVALID_HANDLE_VALUE
;
46 PVOID SmSystemEnvironment
= NULL
;
49 /* FUNCTIONS ****************************************************************/
53 SmCreatePagingFiles (VOID
)
55 UNICODE_STRING FileName
;
58 /* FIXME: Read file names from registry */
60 RtlInitUnicodeString (&FileName
,
61 L
"\\??\\C:\\reactos\\pagefile.sys");
63 NtCreatePagingFile (&FileName
,
72 SmSetEnvironmentVariables (VOID
)
74 UNICODE_STRING EnvVariable
;
75 UNICODE_STRING EnvValue
;
76 UNICODE_STRING EnvExpandedValue
;
78 WCHAR ExpandBuffer
[512];
81 * The following environment variables are read from the registry.
82 * Since the registry does not work yet, the environment variables
83 * are set one by one, using hard-coded default values.
86 * SystemRoot = C:\reactos
90 * Path = %SystemRoot%\system32;%SystemRoot%
91 * windir = %SystemRoot%
94 /* Set "SystemRoot = C:\reactos" */
95 RtlInitUnicodeString (&EnvVariable
,
97 RtlInitUnicodeString (&EnvValue
,
99 RtlSetEnvironmentVariable (&SmSystemEnvironment
,
103 /* Set "SystemDrive = C:" */
104 RtlInitUnicodeString (&EnvVariable
,
106 RtlInitUnicodeString (&EnvValue
,
108 RtlSetEnvironmentVariable (&SmSystemEnvironment
,
113 /* Set "OS = ReactOS" */
114 RtlInitUnicodeString (&EnvVariable
,
116 RtlInitUnicodeString (&EnvValue
,
118 RtlSetEnvironmentVariable (&SmSystemEnvironment
,
123 /* Set "Path = %SystemRoot%\system32;%SystemRoot%" */
124 RtlInitUnicodeString (&EnvVariable
,
126 RtlInitUnicodeString (&EnvValue
,
127 L
"%SystemRoot%\\system32;%SystemRoot%");
128 EnvExpandedValue
.Length
= 0;
129 EnvExpandedValue
.MaximumLength
= 512 * sizeof(WCHAR
);
130 EnvExpandedValue
.Buffer
= ExpandBuffer
;
132 RtlExpandEnvironmentStrings_U (SmSystemEnvironment
,
136 RtlSetEnvironmentVariable (&SmSystemEnvironment
,
140 /* Set "windir = %SystemRoot%" */
141 RtlInitUnicodeString (&EnvVariable
,
143 RtlInitUnicodeString (&EnvValue
,
145 EnvExpandedValue
.Length
= 0;
146 EnvExpandedValue
.MaximumLength
= 512 * sizeof(WCHAR
);
147 EnvExpandedValue
.Buffer
= ExpandBuffer
;
149 RtlExpandEnvironmentStrings_U (SmSystemEnvironment
,
153 RtlSetEnvironmentVariable (&SmSystemEnvironment
,
159 BOOL
InitSessionManager (HANDLE Children
[])
162 UNICODE_STRING UnicodeString
;
163 OBJECT_ATTRIBUTES ObjectAttributes
;
164 UNICODE_STRING CmdLineW
;
165 UNICODE_STRING CurrentDirectoryW
;
166 PRTL_USER_PROCESS_PARAMETERS ProcessParameters
;
167 RTL_USER_PROCESS_INFO ProcessInfo
;
168 HANDLE CsrssInitEvent
;
170 /* Create the "\SmApiPort" object (LPC) */
171 RtlInitUnicodeString (&UnicodeString
,
173 InitializeObjectAttributes (&ObjectAttributes
,
179 Status
= NtCreatePort (&SmApiPort
,
185 if (!NT_SUCCESS(Status
))
191 DisplayString (L
"SM: \\SmApiPort created...\n");
194 /* Create two threads for "\SmApiPort" */
195 RtlCreateUserThread (NtCurrentProcess (),
201 (PTHREAD_START_ROUTINE
)SmApiThread
,
206 RtlCreateUserThread (NtCurrentProcess (),
212 (PTHREAD_START_ROUTINE
)SmApiThread
,
217 /* Create the system environment */
218 Status
= RtlCreateEnvironment (TRUE
,
219 &SmSystemEnvironment
);
220 if (!NT_SUCCESS(Status
))
223 DisplayString (L
"SM: System Environment created\n");
226 /* FIXME: Define symbolic links to kernel devices (MS-DOS names) */
228 /* FIXME: Run all programs in the boot execution list */
230 /* FIXME: Process the file rename list */
232 /* FIXME: Load the well known DLLs */
235 /* Create paging files */
236 SmCreatePagingFiles ();
240 /* Load missing registry hives */
241 NtInitializeRegistry (FALSE
);
244 /* Set environment variables from registry */
245 SmSetEnvironmentVariables ();
247 /* Load the kernel mode driver win32k.sys */
248 RtlInitUnicodeString (&CmdLineW
,
249 L
"\\??\\C:\\reactos\\system32\\drivers\\win32k.sys");
250 Status
= NtLoadDriver (&CmdLineW
);
252 if (!NT_SUCCESS(Status
))
258 RtlInitUnicodeString(&UnicodeString
,
260 InitializeObjectAttributes(&ObjectAttributes
,
265 Status
= NtCreateEvent(&CsrssInitEvent
,
270 if (!NT_SUCCESS(Status
))
272 DbgPrint("Failed to create csrss notification event\n");
275 /* Start the Win32 subsystem (csrss.exe) */
276 DisplayString (L
"SM: Executing csrss.exe\n");
278 RtlInitUnicodeString (&UnicodeString
,
279 L
"\\??\\C:\\reactos\\system32\\csrss.exe");
281 /* initialize current directory */
282 RtlInitUnicodeString (&CurrentDirectoryW
,
283 L
"C:\\reactos\\system32\\");
285 RtlCreateProcessParameters (&ProcessParameters
,
296 Status
= RtlCreateUserProcess (&UnicodeString
,
307 RtlDestroyProcessParameters (ProcessParameters
);
309 if (!NT_SUCCESS(Status
))
311 DisplayString (L
"SM: Loading csrss.exe failed!\n");
315 DbgPrint("SM: Waiting for csrss\n");
316 NtWaitForSingleObject(CsrssInitEvent
,
319 DbgPrint("SM: Finished waiting for csrss\n");
321 Children
[CHILD_CSRSS
] = ProcessInfo
.ProcessHandle
;
322 #endif /* RUN_CSRSS */
325 /* Start the simple shell (shell.exe) */
326 DisplayString (L
"SM: Executing shell\n");
327 RtlInitUnicodeString (&UnicodeString
,
328 L
"\\??\\C:\\reactos\\system32\\shell.exe");
330 /* Start the logon process (winlogon.exe) */
331 DisplayString (L
"SM: Running winlogon\n");
332 RtlInitUnicodeString (&UnicodeString
,
333 L
"\\??\\C:\\reactos\\system32\\winlogon.exe");
336 /* initialize current directory (trailing backslash!!)*/
337 RtlInitUnicodeString (&CurrentDirectoryW
,
340 RtlCreateProcessParameters (&ProcessParameters
,
352 Status
= RtlCreateUserProcess (&UnicodeString
,
363 RtlDestroyProcessParameters (ProcessParameters
);
365 if (!NT_SUCCESS(Status
))
367 DisplayString (L
"SM: Loading shell.exe failed!\n");
369 NtTerminateProcess (Children
[CHILD_CSRSS
],
374 Children
[CHILD_WINLOGON
] = ProcessInfo
.ProcessHandle
;
376 /* Create the \DbgSsApiPort object (LPC) */
377 RtlInitUnicodeString (&UnicodeString
,
379 InitializeObjectAttributes (&ObjectAttributes
,
385 Status
= NtCreatePort (&DbgSsApiPort
,
391 if (!NT_SUCCESS(Status
))
396 DisplayString (L
"SM: DbgSsApiPort created...\n");
399 /* Create the \DbgUiApiPort object (LPC) */
400 RtlInitUnicodeString (&UnicodeString
,
402 InitializeObjectAttributes (&ObjectAttributes
,
408 Status
= NtCreatePort (&DbgUiApiPort
,
414 if (!NT_SUCCESS(Status
))
419 DisplayString (L
"SM: DbgUiApiPort created...\n");