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 RTL_PROCESS_INFO ProcessInfo
;
61 DPRINT("SM: %s called\n",__FUNCTION__
);
63 RtlZeroMemory (& ProcessInfo
, sizeof ProcessInfo
);
64 ProcessInfo
.Size
= sizeof ProcessInfo
;
65 ProcessInfo
.ProcessHandle
= (HANDLE
) SmSsProcessId
;
66 ProcessInfo
.ClientId
.UniqueProcess
= (HANDLE
) SmSsProcessId
;
67 DPRINT("SM: %s: ProcessInfo.ProcessHandle=%lx\n",
68 __FUNCTION__
,ProcessInfo
.ProcessHandle
);
69 Status
= SmCreateClient (& ProcessInfo
, L
"Session Manager");
70 if (NT_SUCCESS(Status
))
72 UNICODE_STRING SbApiPortName
= {0,0,NULL
};
74 RtlInitUnicodeString (& SbApiPortName
, L
"");
75 Status
= SmConnectApiPort(& SbApiPortName
,
76 (HANDLE
) -1, /* SM has no SB port */
77 IMAGE_SUBSYSTEM_NATIVE
,
79 if(!NT_SUCCESS(Status
))
81 DPRINT("SM: %s: SMLIB!SmConnectApiPort failed (Status=0x%08lx)\n",
85 DPRINT("SM self registered\n");
89 DPRINT1("SM: %s: SmCreateClient failed (Status=0x%08lx)\n",
90 __FUNCTION__
, Status
);
93 * Note that you don't need to call complete session
94 * because connection handling code autocompletes
95 * the client structure for IMAGE_SUBSYSTEM_NATIVE.
101 /**********************************************************************
102 * SmpLoadRequiredSubsystems/0
105 SmpLoadRequiredSubsystems (VOID
)
107 NTSTATUS Status
= STATUS_SUCCESS
;
108 WCHAR Data
[MAX_PATH
+ 1];
109 ULONG DataLength
= sizeof Data
;
113 DPRINT("SM: %s called\n", __FUNCTION__
);
115 RtlZeroMemory (Data
, DataLength
);
116 Status
= SmLookupSubsystem (L
"Required",
121 if((STATUS_SUCCESS
== Status
) && (DataLength
> sizeof Data
[0]))
126 for (Name
= Data
; (Offset
< DataLength
); )
130 UNICODE_STRING Program
;
132 /* Run the current program */
133 RtlInitUnicodeString (& Program
, Name
);
134 Status
= SmExecuteProgram (hSmApiPort
, & Program
);
135 if(!NT_SUCCESS(Status
))
137 DPRINT1("SM: %s failed to run '%S' program (Status=0x%08lx)\n",
138 __FUNCTION__
, Name
, Status
);
140 /* Look for the next program */
141 while ((L
'\0' != *Name
) && (Offset
< DataLength
))
155 /**********************************************************************
159 SmLoadSubsystems(VOID
)
161 NTSTATUS Status
= STATUS_SUCCESS
;
164 DPRINT("SM: loading subsystems\n");
166 /* SM self registers */
167 Status
= SmpRegisterSmss();
168 if(!NT_SUCCESS(Status
)) return Status
;
169 /* Load Required subsystems (Debug Windows) */
170 Status
= SmpLoadRequiredSubsystems();
171 if(!NT_SUCCESS(Status
)) return Status
;