1 /* $Id: init.c 13449 2005-02-06 21:55:07Z ea $
3 * initss.c - Load the subsystems
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 * --------------------------------------------------------------------
30 #include <rosrtl/string.h>
35 /* SM handle for its own \SmApiPort */
36 HANDLE hSmApiPort
= (HANDLE
) 0;
39 /* TODO: this file should be totally rewritten
41 * a) look if a special option is set for smss.exe in
42 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
44 * b) make smss register with itself for IMAGE_SUBSYSTEM_NATIVE
47 * d) make smss initialize Debug (DBGSS) and Windows (CSRSS) as described
48 * in the registry key Required="Debug Windows"
49 * HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
51 * e) make optional subsystems loadable (again: they must be described in the registry
52 * key Optional="Posix Os2" to be allowed to run)
55 /**********************************************************************
59 * Make smss register with itself for IMAGE_SUBSYSTEM_NATIVE
60 * (programmatically). This also open hSmApiPort to be used
61 * in loading required subsystems.
67 NTSTATUS Status
= STATUS_SUCCESS
;
68 UNICODE_STRING SbApiPortName
= {0,0,NULL
};
70 DPRINT("SM: %s called\n",__FUNCTION__
);
72 Status
= SmConnectApiPort(& SbApiPortName
,
74 IMAGE_SUBSYSTEM_NATIVE
,
76 if(!NT_SUCCESS(Status
))
78 DPRINT("SM: %s: SMDLL!SmConnectApiPort failed (Status=0x%08lx)\n",
83 * Note that you don't need to call complete session
84 * because connection handling code autocompletes
85 * the client structure for IMAGE_SUBSYSTEM_NATIVE.
91 /**********************************************************************
94 SmLoadSubsystems(VOID
)
96 SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo
;
97 NTSTATUS Status
= STATUS_SUCCESS
;
98 WCHAR Data
[MAX_PATH
+ 1];
99 ULONG DataLength
= sizeof Data
;
103 DPRINT("SM: loading subsystems\n");
105 /* SM self registers */
107 Status
= SmpRegisterSmss();
108 if(!NT_SUCCESS(Status
))
110 DPRINT1("SM: SM failed to self register: system is not secure!\n");
113 /* Load Kmode subsystem (aka win32k.sys) */
114 Status
= SmLookupSubsystem (L
"Kmode",
119 if((STATUS_SUCCESS
== Status
) && (DataLength
> sizeof Data
[0]))
121 WCHAR ImagePath
[MAX_PATH
+ 1] = {0};
123 wcscpy (ImagePath
, L
"\\??\\");
124 wcscat (ImagePath
, Data
);
125 RtlZeroMemory (& ImageInfo
, sizeof ImageInfo
);
126 RtlInitUnicodeString (& ImageInfo
.ModuleName
, ImagePath
);
127 Status
= NtSetSystemInformation(SystemLoadAndCallImage
,
130 if(!NT_SUCCESS(Status
))
132 DPRINT("SM: loading Kmode failed (Status=0x%08lx)\n",
137 /* TODO: load Required subsystems (Debug Windows) */
139 Status
= SmExecuteProgram(L
"DEBUG");
140 if(!NT_SUCCESS(Status
))
142 DPRINT1("SM: DBSS failed to initialize!\n");
152 UNICODE_STRING UnicodeString
;
153 OBJECT_ATTRIBUTES ObjectAttributes
;
154 RTL_PROCESS_INFO ProcessInfo
;
155 HANDLE CsrssInitEvent
;
156 WCHAR ImagePath
[MAX_PATH
];
158 DPRINT("SM: initializing csrss\n");
161 RtlRosInitUnicodeStringFromLiteral(&UnicodeString
,
163 InitializeObjectAttributes(&ObjectAttributes
,
168 Status
= NtCreateEvent(&CsrssInitEvent
,
173 if (!NT_SUCCESS(Status
))
175 DbgPrint("Failed to create csrss notification event\n");
179 * Start the Win32 subsystem (csrss.exe)
182 /* initialize executable path */
183 wcscpy(ImagePath
, L
"\\??\\");
184 wcscat(ImagePath
, SharedUserData
->NtSystemRoot
);
185 wcscat(ImagePath
, L
"\\system32\\csrss.exe");
187 Status
= SmCreateUserProcess(ImagePath
,
191 FALSE
, /* terminate */
194 if (!NT_SUCCESS(Status
))
196 DPRINT("SM: %s: Loading csrss.exe failed!\n", __FUNCTION__
);
200 Status
= NtWaitForSingleObject(CsrssInitEvent
,
204 Children
[CHILD_CSRSS
] = ProcessInfo
.ProcessHandle
;
212 NTSTATUS Status
= STATUS_SUCCESS
;
213 RTL_PROCESS_INFO ProcessInfo
;
214 WCHAR ImagePath
[MAX_PATH
];
217 * Start the logon process (winlogon.exe)
220 DPRINT("SM: starting winlogon\n");
222 /* initialize executable path */
223 wcscpy(ImagePath
, L
"\\??\\");
224 wcscat(ImagePath
, SharedUserData
->NtSystemRoot
);
225 wcscat(ImagePath
, L
"\\system32\\winlogon.exe");
227 Status
= SmCreateUserProcess(ImagePath
,
231 FALSE
, /* terminate */
233 if (!NT_SUCCESS(Status
))
235 DPRINT("SM: %s: Loading winlogon.exe failed!\n", __FUNCTION__
);
236 NtTerminateProcess(Children
[CHILD_CSRSS
], 0);
240 Children
[CHILD_WINLOGON
] = ProcessInfo
.ProcessHandle
;