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;
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
45 /**********************************************************************
49 * Make smss register with itself for IMAGE_SUBSYSTEM_NATIVE
50 * (programmatically). This also opens hSmApiPort to be used
51 * in loading required subsystems.
57 NTSTATUS Status
= STATUS_SUCCESS
;
58 UNICODE_STRING SbApiPortName
= {0,0,NULL
};
61 DPRINT("SM: %s called\n",__FUNCTION__
);
63 RtlInitUnicodeString (& SbApiPortName
, L
"");
64 Status
= SmConnectApiPort(& SbApiPortName
,
65 (HANDLE
) -1, /* SM has no SB port */
66 IMAGE_SUBSYSTEM_NATIVE
,
68 if(!NT_SUCCESS(Status
))
70 DPRINT("SM: %s: SMLIB!SmConnectApiPort failed (Status=0x%08lx)\n",
74 DPRINT("SM self registered\n");
76 * Note that you don't need to call complete session
77 * because connection handling code autocompletes
78 * the client structure for IMAGE_SUBSYSTEM_NATIVE.
84 /**********************************************************************
85 * SmpLoadKernelModeSubsystem/0
88 SmpLoadKernelModeSubsystem (VOID
)
90 NTSTATUS Status
= STATUS_SUCCESS
;
91 WCHAR Data
[MAX_PATH
+ 1];
92 ULONG DataLength
= sizeof Data
;
96 DPRINT("SM: %s called\n", __FUNCTION__
);
98 Status
= SmLookupSubsystem (L
"Kmode",
103 if((STATUS_SUCCESS
== Status
) && (DataLength
> sizeof Data
[0]))
105 WCHAR ImagePath
[MAX_PATH
+ 1] = {0};
106 SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo
;
108 wcscpy (ImagePath
, L
"\\??\\");
109 wcscat (ImagePath
, Data
);
110 RtlZeroMemory (& ImageInfo
, sizeof ImageInfo
);
111 RtlInitUnicodeString (& ImageInfo
.ModuleName
, ImagePath
);
112 Status
= NtSetSystemInformation(SystemLoadAndCallImage
,
115 if(!NT_SUCCESS(Status
))
117 DPRINT("SM: %s: loading Kmode failed (Status=0x%08lx)\n",
118 __FUNCTION__
, Status
);
124 /**********************************************************************
125 * SmpLoadRequiredSubsystems/0
128 SmpLoadRequiredSubsystems (VOID
)
130 NTSTATUS Status
= STATUS_SUCCESS
;
131 WCHAR Data
[MAX_PATH
+ 1];
132 ULONG DataLength
= sizeof Data
;
136 DPRINT("SM: %s called\n", __FUNCTION__
);
138 RtlZeroMemory (Data
, DataLength
);
139 Status
= SmLookupSubsystem (L
"Required",
144 if((STATUS_SUCCESS
== Status
) && (DataLength
> sizeof Data
[0]))
149 for (Name
= Data
; (Offset
< DataLength
); )
153 UNICODE_STRING Program
;
155 /* Run the current program */
156 RtlInitUnicodeString (& Program
, Name
);
157 Status
= SmExecuteProgram (hSmApiPort
, & Program
);
158 if(!NT_SUCCESS(Status
))
160 DPRINT1("SM: %s failed to run '%S' program (Status=0x%08lx)\n",
161 __FUNCTION__
, Name
, Status
);
163 /* Look for the next program */
164 while ((L
'\0' != *Name
) && (Offset
< DataLength
))
178 /**********************************************************************
182 SmLoadSubsystems(VOID
)
184 NTSTATUS Status
= STATUS_SUCCESS
;
187 DPRINT("SM: loading subsystems\n");
189 /* SM self registers */
190 Status
= SmpRegisterSmss();
191 if(!NT_SUCCESS(Status
)) return Status
;
192 /* Load Kmode subsystem (aka win32k.sys) */
193 Status
= SmpLoadKernelModeSubsystem();
194 if(!NT_SUCCESS(Status
)) return Status
;
195 /* Load Required subsystems (Debug Windows) */
196 Status
= SmpLoadRequiredSubsystems();
197 if(!NT_SUCCESS(Status
)) return Status
;