ReactOS 0.4.16-dev-122-g325d74c
smss.c File Reference
#include "smss.h"
#include <pseh/pseh2.h>
#include <debug.h>
Include dependency graph for smss.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI SmpExecuteImage (IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, IN ULONG Flags, IN PRTL_USER_PROCESS_INFORMATION ProcessInformation)
 
NTSTATUS NTAPI SmpInvokeAutoChk (IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING Arguments, IN ULONG Flags)
 
NTSTATUS NTAPI SmpExecuteCommand (IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, OUT PHANDLE ProcessId, IN ULONG Flags)
 
NTSTATUS NTAPI SmpExecuteInitialCommand (IN ULONG MuSessionId, IN PUNICODE_STRING InitialCommand, IN HANDLE InitialCommandProcess, OUT PHANDLE ReturnPid)
 
NTSTATUS NTAPI SmpTerminate (IN PULONG_PTR Parameters, IN ULONG ParameterMask, IN ULONG ParameterCount)
 
LONG SmpUnhandledExceptionFilter (IN PEXCEPTION_POINTERS ExceptionInfo)
 
NTSTATUS __cdecl _main (IN INT argc, IN PCHAR argv[], IN PCHAR envp[], IN ULONG DebugFlag)
 

Variables

UNICODE_STRING SmpSystemRoot
 
ULONG AttachedSessionId = -1
 
BOOLEAN SmpDebug
 
BOOLEAN SmpEnableDots
 
HANDLE SmApiPort
 
HANDLE SmpInitialCommandProcessId
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file smss.c.

Function Documentation

◆ _main()

NTSTATUS __cdecl _main ( IN INT  argc,
IN PCHAR  argv[],
IN PCHAR  envp[],
IN ULONG  DebugFlag 
)

Definition at line 432 of file smss.c.

436{
438 KPRIORITY SetBasePriority;
440 HANDLE Handles[2];
441 PVOID State;
442 ULONG Flags;
443 PROCESS_BASIC_INFORMATION ProcessInfo;
444 UNICODE_STRING DbgString, InitialCommand;
445
446 /* Make us critical */
449
450 /* Raise our priority */
451 SetBasePriority = 11;
454 (PVOID)&SetBasePriority,
455 sizeof(SetBasePriority));
457
458 /* Save the debug flag if it was passed */
459 if (DebugFlag) SmpDebug = DebugFlag != 0;
460
461 /* Build the hard error parameters */
462 Parameters[0] = (ULONG_PTR)&DbgString;
463 Parameters[1] = Parameters[2] = Parameters[3] = 0;
464
465 /* Enter SEH so we can terminate correctly if anything goes wrong */
467 {
468 /* Initialize SMSS */
469 Status = SmpInit(&InitialCommand, &Handles[0]);
470 if (!NT_SUCCESS(Status))
471 {
472 DPRINT1("SMSS: SmpInit return failure - Status == %x\n", Status);
473 RtlInitUnicodeString(&DbgString, L"Session Manager Initialization");
474 Parameters[1] = Status;
476 }
477
478 /* Get the global flags */
480 &Flags,
481 sizeof(Flags),
482 NULL);
484
485 /* Before executing the initial command check if the debug flag is on */
487 {
488 /* SMSS should launch ntsd with a few parameters at this point */
489 DPRINT1("Global Flags Set to SMSS Debugging: Not yet supported\n");
490 }
491
492 /* Execute the initial command (Winlogon.exe) */
493 Status = SmpExecuteInitialCommand(0, &InitialCommand, &Handles[1], NULL);
494 if (!NT_SUCCESS(Status))
495 {
496 /* Fail and raise a hard error */
497 DPRINT1("SMSS: Execute Initial Command failed\n");
498 RtlInitUnicodeString(&DbgString,
499 L"Session Manager ExecuteInitialCommand");
500 Parameters[1] = Status;
502 }
503
504 /* Check if we're already attached to a session */
506 if (AttachedSessionId != -1)
507 {
508 /* Detach from it, we should be in no session right now */
511 sizeof(AttachedSessionId));
514 }
516
517 /* Wait on either CSRSS or Winlogon to die */
519 Handles,
520 WaitAny,
521 FALSE,
522 NULL);
523 if (Status == STATUS_WAIT_0)
524 {
525 /* CSRSS is dead, get exit code and prepare for the hard error */
526 RtlInitUnicodeString(&DbgString, L"Windows SubSystem");
529 &ProcessInfo,
530 sizeof(ProcessInfo),
531 NULL);
532 DPRINT1("SMSS: Windows subsystem terminated when it wasn't supposed to.\n");
533 }
534 else
535 {
536 /* The initial command is dead or we have another failure */
537 RtlInitUnicodeString(&DbgString, L"Windows Logon Process");
538 if (Status == STATUS_WAIT_1)
539 {
540 /* Winlogon.exe got terminated, get its exit code */
543 &ProcessInfo,
544 sizeof(ProcessInfo),
545 NULL);
546 }
547 else
548 {
549 /* Something else satisfied our wait, so set the wait status */
550 ProcessInfo.ExitStatus = Status;
552 }
553 DPRINT1("SMSS: Initial command '%wZ' terminated when it wasn't supposed to.\n",
554 &InitialCommand);
555 }
556
557 /* Check if NtQueryInformationProcess was successful */
558 if (NT_SUCCESS(Status))
559 {
560 /* Then we must have a valid exit status in the structure, use it */
561 Parameters[1] = ProcessInfo.ExitStatus;
562 }
563 else
564 {
565 /* We really don't know what happened, so set a generic error */
567 }
568 }
570 {
571 /* The filter should never return here */
572 ASSERT(FALSE);
573 }
574 _SEH2_END;
575
576 /* Something in the init loop failed, terminate SMSS */
578}
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
ULONG DebugFlag
Definition: fxobject.cpp:44
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
LONG KPRIORITY
Definition: compat.h:803
#define ULONG_PTR
Definition: config.h:101
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define _SEH2_LEAVE
Definition: filesup.c:20
@ SystemFlagsInformation
Definition: ntddk_ex.h:20
Status
Definition: gdiplustypes.h:25
#define FLG_DEBUG_INITIAL_COMMAND
Definition: pstypes.h:58
#define FLG_DEBUG_INITIAL_COMMAND_EX
Definition: pstypes.h:85
@ ProcessBasicInformation
Definition: winternl.h:394
@ ProcessBasePriority
Definition: winternl.h:861
#define ASSERT(a)
Definition: mode.c:44
#define SE_LOAD_DRIVER_PRIVILEGE
Definition: security.c:664
@ SystemSessionDetach
Definition: extypes.h:265
NTSYSAPI NTSTATUS __cdecl RtlSetThreadIsCritical(_In_ BOOLEAN NewValue, _Out_opt_ PBOOLEAN OldValue, _In_ BOOLEAN NeedBreaks)
NTSYSAPI NTSTATUS __cdecl RtlSetProcessIsCritical(_In_ BOOLEAN NewValue, _Out_opt_ PBOOLEAN OldValue, _In_ BOOLEAN NeedBreaks)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NtCurrentProcess()
Definition: nt_native.h:1657
@ WaitAny
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI NtWaitForMultipleObjects(IN ULONG ObjectCount, IN PHANDLE HandleArray, IN WAIT_TYPE WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER TimeOut OPTIONAL)
Definition: obwait.c:46
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:164
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI SmpInit(IN PUNICODE_STRING InitialCommand, OUT PHANDLE ProcessHandle)
Definition: sminit.c:2449
BOOLEAN SmpDebug
Definition: smss.c:22
NTSTATUS NTAPI SmpTerminate(IN PULONG_PTR Parameters, IN ULONG ParameterMask, IN ULONG ParameterCount)
Definition: smss.c:374
NTSTATUS NTAPI SmpExecuteInitialCommand(IN ULONG MuSessionId, IN PUNICODE_STRING InitialCommand, IN HANDLE InitialCommandProcess, OUT PHANDLE ReturnPid)
Definition: smss.c:283
ULONG AttachedSessionId
Definition: smss.c:21
LONG SmpUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: smss.c:403
VOID NTAPI SmpReleasePrivilege(IN PVOID State)
Definition: smutil.c:129
NTSTATUS NTAPI SmpAcquirePrivilege(IN ULONG Privilege, OUT PVOID *PrivilegeStat)
Definition: smutil.c:40
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ SmpExecuteCommand()

NTSTATUS NTAPI SmpExecuteCommand ( IN PUNICODE_STRING  CommandLine,
IN ULONG  MuSessionId,
OUT PHANDLE  ProcessId,
IN ULONG  Flags 
)

Definition at line 210 of file smss.c.

214{
217
218 /* There's no longer a debugging subsystem */
219 if (Flags & SMP_DEBUG_FLAG) return STATUS_SUCCESS;
220
221 /* Parse the command line to see what execution flags are requested */
222 Status = SmpParseCommandLine(CommandLine,
223 &Flags,
224 &FileName,
225 &Directory,
226 &Arguments);
227 if (!NT_SUCCESS(Status))
228 {
229 /* Fail if we couldn't do that */
230 DPRINT1("SMSS: SmpParseCommandLine( %wZ ) failed - Status == %lx\n",
231 CommandLine, Status);
232 return Status;
233 }
234
235 /* Check if autochk is requested */
237 {
238 /* Run it */
240 }
241 else if (Flags & SMP_SUBSYSTEM_FLAG)
242 {
244 &Directory,
245 CommandLine,
246 MuSessionId,
247 ProcessId,
248 Flags);
249 }
250 else if (Flags & SMP_INVALID_PATH)
251 {
252 /* An invalid image was specified, fail */
253 DPRINT1("SMSS: Image file (%wZ) not found\n", &FileName);
255 }
256 else
257 {
258 /* An actual image name was present, execute it */
260 &Directory,
261 CommandLine,
262 MuSessionId,
263 Flags,
264 NULL);
265 }
266
267 /* Free all the token parameters */
268 if (FileName.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, FileName.Buffer);
269 if (Directory.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Directory.Buffer);
270 if (Arguments.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Arguments.Buffer);
271
272 /* Return to the caller */
273 if (!NT_SUCCESS(Status))
274 {
275 DPRINT1("SMSS: Command '%wZ' failed - Status == %x\n",
276 CommandLine, Status);
277 }
278 return Status;
279}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2712
struct _FileName FileName
Definition: fatprocs.h:897
NTSTATUS NTAPI SmpExecuteImage(IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, IN ULONG Flags, IN PRTL_USER_PROCESS_INFORMATION ProcessInformation)
Definition: smss.c:30
NTSTATUS NTAPI SmpInvokeAutoChk(IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING Arguments, IN ULONG Flags)
Definition: smss.c:149
#define SMP_AUTOCHK_FLAG
Definition: smss.h:46
NTSTATUS NTAPI SmpParseCommandLine(IN PUNICODE_STRING CommandLine, OUT PULONG Flags, OUT PUNICODE_STRING FileName, OUT PUNICODE_STRING Directory, OUT PUNICODE_STRING Arguments)
Definition: smutil.c:233
NTSTATUS NTAPI SmpLoadSubSystem(IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, OUT PHANDLE ProcessId, IN ULONG Flags)
Definition: smsubsys.c:138
#define SMP_DEBUG_FLAG
Definition: smss.h:44
#define SMP_INVALID_PATH
Definition: smss.h:48
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:47
base for all directory entries
Definition: entries.h:138
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by SmpLoadDataFromRegistry(), SmpLoadDeferedSubsystem(), and SmpLoadSubSystemsForMuSession().

◆ SmpExecuteImage()

NTSTATUS NTAPI SmpExecuteImage ( IN PUNICODE_STRING  FileName,
IN PUNICODE_STRING  Directory,
IN PUNICODE_STRING  CommandLine,
IN ULONG  MuSessionId,
IN ULONG  Flags,
IN PRTL_USER_PROCESS_INFORMATION  ProcessInformation 
)

Definition at line 30 of file smss.c.

36{
39 RTL_USER_PROCESS_INFORMATION LocalProcessInfo;
40 PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
41
42 /* Use the input process information if we have it, otherwise use local */
43 ProcessInfo = ProcessInformation;
44 if (!ProcessInfo) ProcessInfo = &LocalProcessInfo;
45
46 /* Create parameters for the target process */
47 Status = RtlCreateProcessParameters(&ProcessParameters,
52 CommandLine,
54 NULL,
55 NULL,
56 NULL,
57 0);
58 if (!NT_SUCCESS(Status))
59 {
60 /* This is a pretty bad failure. ASSERT on checked builds and exit */
61 ASSERTMSG("RtlCreateProcessParameters failed.\n", NT_SUCCESS(Status));
62 DPRINT1("SMSS: RtlCreateProcessParameters failed for %wZ - Status == %lx\n",
64 return Status;
65 }
66
67 /* Set the size field as required */
68 ProcessInfo->Size = sizeof(*ProcessInfo);
69
70 /* Check if the debug flag was requested */
72 {
73 /* Write it in the process parameters */
74 ProcessParameters->DebugFlags = 1;
75 }
76 else
77 {
78 /* Otherwise inherit the flag that was passed to SMSS itself */
79 ProcessParameters->DebugFlags = SmpDebug;
80 }
81
82 /* Subsystems get the first 1MB of memory reserved for DOS/IVT purposes */
84 {
86 }
87
88 /* And always force NX for anything that SMSS launches */
89 ProcessParameters->Flags |= RTL_USER_PROCESS_PARAMETERS_NX;
90
91 /* Now create the process in suspended state */
94 ProcessParameters,
95 NULL,
96 NULL,
97 NULL,
98 FALSE,
99 NULL,
100 NULL,
101 ProcessInfo);
102 RtlDestroyProcessParameters(ProcessParameters);
103 if (!NT_SUCCESS(Status))
104 {
105 /* If we couldn't create it, fail back to the caller */
106 DPRINT1("SMSS: Failed load of %wZ - Status == %lx\n",
108 return Status;
109 }
110
111 /* Associate a session with this process */
112 Status = SmpSetProcessMuSessionId(ProcessInfo->ProcessHandle, MuSessionId);
113
114 /* If the application is deferred (suspended), there's nothing to do */
115 if (Flags & SMP_DEFERRED_FLAG) return Status;
116
117 /* Otherwise, get ready to start it, but make sure it's a native app */
119 {
120 /* Resume it */
121 NtResumeThread(ProcessInfo->ThreadHandle, NULL);
122 if (!(Flags & SMP_ASYNC_FLAG))
123 {
124 /* Block on it unless Async was requested */
126 }
127
128 /* It's up and running now, close our handles */
129 NtClose(ProcessInfo->ThreadHandle);
130 NtClose(ProcessInfo->ProcessHandle);
131 }
132 else
133 {
134 /* This image is invalid, so kill it, close our handles, and fail */
138 NtClose(ProcessInfo->ThreadHandle);
139 NtClose(ProcessInfo->ProcessHandle);
140 DPRINT1("SMSS: Not an NT image - %wZ\n", FileName);
141 }
142
143 /* Return the outcome of the process create */
144 return Status;
145}
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI RtlDestroyProcessParameters(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
NTSYSAPI NTSTATUS NTAPI RtlCreateProcessParameters(_Out_ PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, _In_ PUNICODE_STRING ImagePathName, _In_opt_ PUNICODE_STRING DllPath, _In_opt_ PUNICODE_STRING CurrentDirectory, _In_opt_ PUNICODE_STRING CommandLine, _In_opt_ PWSTR Environment, _In_opt_ PUNICODE_STRING WindowTitle, _In_opt_ PUNICODE_STRING DesktopInfo, _In_opt_ PUNICODE_STRING ShellInfo, _In_opt_ PUNICODE_STRING RuntimeInfo)
NTSYSAPI NTSTATUS NTAPI RtlCreateUserProcess(_In_ PUNICODE_STRING ImageFileName, _In_ ULONG Attributes, _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters, _In_opt_ PSECURITY_DESCRIPTOR ProcessSecutityDescriptor, _In_opt_ PSECURITY_DESCRIPTOR ThreadSecurityDescriptor, _In_opt_ HANDLE ParentProcess, _In_ BOOLEAN CurrentDirectory, _In_opt_ HANDLE DebugPort, _In_opt_ HANDLE ExceptionPort, _Out_ PRTL_USER_PROCESS_INFORMATION ProcessInfo)
#define RTL_USER_PROCESS_PARAMETERS_NX
Definition: rtltypes.h:55
#define RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB
Definition: rtltypes.h:46
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
UNICODE_STRING SmpDefaultLibPath
Definition: sminit.c:29
PWCHAR SmpDefaultEnvironment
Definition: sminit.c:28
NTSTATUS NTAPI SmpSetProcessMuSessionId(IN HANDLE ProcessHandle, IN ULONG SessionId)
Definition: smsessn.c:199
#define SMP_DEFERRED_FLAG
Definition: smss.h:49
#define SMP_ASYNC_FLAG
Definition: smss.h:45
SECTION_IMAGE_INFORMATION ImageInformation
Definition: rtltypes.h:1573

Referenced by SmpExecuteCommand(), SmpExecuteInitialCommand(), SmpInvokeAutoChk(), and SmpLoadSubSystem().

◆ SmpExecuteInitialCommand()

NTSTATUS NTAPI SmpExecuteInitialCommand ( IN ULONG  MuSessionId,
IN PUNICODE_STRING  InitialCommand,
IN HANDLE  InitialCommandProcess,
OUT PHANDLE  ReturnPid 
)

Definition at line 283 of file smss.c.

287{
291 ULONG Flags = 0;
292
293 /* Check if we haven't yet connected to ourselves */
294 if (!SmApiPort)
295 {
296 /* Connect to ourselves, as a client */
298 if (!NT_SUCCESS(Status))
299 {
300 DPRINT1("SMSS: Unable to connect to SM - Status == %lx\n", Status);
301 return Status;
302 }
303 }
304
305 /* Parse the initial command line */
306 Status = SmpParseCommandLine(InitialCommand,
307 &Flags,
308 &FileName,
309 &Directory,
310 &Arguments);
312 {
313 /* Fail if it doesn't exist */
314 DPRINT1("SMSS: Initial command image (%wZ) not found\n", &FileName);
315 if (FileName.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, FileName.Buffer);
317 }
318
319 /* And fail if any other reason is also true */
320 if (!NT_SUCCESS(Status))
321 {
322 DPRINT1("SMSS: SmpParseCommandLine( %wZ ) failed - Status == %lx\n",
323 InitialCommand, Status);
324 return Status;
325 }
326
327 /* Execute the initial command, but defer its full execution */
329 &Directory,
330 InitialCommand,
331 MuSessionId,
333 &ProcessInfo);
334
335 /* Free all the token parameters */
336 if (FileName.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, FileName.Buffer);
337 if (Directory.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Directory.Buffer);
338 if (Arguments.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Arguments.Buffer);
339
340 /* Bail out if we couldn't execute the initial command */
341 if (!NT_SUCCESS(Status)) return Status;
342
343 /* Now duplicate the handle to this process */
345 ProcessInfo.ProcessHandle,
347 InitialCommandProcess,
349 0,
350 0);
351 if (!NT_SUCCESS(Status))
352 {
353 /* Kill it utterly if duplication failed */
354 DPRINT1("SMSS: DupObject Failed. Status == %lx\n", Status);
356 NtResumeThread(ProcessInfo.ThreadHandle, NULL);
357 NtClose(ProcessInfo.ThreadHandle);
358 NtClose(ProcessInfo.ProcessHandle);
359 return Status;
360 }
361
362 /* Return PID to the caller, and set this as the initial command PID */
363 if (ReturnPid) *ReturnPid = ProcessInfo.ClientId.UniqueProcess;
364 if (!MuSessionId) SmpInitialCommandProcessId = ProcessInfo.ClientId.UniqueProcess;
365
366 /* Now call our server execution function to wrap up its initialization */
367 Status = SmExecPgm(SmApiPort, &ProcessInfo, FALSE);
368 if (!NT_SUCCESS(Status)) DPRINT1("SMSS: SmExecPgm Failed. Status == %lx\n", Status);
369 return Status;
370}
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3410
NTSTATUS NTAPI SmConnectToSm(_In_opt_ PUNICODE_STRING SbApiPortName, _In_opt_ HANDLE SbApiPort, _In_opt_ ULONG ImageType, _Out_ PHANDLE SmApiPort)
Connects to the SM API port for registering a session callback port (Sb) associated to a subsystem,...
Definition: smclient.c:57
NTSTATUS NTAPI SmExecPgm(_In_ HANDLE SmApiPort, _In_ PRTL_USER_PROCESS_INFORMATION ProcessInformation, _In_ BOOLEAN DebugFlag)
Requests the SM to start a process under a new environment session.
Definition: smclient.c:265
HANDLE SmpInitialCommandProcessId
Definition: smss.c:24
HANDLE SmApiPort
Definition: smss.c:23
HANDLE UniqueProcess
Definition: compat.h:825

Referenced by _main(), and SmpStartCsr().

◆ SmpInvokeAutoChk()

NTSTATUS NTAPI SmpInvokeAutoChk ( IN PUNICODE_STRING  FileName,
IN PUNICODE_STRING  Directory,
IN PUNICODE_STRING  Arguments,
IN ULONG  Flags 
)

Definition at line 149 of file smss.c.

153{
154 ANSI_STRING MessageString;
155 CHAR MessageBuffer[256];
157 WCHAR Buffer[1024];
158 BOOLEAN BootState, BootOkay, ShutdownOkay;
159
160 /* Check if autochk should show dots (if the user booted with /SOS) */
162
163 /* Make sure autochk was actually found */
165 {
166 /* It wasn't, so create an error message to print on the screen */
167 RtlStringCbPrintfA(MessageBuffer,
168 sizeof(MessageBuffer),
169 "%wZ program not found - skipping AUTOCHECK\r\n",
170 FileName);
171 RtlInitAnsiString(&MessageString, MessageBuffer);
173 &MessageString,
174 TRUE)))
175 {
176 /* And show it */
179 }
180 }
181 else
182 {
183 /* Autochk is there, so record the BSD state */
184 BootState = SmpSaveAndClearBootStatusData(&BootOkay, &ShutdownOkay);
185
186 /* Build the path to autochk and place its arguments */
187 RtlInitEmptyUnicodeString(&Destination, Buffer, sizeof(Buffer));
191
192 /* Execute it */
194 Directory,
196 0,
198 NULL);
199
200 /* Restore the BSD state */
201 if (BootState) SmpRestoreBootStatusData(BootOkay, ShutdownOkay);
202 }
203
204 /* We're all done! */
205 return STATUS_SUCCESS;
206}
unsigned char BOOLEAN
Definition: bufpool.h:45
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3016
NTSTATUS NTAPI NtDisplayString(PUNICODE_STRING String)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
BOOLEAN SmpEnableDots
Definition: smss.c:22
BOOLEAN NTAPI SmpQueryRegistrySosOption(VOID)
Definition: smutil.c:424
BOOLEAN NTAPI SmpSaveAndClearBootStatusData(OUT PBOOLEAN BootOkay, OUT PBOOLEAN ShutdownOkay)
Definition: smutil.c:481
VOID NTAPI SmpRestoreBootStatusData(IN BOOLEAN BootOkay, IN BOOLEAN ShutdownOkay)
Definition: smutil.c:531
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by SmpExecuteCommand().

◆ SmpTerminate()

NTSTATUS NTAPI SmpTerminate ( IN PULONG_PTR  Parameters,
IN ULONG  ParameterMask,
IN ULONG  ParameterCount 
)

Definition at line 374 of file smss.c.

377{
379 BOOLEAN Old;
381
382 /* Give the shutdown privilege to the thread */
385 {
386 /* Thread doesn't have a token, give it to the entire process */
388 }
389
390 /* Take down the process/machine with a hard error */
392 ParameterCount,
393 ParameterMask,
396 &Response);
397
398 /* Terminate the process if the hard error didn't already */
400}
NTSTATUS NTAPI NtRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:551
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
@ OptionShutdownSystem
Definition: extypes.h:192
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
#define STATUS_SYSTEM_PROCESS_TERMINATED
Definition: ntstatus.h:670
Definition: ncftp.h:89

Referenced by _main(), SmpInitializeKnownDllsInternal(), and SmpUnhandledExceptionFilter().

◆ SmpUnhandledExceptionFilter()

LONG SmpUnhandledExceptionFilter ( IN PEXCEPTION_POINTERS  ExceptionInfo)

Definition at line 403 of file smss.c.

404{
406 UNICODE_STRING ErrorString;
407
408 /* Print and breakpoint into the debugger */
409 DbgPrint("SMSS: Unhandled exception - Status == %x IP == %p\n",
410 ExceptionInfo->ExceptionRecord->ExceptionCode,
411 ExceptionInfo->ExceptionRecord->ExceptionAddress);
412 DbgPrint(" Memory Address: %x Read/Write: %x\n",
413 ExceptionInfo->ExceptionRecord->ExceptionInformation[0],
414 ExceptionInfo->ExceptionRecord->ExceptionInformation[1]);
416
417 /* Build the hard error and terminate */
418 RtlInitUnicodeString(&ErrorString, L"Unhandled Exception in Session Manager");
419 Parameters[0] = (ULONG_PTR)&ErrorString;
420 Parameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
421 Parameters[2] = (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress;
422 Parameters[3] = (ULONG_PTR)ExceptionInfo->ContextRecord;
424
425 /* We should never get here */
426 ASSERT(FALSE);
428}
#define DbgPrint
Definition: hal.h:12
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSYSAPI void WINAPI DbgBreakPoint(void)

Referenced by _main().

Variable Documentation

◆ AttachedSessionId

ULONG AttachedSessionId = -1

Definition at line 21 of file smss.c.

Referenced by _main(), SmpLoadSubSystem(), and SmpLoadSubSystemsForMuSession().

◆ SmApiPort

◆ SmpDebug

BOOLEAN SmpDebug

Definition at line 22 of file smss.c.

Referenced by _main(), SmpExecuteImage(), and SmpLoadSubSystem().

◆ SmpEnableDots

BOOLEAN SmpEnableDots

Definition at line 22 of file smss.c.

Referenced by SmpInvokeAutoChk().

◆ SmpInitialCommandProcessId

HANDLE SmpInitialCommandProcessId

Definition at line 24 of file smss.c.

Referenced by SmpExecuteInitialCommand().

◆ SmpSystemRoot

UNICODE_STRING SmpSystemRoot

Definition at line 20 of file smss.c.

Referenced by SmpParseCommandLine().