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 RtlInitUnicodeString (& SbApiPortName
, L
"");
73 Status
= SmConnectApiPort(& SbApiPortName
,
75 IMAGE_SUBSYSTEM_NATIVE
,
77 if(!NT_SUCCESS(Status
))
79 DPRINT("SM: %s: SMDLL!SmConnectApiPort failed (Status=0x%08lx)\n",
83 DPRINT("SM self registered\n");
85 * Note that you don't need to call complete session
86 * because connection handling code autocompletes
87 * the client structure for IMAGE_SUBSYSTEM_NATIVE.
93 /**********************************************************************
96 SmLoadSubsystems(VOID
)
98 SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo
;
99 NTSTATUS Status
= STATUS_SUCCESS
;
100 WCHAR Data
[MAX_PATH
+ 1];
101 ULONG DataLength
= sizeof Data
;
105 DPRINT("SM: loading subsystems\n");
107 /* SM self registers */
108 Status
= SmpRegisterSmss();
109 if(!NT_SUCCESS(Status
))
111 DPRINT1("SM: SM failed to self register: system is not secure!\n");
114 /* Load Kmode subsystem (aka win32k.sys) */
115 Status
= SmLookupSubsystem (L
"Kmode",
120 if((STATUS_SUCCESS
== Status
) && (DataLength
> sizeof Data
[0]))
122 WCHAR ImagePath
[MAX_PATH
+ 1] = {0};
124 wcscpy (ImagePath
, L
"\\??\\");
125 wcscat (ImagePath
, Data
);
126 RtlZeroMemory (& ImageInfo
, sizeof ImageInfo
);
127 RtlInitUnicodeString (& ImageInfo
.ModuleName
, ImagePath
);
128 Status
= NtSetSystemInformation(SystemLoadAndCallImage
,
131 if(!NT_SUCCESS(Status
))
133 DPRINT("SM: loading Kmode failed (Status=0x%08lx)\n",
138 /* TODO: load Required subsystems (Debug Windows) */
140 Status
= SmExecuteProgram (hSmApiPort
, L
"DEBUG");
141 if(!NT_SUCCESS(Status
))
143 DPRINT1("SM: DBSS failed to initialize!\n");
153 UNICODE_STRING UnicodeString
;
154 OBJECT_ATTRIBUTES ObjectAttributes
;
155 RTL_PROCESS_INFO ProcessInfo
;
156 HANDLE CsrssInitEvent
;
157 WCHAR ImagePath
[MAX_PATH
];
159 DPRINT("SM: initializing csrss\n");
162 RtlRosInitUnicodeStringFromLiteral(&UnicodeString
,
164 InitializeObjectAttributes(&ObjectAttributes
,
169 Status
= NtCreateEvent(&CsrssInitEvent
,
174 if (!NT_SUCCESS(Status
))
176 DbgPrint("Failed to create csrss notification event\n");
180 * Start the Win32 subsystem (csrss.exe)
183 /* initialize executable path */
184 wcscpy(ImagePath
, L
"\\??\\");
185 wcscat(ImagePath
, SharedUserData
->NtSystemRoot
);
186 wcscat(ImagePath
, L
"\\system32\\csrss.exe");
188 Status
= SmCreateUserProcess(ImagePath
,
192 FALSE
, /* terminate */
195 if (!NT_SUCCESS(Status
))
197 DPRINT("SM: %s: Loading csrss.exe failed!\n", __FUNCTION__
);
201 Status
= NtWaitForSingleObject(CsrssInitEvent
,
205 Children
[CHILD_CSRSS
] = ProcessInfo
.ProcessHandle
;
213 NTSTATUS Status
= STATUS_SUCCESS
;
214 RTL_PROCESS_INFO ProcessInfo
;
215 WCHAR ImagePath
[MAX_PATH
];
218 * Start the logon process (winlogon.exe)
221 DPRINT("SM: starting winlogon\n");
223 /* initialize executable path */
224 wcscpy(ImagePath
, L
"\\??\\");
225 wcscat(ImagePath
, SharedUserData
->NtSystemRoot
);
226 wcscat(ImagePath
, L
"\\system32\\winlogon.exe");
228 Status
= SmCreateUserProcess(ImagePath
,
232 FALSE
, /* terminate */
234 if (!NT_SUCCESS(Status
))
236 DPRINT("SM: %s: Loading winlogon.exe failed!\n", __FUNCTION__
);
237 NtTerminateProcess(Children
[CHILD_CSRSS
], 0);
241 Children
[CHILD_WINLOGON
] = ProcessInfo
.ProcessHandle
;