ReactOS  0.4.15-dev-1377-ga59cecd
smss.h File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <ndk/iofuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/rtlfuncs.h>
#include <ndk/cmfuncs.h>
#include <ndk/exfuncs.h>
#include <ndk/mmfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/lpcfuncs.h>
#include <ndk/setypes.h>
#include <ndk/umfuncs.h>
#include <ndk/kefuncs.h>
#include <ntstrsafe.h>
#include <sm/smmsg.h>
Include dependency graph for smss.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SMP_REGISTRY_VALUE
 
struct  _SMP_SUBSYSTEM
 

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define SMP_DEBUG_FLAG   0x01
 
#define SMP_ASYNC_FLAG   0x02
 
#define SMP_AUTOCHK_FLAG   0x04
 
#define SMP_SUBSYSTEM_FLAG   0x08
 
#define SMP_INVALID_PATH   0x10
 
#define SMP_DEFERRED_FLAG   0x20
 
#define SMP_POSIX_FLAG   0x100
 
#define SMP_OS2_FLAG   0x200
 

Typedefs

typedef struct _SMP_REGISTRY_VALUE SMP_REGISTRY_VALUE
 
typedef struct _SMP_REGISTRY_VALUEPSMP_REGISTRY_VALUE
 
typedef struct _SMP_SUBSYSTEM SMP_SUBSYSTEM
 
typedef struct _SMP_SUBSYSTEMPSMP_SUBSYSTEM
 

Functions

NTSTATUS NTAPI SmpTerminate (IN PULONG_PTR Parameters, IN ULONG ParameterMask, IN ULONG ParameterCount)
 
NTSTATUS NTAPI SmpCreateSecurityDescriptors (IN BOOLEAN InitialCall)
 
NTSTATUS NTAPI SmpInit (IN PUNICODE_STRING InitialCommand, OUT PHANDLE ProcessHandle)
 
NTSTATUS NTAPI SmpAcquirePrivilege (IN ULONG Privilege, OUT PVOID *PrivilegeStat)
 
VOID NTAPI SmpReleasePrivilege (IN PVOID State)
 
ULONG NTAPI SmpApiLoop (IN PVOID Parameter)
 
NTSTATUS NTAPI SmpExecuteCommand (IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, OUT PHANDLE ProcessId, IN ULONG Flags)
 
NTSTATUS NTAPI SmpLoadSubSystemsForMuSession (IN PULONG MuSessionId, OUT PHANDLE ProcessId, IN PUNICODE_STRING InitialCommand)
 
VOID NTAPI SmpPagingFileInitialize (VOID)
 
NTSTATUS NTAPI SmpCreatePagingFileDescriptor (IN PUNICODE_STRING PageFileToken)
 
NTSTATUS NTAPI SmpCreatePagingFiles (VOID)
 
NTSTATUS NTAPI SmpParseCommandLine (IN PUNICODE_STRING CommandLine, OUT PULONG Flags, OUT PUNICODE_STRING FileName, OUT PUNICODE_STRING Directory, OUT PUNICODE_STRING Arguments)
 
NTSTATUS NTAPI SmpLoadSubSystem (IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, OUT PHANDLE ProcessId, IN ULONG Flags)
 
NTSTATUS NTAPI SmpSetProcessMuSessionId (IN HANDLE ProcessHandle, IN ULONG SessionId)
 
BOOLEAN NTAPI SmpQueryRegistrySosOption (VOID)
 
BOOLEAN NTAPI SmpSaveAndClearBootStatusData (OUT PBOOLEAN BootOkay, OUT PBOOLEAN ShutdownOkay)
 
VOID NTAPI SmpRestoreBootStatusData (IN BOOLEAN BootOkay, IN BOOLEAN ShutdownOkay)
 
BOOLEAN NTAPI SmpCheckForCrashDump (IN PUNICODE_STRING FileName)
 
VOID NTAPI SmpTranslateSystemPartitionInformation (VOID)
 
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByCid (IN PCLIENT_ID ClientId)
 
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType (IN ULONG MuSessionId, IN ULONG ImageType)
 
NTSTATUS NTAPI SmpGetProcessMuSessionId (IN HANDLE ProcessHandle, OUT PULONG SessionId)
 
VOID NTAPI SmpDereferenceSubsystem (IN PSMP_SUBSYSTEM SubSystem)
 
NTSTATUS NTAPI SmpSbCreateSession (IN PVOID Reserved, IN PSMP_SUBSYSTEM OtherSubsystem, IN PRTL_USER_PROCESS_INFORMATION ProcessInformation, IN ULONG MuSessionId, IN PCLIENT_ID DbgClientId)
 
ULONG NTAPI SmpAllocateSessionId (IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
 
VOID NTAPI SmpDeleteSession (IN ULONG SessionId)
 
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId (IN ULONG MuSessionId)
 
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)
 

Variables

RTL_CRITICAL_SECTION SmpKnownSubSysLock
 
LIST_ENTRY SmpKnownSubSysHead
 
RTL_CRITICAL_SECTION SmpSessionListLock
 
LIST_ENTRY SmpSessionListHead
 
ULONG SmpNextSessionId
 
ULONG SmpNextSessionIdScanMode
 
BOOLEAN SmpDbgSsLoaded
 
HANDLE SmpWindowsSubSysProcess
 
HANDLE SmpSessionsObjectDirectory
 
HANDLE SmpWindowsSubSysProcessId
 
BOOLEAN RegPosixSingleInstance
 
UNICODE_STRING SmpDebugKeyword
 
UNICODE_STRING SmpASyncKeyword
 
UNICODE_STRING SmpAutoChkKeyword
 
PVOID SmpHeap
 
ULONG SmBaseTag
 
UNICODE_STRING SmpSystemRoot
 
PWCHAR SmpDefaultEnvironment
 
UNICODE_STRING SmpDefaultLibPath
 
LIST_ENTRY SmpSetupExecuteList
 
LIST_ENTRY SmpSubSystemsToLoad
 
LIST_ENTRY SmpExecuteList
 
LIST_ENTRY SmpSubSystemList
 
ULONG AttachedSessionId
 
BOOLEAN SmpDebug
 

Macro Definition Documentation

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 21 of file smss.h.

◆ SMP_ASYNC_FLAG

#define SMP_ASYNC_FLAG   0x02

Definition at line 42 of file smss.h.

◆ SMP_AUTOCHK_FLAG

#define SMP_AUTOCHK_FLAG   0x04

Definition at line 43 of file smss.h.

◆ SMP_DEBUG_FLAG

#define SMP_DEBUG_FLAG   0x01

Definition at line 41 of file smss.h.

◆ SMP_DEFERRED_FLAG

#define SMP_DEFERRED_FLAG   0x20

Definition at line 46 of file smss.h.

◆ SMP_INVALID_PATH

#define SMP_INVALID_PATH   0x10

Definition at line 45 of file smss.h.

◆ SMP_OS2_FLAG

#define SMP_OS2_FLAG   0x200

Definition at line 48 of file smss.h.

◆ SMP_POSIX_FLAG

#define SMP_POSIX_FLAG   0x100

Definition at line 47 of file smss.h.

◆ SMP_SUBSYSTEM_FLAG

#define SMP_SUBSYSTEM_FLAG   0x08

Definition at line 44 of file smss.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 16 of file smss.h.

Typedef Documentation

◆ PSMP_REGISTRY_VALUE

◆ PSMP_SUBSYSTEM

◆ SMP_REGISTRY_VALUE

◆ SMP_SUBSYSTEM

Function Documentation

◆ SmpAcquirePrivilege()

NTSTATUS NTAPI SmpAcquirePrivilege ( IN ULONG  Privilege,
OUT PVOID PrivilegeStat 
)

Definition at line 40 of file smutil.c.

42 {
44  ULONG Size;
46 
47  /* Assume failure */
48  *PrivilegeState = NULL;
49 
50  /* Acquire the state structure to hold everything we need */
52  0,
53  sizeof(SMP_PRIVILEGE_STATE) +
54  sizeof(TOKEN_PRIVILEGES) +
55  sizeof(LUID_AND_ATTRIBUTES));
56  if (!State) return STATUS_NO_MEMORY;
57 
58  /* Open our token */
61  &State->TokenHandle);
62  if (!NT_SUCCESS(Status))
63  {
64  /* Fail */
66  return Status;
67  }
68 
69  /* Set one privilege in the enabled state */
70  State->NewPrivileges = &State->NewBuffer;
71  State->OldPrivileges = (PTOKEN_PRIVILEGES)&State->OldBuffer;
72  State->NewPrivileges->PrivilegeCount = 1;
73  State->NewPrivileges->Privileges[0].Luid = RtlConvertUlongToLuid(Privilege);
74  State->NewPrivileges->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
75 
76  /* Adjust the privileges in the token */
77  Size = sizeof(State->OldBuffer);
78  Status = NtAdjustPrivilegesToken(State->TokenHandle,
79  FALSE,
80  State->NewPrivileges,
81  Size,
82  State->OldPrivileges,
83  &Size);
85  {
86  /* Our static buffer is not big enough, allocate a bigger one */
87  State->OldPrivileges = RtlAllocateHeap(SmpHeap, 0, Size);
88  if (!State->OldPrivileges)
89  {
90  /* Out of memory, fail */
92  goto Quickie;
93  }
94 
95  /* Now try again */
96  Status = NtAdjustPrivilegesToken(State->TokenHandle,
97  FALSE,
98  State->NewPrivileges,
99  Size,
100  State->OldPrivileges,
101  &Size);
102  }
103 
104  /* Normalize failure code and check for success */
106  if (NT_SUCCESS(Status))
107  {
108  /* We got the privilege, return */
109  *PrivilegeState = State;
110  return STATUS_SUCCESS;
111  }
112 
113 Quickie:
114  /* Check if we used a dynamic buffer */
115  if (State->OldPrivileges != (PTOKEN_PRIVILEGES)&State->OldBuffer)
116  {
117  /* Free it */
118  RtlFreeHeap(SmpHeap, 0, State->OldPrivileges);
119  }
120 
121  /* Close the token handle and free the state structure */
122  NtClose(State->TokenHandle);
124  return Status;
125 }
#define STATUS_NOT_ALL_ASSIGNED
Definition: ntstatus.h:85
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
NTSTATUS NTAPI NtOpenProcessToken(IN HANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
Definition: security.c:350
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define FALSE
Definition: types.h:117
PVOID SmpHeap
Definition: sminit.c:24
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FORCEINLINE LUID NTAPI_INLINE RtlConvertUlongToLuid(_In_ ULONG Val)
Definition: rtlfuncs.h:3543
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
struct _TOKEN_PRIVILEGES * PTOKEN_PRIVILEGES
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtAdjustPrivilegesToken(_In_ HANDLE TokenHandle, _In_ BOOLEAN DisableAllPrivileges, _In_opt_ PTOKEN_PRIVILEGES NewState, _In_ ULONG BufferLength, _Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_PRIVILEGES PreviousState, _When_(PreviousState!=NULL, _Out_) PULONG ReturnLength)
Definition: token.c:3214

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

◆ SmpAllocateSessionId()

ULONG NTAPI SmpAllocateSessionId ( IN PSMP_SUBSYSTEM  Subsystem,
IN PSMP_SUBSYSTEM  OtherSubsystem 
)

Definition at line 123 of file smsessn.c.

125 {
127  PSMP_SESSION Session;
128 
129  /* Allocate a new ID while under the lock */
132 
133  /* Check for overflow */
135  {
136  /* Break if it happened */
137  DbgPrint("SMSS: SessionId's Wrapped\n");
138  DbgBreakPoint();
139  }
140  else
141  {
142  /* Detect it for next time */
144  }
145 
146  /* Allocate a session structure */
147  Session = RtlAllocateHeap(SmpHeap, 0, sizeof(SMP_SESSION));
148  if (Session)
149  {
150  /* Write the session data and insert it into the session list */
151  Session->Subsystem = Subsystem;
152  Session->SessionId = SessionId;
153  Session->OtherSubsystem = OtherSubsystem;
155  }
156  else
157  {
158  DPRINT1("SMSS: Unable to keep track of session ID -- no memory available\n");
159  }
160 
161  /* Release the session lock */
163  return SessionId;
164 }
#define DbgPrint
Definition: loader.c:25
PSMP_SUBSYSTEM Subsystem
Definition: smsessn.c:22
ULONG SessionId
Definition: dllmain.c:28
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define InsertTailList(ListHead, Entry)
void DbgBreakPoint()
Definition: mach.c:553
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
LIST_ENTRY SmpSessionListHead
Definition: smsessn.c:27
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
ULONG SessionId
Definition: smsessn.c:21
PSMP_SUBSYSTEM OtherSubsystem
Definition: smsessn.c:23
ULONG SmpNextSessionIdScanMode
Definition: smsessn.c:29
#define DPRINT1
Definition: precomp.h:8
ULONG SmpNextSessionId
Definition: smsessn.c:28
unsigned int ULONG
Definition: retypes.h:1
LIST_ENTRY Entry
Definition: smsessn.c:20

Referenced by SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpApiLoop()

ULONG NTAPI SmpApiLoop ( IN PVOID  Parameter)

Definition at line 335 of file smloop.c.

336 {
340  PSM_API_MSG ReplyMsg = NULL;
341  SM_API_MSG RequestMsg;
342  PROCESS_BASIC_INFORMATION ProcessInformation;
344 
345  /* Increase the number of API threads for throttling code for later */
347 
348  /* Mark us critical */
350 
351  /* Set the PID of the SM process itself for later checking */
354  &ProcessInformation,
355  sizeof(ProcessInformation),
356  NULL);
357  SmUniqueProcessId = (HANDLE)ProcessInformation.UniqueProcessId;
358 
359  /* Now process incoming messages */
360  while (TRUE)
361  {
362  /* Begin waiting on a request */
364  (PVOID*)&ClientContext,
365  &ReplyMsg->h,
366  &RequestMsg.h);
367  if (Status == STATUS_NO_MEMORY)
368  {
369  /* Ran out of memory, so do a little timeout and try again */
370  if (ReplyMsg) DPRINT1("SMSS: Failed to reply to calling thread, retrying.\n");
371  Timeout.QuadPart = -50000000;
373  continue;
374  }
375 
376  /* Check what kind of request we received */
377  switch (RequestMsg.h.u2.s2.Type)
378  {
379  /* A new connection */
381  /* Create the right structures for it */
383  ReplyMsg = NULL;
384  break;
385 
386  /* A closed connection */
387  case LPC_PORT_CLOSED:
388  /* Destroy any state we had for this client */
389  DPRINT1("Port closed\n");
390  //if (ClientContext) SmpPushDeferredClientContext(ClientContext);
391  ReplyMsg = NULL;
392  break;
393 
394  /* An actual API message */
395  default:
396  if (!ClientContext)
397  {
398  ReplyMsg = NULL;
399  break;
400  }
401 
402  RequestMsg.ReturnValue = STATUS_PENDING;
403 
404  /* Check if the API is valid */
405  if (RequestMsg.ApiNumber >= SmpMaxApiNumber)
406  {
407  /* It isn't, fail */
408  DPRINT1("Invalid API: %lx\n", RequestMsg.ApiNumber);
410  }
411  else if ((RequestMsg.ApiNumber <= SmpTerminateForeignSessionApi) &&
412  !(ClientContext->Subsystem))
413  {
414  /* It's valid, but doesn't have a subsystem with it */
415  DPRINT1("Invalid session API\n");
417  }
418  else
419  {
420  /* It's totally okay, so call the dispatcher for it */
421  Status = SmpApiDispatch[RequestMsg.ApiNumber](&RequestMsg,
423  SmApiPort);
424  }
425 
426  /* Write the result value and return the message back */
427  RequestMsg.ReturnValue = Status;
428  ReplyMsg = &RequestMsg;
429  break;
430  }
431  }
432  return STATUS_SUCCESS;
433 }
PORT_MESSAGE h
Definition: smmsg.h:92
NTSTATUS NTAPI SmpHandleConnectionRequest(IN HANDLE SmApiPort, IN PSB_API_MSG SbApiMsg)
Definition: smloop.c:185
HANDLE SmApiPort
Definition: smss.c:23
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ PVOID Parameter
Definition: ldrtypes.h:241
while(1)
Definition: macro.lex.yy.c:740
return STATUS_NOT_IMPLEMENTED
HANDLE SmUniqueProcessId
Definition: smloop.c:35
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS __cdecl RtlSetThreadIsCritical(_In_ BOOLEAN NewValue, _Out_opt_ PBOOLEAN OldValue, _In_ BOOLEAN NeedBreaks)
volatile LONG SmTotalApiThreads
Definition: smloop.c:34
PSM_API_HANDLER SmpApiDispatch[SmpMaxApiNumber - SmpCreateForeignSessionApi]
Definition: smloop.c:170
NTSTATUS NTAPI NtDelayExecution(IN BOOLEAN Alertable, IN PLARGE_INTEGER DelayInterval)
Definition: wait.c:879
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
SMSRV_API_NUMBER ApiNumber
Definition: smmsg.h:93
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ PVOID ClientContext
Definition: netioddk.h:55
PVOID HANDLE
Definition: typedefs.h:73
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
static ULONG Timeout
Definition: ping.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define STATUS_SUCCESS
Definition: shellext.h:65
long __cdecl _InterlockedExchangeAdd(_Interlocked_operand_ long volatile *_Addend, long _Value)
NTSTATUS ReturnValue
Definition: smmsg.h:94

Referenced by SmpInit().

◆ SmpCheckDuplicateMuSessionId()

BOOLEAN NTAPI SmpCheckDuplicateMuSessionId ( IN ULONG  MuSessionId)

Definition at line 37 of file smsessn.c.

38 {
39  PSMP_SUBSYSTEM Subsystem;
40  BOOLEAN FoundDuplicate = FALSE;
41  PLIST_ENTRY NextEntry;
42 
43  /* Lock the subsystem database */
45 
46  /* Scan each entry */
47  NextEntry = SmpKnownSubSysHead.Flink;
48  while (NextEntry != &SmpKnownSubSysHead)
49  {
50  /* Check if this entry has the same session ID */
51  Subsystem = CONTAINING_RECORD(NextEntry, SMP_SUBSYSTEM, Entry);
52  if (Subsystem->MuSessionId == MuSessionId)
53  {
54  /* Break out of here! */
55  FoundDuplicate = TRUE;
56  break;
57  }
58 
59  /* Keep going */
60  NextEntry = NextEntry->Flink;
61  }
62 
63  /* Release the database and return the result */
65  return FoundDuplicate;
66 }
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
unsigned char BOOLEAN
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
ULONG MuSessionId
Definition: smss.h:69
base of all file and directory entries
Definition: entries.h:82
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19

Referenced by SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpCheckForCrashDump()

BOOLEAN NTAPI SmpCheckForCrashDump ( IN PUNICODE_STRING  FileName)

Definition at line 20 of file crashdmp.c.

21 {
22  return FALSE;
23 }
#define FALSE
Definition: types.h:117

Referenced by SmpCreatePagingFileOnFixedDrive().

◆ SmpCreatePagingFileDescriptor()

NTSTATUS NTAPI SmpCreatePagingFileDescriptor ( IN PUNICODE_STRING  PageFileToken)

Definition at line 84 of file pagefile.c.

85 {
87  ULONG MinSize = 0, MaxSize = 0;
88  BOOLEAN SystemManaged = FALSE, ZeroSize = TRUE;
89  PSMP_PAGEFILE_DESCRIPTOR Descriptor, ListDescriptor;
90  ULONG i;
91  WCHAR c;
92  PLIST_ENTRY NextEntry;
93  UNICODE_STRING PageFileName, Arguments, SecondArgument;
94 
95  /* Make sure we don't have too many */
96  if (SmpNumberOfPagingFiles >= 16)
97  {
98  DPRINT1("SMSS:PFILE: Too many paging files specified - %lu\n",
101  }
102 
103  /* Parse the specified and get the name and arguments out of it */
104  DPRINT("SMSS:PFILE: Paging file specifier `%wZ'\n", PageFileToken);
105  Status = SmpParseCommandLine(PageFileToken,
106  NULL,
107  &PageFileName,
108  NULL,
109  &Arguments);
110  if (!NT_SUCCESS(Status))
111  {
112  /* Fail */
113  DPRINT1("SMSS:PFILE: SmpParseCommandLine( %wZ ) failed - Status == %lx\n",
114  PageFileToken, Status);
115  return Status;
116  }
117 
118  /* Set the variable to let everyone know we have a pagefile token */
120 
121  /* Parse the arguments, if any */
122  if (Arguments.Buffer)
123  {
124  /* Parse the pagefile size */
125  for (i = 0; i < Arguments.Length / sizeof(WCHAR); i++)
126  {
127  /* Check if it's zero */
128  c = Arguments.Buffer[i];
129  if ((c != L' ') && (c != L'\t') && (c != L'0'))
130  {
131  /* It isn't, break out */
132  ZeroSize = FALSE;
133  break;
134  }
135  }
136  }
137 
138  /* Was a pagefile not specified, or was it specified with no size? */
139  if (!(Arguments.Buffer) || (ZeroSize))
140  {
141  /* In this case, the system will manage its size */
142  SystemManaged = TRUE;
143  }
144  else
145  {
146  /* We do have a size, so convert the arguments into a number */
147  Status = RtlUnicodeStringToInteger(&Arguments, 0, &MinSize);
148  if (!NT_SUCCESS(Status))
149  {
150  /* Fail */
151  RtlFreeUnicodeString(&PageFileName);
152  RtlFreeUnicodeString(&Arguments);
153  return Status;
154  }
155 
156  /* Now advance to the next argument */
157  for (i = 0; i < Arguments.Length / sizeof(WCHAR); i++)
158  {
159  /* Found a space -- second argument must start here */
160  if (Arguments.Buffer[i] == L' ')
161  {
162  /* Use the rest of the arguments as a maximum size */
163  SecondArgument.Buffer = &Arguments.Buffer[i];
164  SecondArgument.Length = (USHORT)(Arguments.Length -
165  i * sizeof(WCHAR));
166  SecondArgument.MaximumLength = (USHORT)(Arguments.MaximumLength -
167  i * sizeof(WCHAR));
168  Status = RtlUnicodeStringToInteger(&SecondArgument, 0, &MaxSize);
169  if (!NT_SUCCESS(Status))
170  {
171  /* Fail */
172  RtlFreeUnicodeString(&PageFileName);
173  RtlFreeUnicodeString(&Arguments);
174  return Status;
175  }
176 
177  break;
178  }
179  }
180  }
181 
182  /* We are done parsing arguments */
183  RtlFreeUnicodeString(&Arguments);
184 
185  /* Now we can allocate our descriptor */
186  Descriptor = RtlAllocateHeap(RtlGetProcessHeap(),
188  sizeof(SMP_PAGEFILE_DESCRIPTOR));
189  if (!Descriptor)
190  {
191  /* Fail if we couldn't */
192  RtlFreeUnicodeString(&PageFileName);
193  return STATUS_NO_MEMORY;
194  }
195 
196  /* Capture all our data into the descriptor */
197  Descriptor->Token = *PageFileToken;
198  Descriptor->Name = PageFileName;
199  Descriptor->MinSize.QuadPart = MinSize * MEGABYTE;
200  Descriptor->MaxSize.QuadPart = MaxSize * MEGABYTE;
201  if (SystemManaged) Descriptor->Flags |= SMP_PAGEFILE_SYSTEM_MANAGED;
204  if (Descriptor->Name.Buffer[STANDARD_DRIVE_LETTER_OFFSET] == '?')
205  {
207  }
208 
209  /* Now loop the existing descriptors */
211  do
212  {
213  /* Are there none, or have we looped back to the beginning? */
214  if (NextEntry == &SmpPagingFileDescriptorList)
215  {
216  /* This means no duplicates exist, so insert our descriptor! */
219  DPRINT("SMSS:PFILE: Created descriptor for `%wZ' (`%wZ')\n",
220  PageFileToken, &Descriptor->Name);
221  return STATUS_SUCCESS;
222  }
223 
224  /* Keep going until we find a duplicate, unless we are in "any" mode */
225  ListDescriptor = CONTAINING_RECORD(NextEntry, SMP_PAGEFILE_DESCRIPTOR, Entry);
226  NextEntry = NextEntry->Flink;
227  } while (!(ListDescriptor->Flags & SMP_PAGEFILE_ON_ANY_DRIVE) ||
229 
230  /* We found a duplicate, so skip this descriptor/pagefile and fail */
231  DPRINT1("SMSS:PFILE: Skipping duplicate specifier `%wZ'\n", PageFileToken);
232  RtlFreeUnicodeString(&PageFileName);
233  RtlFreeHeap(RtlGetProcessHeap(), 0, Descriptor);
235 }
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG SmpNumberOfPagingFiles
Definition: pagefile.c:69
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
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
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define InsertTailList(ListHead, Entry)
NTSYSAPI WCHAR NTAPI RtlUpcaseUnicodeChar(WCHAR Source)
#define STATUS_TOO_MANY_PAGING_FILES
Definition: ntstatus.h:387
#define MEGABYTE
Definition: pagefile.c:23
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const GLubyte * c
Definition: glext.h:8905
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
static const WCHAR L[]
Definition: oid.c:1250
#define SMP_PAGEFILE_SYSTEM_MANAGED
Definition: pagefile.c:34
Definition: typedefs.h:119
#define SMP_PAGEFILE_ON_ANY_DRIVE
Definition: pagefile.c:36
#define STANDARD_DRIVE_LETTER_OFFSET
Definition: pagefile.c:22
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define DPRINT1
Definition: precomp.h:8
LIST_ENTRY SmpPagingFileDescriptorList
Definition: pagefile.c:67
#define c
Definition: ke_i.h:80
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:82
BOOLEAN SmpRegistrySpecifierPresent
Definition: pagefile.c:68

Referenced by SmpLoadDataFromRegistry().

◆ SmpCreatePagingFiles()

NTSTATUS NTAPI SmpCreatePagingFiles ( VOID  )

Definition at line 998 of file pagefile.c.

999 {
1000  NTSTATUS Status;
1002  LARGE_INTEGER Size, FuzzFactor;
1003  BOOLEAN Created = FALSE;
1004  PLIST_ENTRY NextEntry;
1005 
1006  /* Check if no paging files were requested */
1008  {
1009  /* The list should be empty -- nothing to do */
1011  DPRINT1("SMSS:PFILE: No paging file was requested\n");
1012  return STATUS_SUCCESS;
1013  }
1014 
1015  /* Initialize the volume descriptors so we can know what's available */
1017  if (!NT_SUCCESS(Status))
1018  {
1019  /* We can't make decisions without this, so fail */
1020  DPRINT1("SMSS:PFILE: Failed to create volume descriptors (status %X)\n",
1021  Status);
1022  return Status;
1023  }
1024 
1025  /* If we fail creating pagefiles, try to reduce by this much each time */
1026  FuzzFactor.QuadPart = FUZZ_FACTOR;
1027 
1028  /* Loop the descriptor list */
1029  NextEntry = SmpPagingFileDescriptorList.Flink;
1030  while (NextEntry != &SmpPagingFileDescriptorList)
1031  {
1032  /* Check what kind of descriptor this is */
1035  {
1036  /* This is a system-managed descriptor. Create the correct file */
1037  DPRINT("SMSS:PFILE: Creating a system managed paging file (`%wZ')\n",
1038  &Descriptor->Name);
1040  if (!NT_SUCCESS(Status))
1041  {
1042  /* We failed -- try again, with size minimization this time */
1043  DPRINT("SMSS:PFILE: Trying lower sizes for (`%wZ')\n",
1044  &Descriptor->Name);
1046  }
1047  }
1048  else
1049  {
1050  /* This is a manually entered descriptor. Validate its size first */
1052 
1053  /* Check if this is an ANY pagefile or a FIXED pagefile */
1054  DPRINT("SMSS:PFILE: Creating a normal paging file (`%wZ')\n",
1055  &Descriptor->Name);
1056  if (Descriptor->Name.Buffer[STANDARD_DRIVE_LETTER_OFFSET] == L'?')
1057  {
1058  /* It's an any pagefile, try to create it wherever possible */
1059  Size = Descriptor->MinSize;
1061  &FuzzFactor,
1062  &Size);
1063  if (!NT_SUCCESS(Status))
1064  {
1065  /* We failed to create it. Try again with a smaller size */
1066  DPRINT("SMSS:PFILE: Trying lower sizes for (`%wZ')\n",
1067  &Descriptor->Name);
1068  Size.QuadPart = 16 * MEGABYTE;
1070  &FuzzFactor,
1071  &Size);
1072  }
1073  }
1074  else
1075  {
1076  /* It's a fixed pagefile: override the minimum and use ours */
1077  Size.QuadPart = 16 * MEGABYTE;
1079  &FuzzFactor,
1080  &Size);
1081  }
1082  }
1083 
1084  /* Go to the next descriptor */
1085  if (NT_SUCCESS(Status)) Created = TRUE;
1086  NextEntry = NextEntry->Flink;
1087  }
1088 
1089  /* Check if none of the code in our loops above was able to create it */
1090  if (!Created)
1091  {
1092  /* Build an emergency pagefile ourselves */
1093  DPRINT1("SMSS:PFILE: Creating emergency paging file.\n");
1095  }
1096 
1097  /* All done */
1098  return Status;
1099 }
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
NTSTATUS NTAPI SmpCreateEmergencyPagingFile(VOID)
Definition: pagefile.c:783
ULONG SmpNumberOfPagingFiles
Definition: pagefile.c:69
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
NTSTATUS NTAPI SmpCreatePagingFileOnFixedDrive(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor, IN PLARGE_INTEGER FuzzFactor, IN PLARGE_INTEGER MinimumSize)
Definition: pagefile.c:479
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define MEGABYTE
Definition: pagefile.c:23
NTSTATUS NTAPI SmpCreateSystemManagedPagingFile(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor, IN BOOLEAN DecreaseSize)
Definition: pagefile.c:750
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
NTSTATUS NTAPI SmpCreatePagingFileOnAnyDrive(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor, IN PLARGE_INTEGER FuzzFactor, IN PLARGE_INTEGER MinimumSize)
Definition: pagefile.c:611
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
#define SMP_PAGEFILE_SYSTEM_MANAGED
Definition: pagefile.c:34
Definition: typedefs.h:119
#define STANDARD_DRIVE_LETTER_OFFSET
Definition: pagefile.c:22
#define DPRINT1
Definition: precomp.h:8
LIST_ENTRY SmpPagingFileDescriptorList
Definition: pagefile.c:67
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI SmpValidatePagingFileSizes(IN PSMP_PAGEFILE_DESCRIPTOR Descriptor)
Definition: pagefile.c:693
base of all file and directory entries
Definition: entries.h:82
#define FUZZ_FACTOR
Definition: pagefile.c:27
LONGLONG QuadPart
Definition: typedefs.h:114
NTSTATUS NTAPI SmpCreateVolumeDescriptors(VOID)
Definition: pagefile.c:818
BOOLEAN SmpRegistrySpecifierPresent
Definition: pagefile.c:68

Referenced by SmpLoadDataFromRegistry().

◆ SmpCreateSecurityDescriptors()

NTSTATUS NTAPI SmpCreateSecurityDescriptors ( IN BOOLEAN  InitialCall)

Definition at line 950 of file sminit.c.

951 {
953  PSID WorldSid = NULL, AdminSid = NULL, SystemSid = NULL;
954  PSID RestrictedSid = NULL, OwnerSid = NULL;
958  ULONG AclLength, SidLength;
959  PACL Acl;
961  BOOLEAN ProtectionRequired = FALSE;
962 
963  /* Check if this is the first call */
964  if (InitialCall)
965  {
966  /* Create and set the primary descriptor */
972  TRUE,
973  NULL,
974  FALSE);
976 
977  /* Create and set the liberal descriptor */
983  TRUE,
984  NULL,
985  FALSE);
987 
988  /* Create and set the \KnownDlls descriptor */
994  TRUE,
995  NULL,
996  FALSE);
998 
999  /* Create and Set the \ApiPort descriptor */
1005  TRUE,
1006  NULL,
1007  FALSE);
1009  }
1010 
1011  /* Check if protection was requested in the registry (on by default) */
1012  if (SmpProtectionMode & 1) ProtectionRequired = TRUE;
1013 
1014  /* Exit if there's nothing to do */
1015  if (!(InitialCall || ProtectionRequired)) return STATUS_SUCCESS;
1016 
1017  /* Build the world SID */
1020  0, 0, 0, 0, 0, 0, 0,
1021  &WorldSid);
1022  if (!NT_SUCCESS(Status))
1023  {
1024  WorldSid = NULL;
1025  goto Quickie;
1026  }
1027 
1028  /* Build the admin SID */
1032  0, 0, 0, 0, 0, 0,
1033  &AdminSid);
1034  if (!NT_SUCCESS(Status))
1035  {
1036  AdminSid = NULL;
1037  goto Quickie;
1038  }
1039 
1040  /* Build the owner SID */
1041  Status = RtlAllocateAndInitializeSid(&CreatorAuthority, 1,
1043  0, 0, 0, 0, 0, 0, 0,
1044  &OwnerSid);
1045  if (!NT_SUCCESS(Status))
1046  {
1047  OwnerSid = NULL;
1048  goto Quickie;
1049  }
1050 
1051  /* Build the restricted SID */
1054  0, 0, 0, 0, 0, 0, 0,
1055  &RestrictedSid);
1056  if (!NT_SUCCESS(Status))
1057  {
1058  RestrictedSid = NULL;
1059  goto Quickie;
1060  }
1061 
1062  /* Build the system SID */
1065  0, 0, 0, 0, 0, 0, 0,
1066  &SystemSid);
1067  if (!NT_SUCCESS(Status))
1068  {
1069  SystemSid = NULL;
1070  goto Quickie;
1071  }
1072 
1073  /* Now check if we're creating the core descriptors */
1074  if (!InitialCall)
1075  {
1076  /* We're skipping NextAcl so we have to do this here */
1077  SidLength = RtlLengthSid(WorldSid) + RtlLengthSid(RestrictedSid) + RtlLengthSid(AdminSid);
1078  SidLength *= 2;
1079  goto NotInitial;
1080  }
1081 
1082  /* Allocate an ACL with two ACEs with two SIDs each */
1083  SidLength = RtlLengthSid(SystemSid) + RtlLengthSid(AdminSid);
1084  AclLength = sizeof(ACL) + 2 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
1085  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1086  if (!Acl) Status = STATUS_NO_MEMORY;
1087  if (!NT_SUCCESS(Status)) goto NextAcl;
1088 
1089  /* Now build the ACL and add the two ACEs */
1096 
1097  /* Set this as the DACL */
1099  TRUE,
1100  Acl,
1101  FALSE);
1103 
1104 NextAcl:
1105  /* Allocate an ACL with 6 ACEs, two ACEs per SID */
1106  SidLength = RtlLengthSid(WorldSid) + RtlLengthSid(RestrictedSid) + RtlLengthSid(AdminSid);
1107  SidLength *= 2;
1108  AclLength = sizeof(ACL) + 6 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
1109  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1110  if (!Acl) Status = STATUS_NO_MEMORY;
1111  if (!NT_SUCCESS(Status)) goto NotInitial;
1112 
1113  /* Now build the ACL and add the six ACEs */
1128 
1129  /* Now edit the last three ACEs and make them inheritable */
1130  Status = RtlGetAce(Acl, 3, (PVOID)&Ace);
1133  Status = RtlGetAce(Acl, 4, (PVOID)&Ace);
1136  Status = RtlGetAce(Acl, 5, (PVOID)&Ace);
1139 
1140  /* Set this as the DACL */
1142  TRUE,
1143  Acl,
1144  FALSE);
1146 
1147 NotInitial:
1148  /* The initial ACLs have been created, are we also protecting objects? */
1149  if (!ProtectionRequired) goto Quickie;
1150 
1151  /* Allocate an ACL with 7 ACEs, two ACEs per SID, and one final owner ACE */
1152  SidLength += RtlLengthSid(OwnerSid);
1153  AclLength = sizeof(ACL) + 7 * sizeof (ACCESS_ALLOWED_ACE) + 2 * SidLength;
1154  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1155  if (!Acl) Status = STATUS_NO_MEMORY;
1156  if (!NT_SUCCESS(Status)) goto Quickie;
1157 
1158  /* Build the ACL and add the seven ACEs */
1175 
1176  /* Edit the last 4 ACEs to make then inheritable */
1177  Status = RtlGetAce(Acl, 3, (PVOID)&Ace);
1180  Status = RtlGetAce(Acl, 4, (PVOID)&Ace);
1183  Status = RtlGetAce(Acl, 5, (PVOID)&Ace);
1186  Status = RtlGetAce(Acl, 6, (PVOID)&Ace);
1189 
1190  /* Set this as the DACL for the primary SD */
1192  TRUE,
1193  Acl,
1194  FALSE);
1196 
1197  /* Allocate an ACL with 7 ACEs, two ACEs per SID, and one final owner ACE */
1198  AclLength = sizeof(ACL) + 7 * sizeof (ACCESS_ALLOWED_ACE) + 2 * SidLength;
1199  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1200  if (!Acl) Status = STATUS_NO_MEMORY;
1201  if (!NT_SUCCESS(Status)) goto Quickie;
1202 
1203  /* Build the ACL and add the seven ACEs */
1220 
1221  /* Edit the last 4 ACEs to make then inheritable */
1222  Status = RtlGetAce(Acl, 3, (PVOID)&Ace);
1225  Status = RtlGetAce(Acl, 4, (PVOID)&Ace);
1228  Status = RtlGetAce(Acl, 5, (PVOID)&Ace);
1231  Status = RtlGetAce(Acl, 6, (PVOID)&Ace);
1234 
1235  /* Now set this as the DACL for the liberal SD */
1237  TRUE,
1238  Acl,
1239  FALSE);
1241 
1242 Quickie:
1243  /* Cleanup the SIDs */
1244  if (OwnerSid) RtlFreeHeap(RtlGetProcessHeap(), 0, OwnerSid);
1245  if (AdminSid) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminSid);
1246  if (WorldSid) RtlFreeHeap(RtlGetProcessHeap(), 0, WorldSid);
1247  if (SystemSid) RtlFreeHeap(RtlGetProcessHeap(), 0, SystemSid);
1248  if (RestrictedSid) RtlFreeHeap(RtlGetProcessHeap(), 0, RestrictedSid);
1249  return Status;
1250 }
#define GENERIC_ALL
Definition: nt_native.h:92
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
SECURITY_DESCRIPTOR SmpPrimarySDBody
Definition: sminit.c:35
PISECURITY_DESCRIPTOR SmpPrimarySecurityDescriptor
Definition: sminit.c:37
static PSID AdminSid
Definition: msgina.c:39
#define TRUE
Definition: types.h:120
PISECURITY_DESCRIPTOR SmpApiPortSecurityDescriptor
Definition: sminit.c:38
SECURITY_DESCRIPTOR SmpKnownDllsSDBody
Definition: sminit.c:35
LONG NTSTATUS
Definition: precomp.h:26
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlGetAce(PACL Acl, ULONG AceIndex, PVOID *Ace)
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define FALSE
Definition: types.h:117
PISECURITY_DESCRIPTOR SmpLiberalSecurityDescriptor
Definition: sminit.c:37
#define GENERIC_WRITE
Definition: nt_native.h:90
Definition: card.h:12
unsigned char BOOLEAN
#define ACL_REVISION2
Definition: setypes.h:43
struct _ACL ACL
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:526
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define CONTAINER_INHERIT_ACE
Definition: setypes.h:715
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:499
#define SECURITY_WORLD_RID
Definition: setypes.h:513
#define SECURITY_CREATOR_OWNER_RID
Definition: setypes.h:517
PISECURITY_DESCRIPTOR SmpKnownDllsSecurityDescriptor
Definition: sminit.c:38
PSID WorldSid
Definition: globals.c:15
#define GENERIC_READ
Definition: compat.h:135
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define SECURITY_RESTRICTED_CODE_RID
Definition: setypes.h:541
#define NULL
Definition: types.h:112
SECURITY_DESCRIPTOR SmpLiberalSDBody
Definition: sminit.c:35
ULONG SmpProtectionMode
Definition: sminit.c:40
SECURITY_DESCRIPTOR SmpApiPortSDBody
Definition: sminit.c:36
unsigned int ULONG
Definition: retypes.h:1
#define INHERIT_ONLY_ACE
Definition: setypes.h:717
#define STATUS_SUCCESS
Definition: shellext.h:65
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624
#define OBJECT_INHERIT_ACE
Definition: setypes.h:714
_In_ ULONG AclLength
Definition: rtlfuncs.h:1844
#define SECURITY_CREATOR_SID_AUTHORITY
Definition: setypes.h:505
SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: database.c:19

Referenced by SmpConfigureProtectionMode(), and SmpInit().

◆ SmpDeleteSession()

VOID NTAPI SmpDeleteSession ( IN ULONG  SessionId)

Definition at line 98 of file smsessn.c.

99 {
100  PSMP_SESSION Session;
101 
102  /* Enter the lock and get the session structure */
104  Session = SmpSessionIdToSession(SessionId);
105  if (Session)
106  {
107  /* Remove it from the list */
108  RemoveEntryList(&Session->Entry);
110 
111  /* Now free the structure outside of the lock */
112  RtlFreeHeap(SmpHeap, 0, Session);
113  }
114  else
115  {
116  /* ID doesn't map to one of our structures, nothing to do... */
118  }
119 }
ULONG SessionId
Definition: dllmain.c:28
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PSMP_SESSION NTAPI SmpSessionIdToSession(IN ULONG SessionId)
Definition: smsessn.c:70
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
LIST_ENTRY Entry
Definition: smsessn.c:20

Referenced by SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpDereferenceSubsystem()

VOID NTAPI SmpDereferenceSubsystem ( IN PSMP_SUBSYSTEM  SubSystem)

Definition at line 47 of file smsubsys.c.

48 {
49  /* Acquire the database lock while we (potentially) destroy this subsystem */
51 
52  /* Drop the reference and see if it's terminating */
53  if (!(--SubSystem->ReferenceCount) && (SubSystem->Terminating))
54  {
55  /* Close all handles and free it */
56  if (SubSystem->Event) NtClose(SubSystem->Event);
57  if (SubSystem->ProcessHandle) NtClose(SubSystem->ProcessHandle);
58  if (SubSystem->SbApiPort) NtClose(SubSystem->SbApiPort);
59  RtlFreeHeap(SmpHeap, 0, SubSystem);
60  }
61 
62  /* Release the database lock */
64 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18

Referenced by SmpHandleConnectionRequest(), SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpExecuteCommand()

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

Definition at line 221 of file smss.c.

225 {
227  UNICODE_STRING Arguments, Directory, FileName;
228 
229  /* There's no longer a debugging subsystem */
230  if (Flags & SMP_DEBUG_FLAG) return STATUS_SUCCESS;
231 
232  /* Parse the command line to see what execution flags are requested */
233  Status = SmpParseCommandLine(CommandLine,
234  &Flags,
235  &FileName,
236  &Directory,
237  &Arguments);
238  if (!NT_SUCCESS(Status))
239  {
240  /* Fail if we couldn't do that */
241  DPRINT1("SMSS: SmpParseCommandLine( %wZ ) failed - Status == %lx\n",
242  CommandLine, Status);
243  return Status;
244  }
245 
246  /* Check if autochk is requested */
247  if (Flags & SMP_AUTOCHK_FLAG)
248  {
249  /* Run it */
250  Status = SmpInvokeAutoChk(&FileName, &Directory, &Arguments, Flags);
251  }
252  else if (Flags & SMP_SUBSYSTEM_FLAG)
253  {
255  &Directory,
256  CommandLine,
257  MuSessionId,
258  ProcessId,
259  Flags);
260  }
261  else if (Flags & SMP_INVALID_PATH)
262  {
263  /* An invalid image was specified, fail */
264  DPRINT1("SMSS: Image file (%wZ) not found\n", &FileName);
266  }
267  else
268  {
269  /* An actual image name was present -- execute it */
271  &Directory,
272  CommandLine,
273  MuSessionId,
274  Flags,
275  NULL);
276  }
277 
278  /* Free all the token parameters */
279  if (FileName.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, FileName.Buffer);
280  if (Directory.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Directory.Buffer);
281  if (Arguments.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Arguments.Buffer);
282 
283  /* Return to the caller */
284  if (!NT_SUCCESS(Status))
285  {
286  DPRINT1("SMSS: Command '%wZ' failed - Status == %x\n",
287  CommandLine, Status);
288  }
289  return Status;
290 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2706
#define SMP_AUTOCHK_FLAG
Definition: smss.h:43
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
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS NTAPI SmpInvokeAutoChk(IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING Arguments, IN ULONG Flags)
Definition: smss.c:161
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SMP_INVALID_PATH
Definition: smss.h:45
struct _FileName FileName
Definition: fatprocs.h:893
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 STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define SMP_DEBUG_FLAG
Definition: smss.h:41
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:44
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
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:42
base for all directory entries
Definition: entries.h:138
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ BOOLEAN _In_ USHORT Directory
Definition: rtlfuncs.h:3872

Referenced by SmpLoadDataFromRegistry(), 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 42 of file smss.c.

48 {
51  RTL_USER_PROCESS_INFORMATION LocalProcessInfo;
52  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
53 
54  /* Use the input process information if we have it, otherwise use local */
55  ProcessInfo = ProcessInformation;
56  if (!ProcessInfo) ProcessInfo = &LocalProcessInfo;
57 
58  /* Create parameters for the target process */
59  Status = RtlCreateProcessParameters(&ProcessParameters,
60  FileName,
63  Directory,
64  CommandLine,
66  NULL,
67  NULL,
68  NULL,
69  0);
70  if (!NT_SUCCESS(Status))
71  {
72  /* This is a pretty bad failure. ASSERT on checked builds and exit */
73  ASSERTMSG("RtlCreateProcessParameters failed.\n", NT_SUCCESS(Status));
74  DPRINT1("SMSS: RtlCreateProcessParameters failed for %wZ - Status == %lx\n",
75  FileName, Status);
76  return Status;
77  }
78 
79  /* Set the size field as required */
80  ProcessInfo->Size = sizeof(RTL_USER_PROCESS_INFORMATION);
81 
82  /* Check if the debug flag was requested */
83  if (Flags & SMP_DEBUG_FLAG)
84  {
85  /* Write it in the process parameters */
86  ProcessParameters->DebugFlags = 1;
87  }
88  else
89  {
90  /* Otherwise inherit the flag that was passed to SMSS itself */
91  ProcessParameters->DebugFlags = SmpDebug;
92  }
93 
94  /* Subsystems get the first 1MB of memory reserved for DOS/IVT purposes */
96  {
97  ProcessParameters->Flags |= RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB;
98  }
99 
100  /* And always force NX for anything that SMSS launches */
101  ProcessParameters->Flags |= RTL_USER_PROCESS_PARAMETERS_NX;
102 
103  /* Now create the process */
106  ProcessParameters,
107  NULL,
108  NULL,
109  NULL,
110  FALSE,
111  NULL,
112  NULL,
113  ProcessInfo);
114  RtlDestroyProcessParameters(ProcessParameters);
115  if (!NT_SUCCESS(Status))
116  {
117  /* If we couldn't create it, fail back to the caller */
118  DPRINT1("SMSS: Failed load of %wZ - Status == %lx\n",
119  FileName, Status);
120  return Status;
121  }
122 
123  /* Associate a session with this process */
124  Status = SmpSetProcessMuSessionId(ProcessInfo->ProcessHandle, MuSessionId);
125 
126  /* If the application is deferred (suspended), there's nothing to do */
127  if (Flags & SMP_DEFERRED_FLAG) return Status;
128 
129  /* Otherwise, get ready to start it, but make sure it's a native app */
131  {
132  /* Resume it */
133  NtResumeThread(ProcessInfo->ThreadHandle, NULL);
134  if (!(Flags & SMP_ASYNC_FLAG))
135  {
136  /* Block on it unless Async was requested */
138  }
139 
140  /* It's up and running now, close our handles */
141  NtClose(ProcessInfo->ThreadHandle);
142  NtClose(ProcessInfo->ProcessHandle);
143  }
144  else
145  {
146  /* This image is invalid, so kill it, close our handles, and fail */
148  NtTerminateProcess(ProcessInfo->ProcessHandle, Status);
149  NtWaitForSingleObject(ProcessInfo->ThreadHandle, 0, 0);
150  NtClose(ProcessInfo->ThreadHandle);
151  NtClose(ProcessInfo->ProcessHandle);
152  DPRINT1("SMSS: Not an NT image - %wZ\n", FileName);
153  }
154 
155  /* Return the outcome of the process create */
156  return Status;
157 }
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)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
UNICODE_STRING SmpDefaultLibPath
Definition: sminit.c:28
#define RTL_USER_PROCESS_PARAMETERS_NX
Definition: rtltypes.h:55
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlDestroyProcessParameters(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
struct _RTL_USER_PROCESS_INFORMATION RTL_USER_PROCESS_INFORMATION
NTSTATUS NTAPI SmpSetProcessMuSessionId(IN HANDLE ProcessHandle, IN ULONG SessionId)
Definition: smsessn.c:199
#define FALSE
Definition: types.h:117
PWCHAR SmpDefaultEnvironment
Definition: sminit.c:27
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
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)
Status
Definition: gdiplustypes.h:24
SECTION_IMAGE_INFORMATION ImageInformation
Definition: rtltypes.h:1571
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB
Definition: rtltypes.h:46
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define SMP_ASYNC_FLAG
Definition: smss.h:42
BOOLEAN SmpDebug
Definition: smss.c:22
#define SMP_DEBUG_FLAG
Definition: smss.h:41
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:44
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
base for all directory entries
Definition: entries.h:138
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define SMP_DEFERRED_FLAG
Definition: smss.h:46
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

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

◆ SmpGetProcessMuSessionId()

NTSTATUS NTAPI SmpGetProcessMuSessionId ( IN HANDLE  ProcessHandle,
OUT PULONG  SessionId 
)

Definition at line 168 of file smsessn.c.

170 {
172  ULONG ProcessSession;
173 
174  /* Query the kernel for the session ID */
177  &ProcessSession,
178  sizeof(ProcessSession),
179  NULL);
180  if (NT_SUCCESS(Status))
181  {
182  /* Copy it back into the buffer */
183  *SessionId = ProcessSession;
184  }
185  else
186  {
187  /* Failure -- assume session zero */
188  DPRINT1("SMSS: GetProcessMuSessionId, Process=%p, Status=%x\n",
190  *SessionId = 0;
191  }
192 
193  /* Return result */
194  return Status;
195 }
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by SmpHandleConnectionRequest(), and SmpSbCreateSession().

◆ SmpInit()

NTSTATUS NTAPI SmpInit ( IN PUNICODE_STRING  InitialCommand,
OUT PHANDLE  ProcessHandle 
)

Definition at line 2423 of file sminit.c.

2425 {
2426  NTSTATUS Status, Status2;
2428  UNICODE_STRING PortName, EventName;
2429  HANDLE EventHandle, PortHandle;
2430  ULONG HardErrorMode;
2431 
2432  /* Create the SMSS Heap */
2433  SmBaseTag = RtlCreateTagHeap(RtlGetProcessHeap(),
2434  0,
2435  L"SMSS!",
2436  L"INIT");
2437  SmpHeap = RtlGetProcessHeap();
2438 
2439  /* Enable hard errors */
2440  HardErrorMode = TRUE;
2443  &HardErrorMode,
2444  sizeof(HardErrorMode));
2445 
2446  /* Initialize the subsystem list and the session list, plus their locks */
2451 
2452  /* Initialize the process list */
2454 
2455  /* Initialize session parameters */
2456  SmpNextSessionId = 1;
2459 
2460  /* Create the initial security descriptors */
2462  if (!NT_SUCCESS(Status))
2463  {
2464  /* Fail */
2466  return Status;
2467  }
2468 
2469  /* Initialize subsystem names */
2470  RtlInitUnicodeString(&SmpSubsystemName, L"NT-Session Manager");
2471  RtlInitUnicodeString(&PosixName, L"POSIX");
2472  RtlInitUnicodeString(&Os2Name, L"OS2");
2473 
2474  /* Create the SM API Port */
2475  RtlInitUnicodeString(&PortName, L"\\SmApiPort");
2477  Status = NtCreatePort(&PortHandle,
2479  sizeof(SB_CONNECTION_INFO),
2480  sizeof(SM_API_MSG),
2481  sizeof(SB_API_MSG) * 32);
2483  SmpDebugPort = PortHandle;
2484 
2485  /* Create two SM API threads */
2487  NULL,
2488  FALSE,
2489  0,
2490  0,
2491  0,
2492  SmpApiLoop,
2493  PortHandle,
2494  NULL,
2495  NULL);
2498  NULL,
2499  FALSE,
2500  0,
2501  0,
2502  0,
2503  SmpApiLoop,
2504  PortHandle,
2505  NULL,
2506  NULL);
2508 
2509  /* Create the write event that autochk can set after running */
2510  RtlInitUnicodeString(&EventName, L"\\Device\\VolumesSafeForWriteAccess");
2512  &EventName,
2513  OBJ_PERMANENT,
2514  NULL,
2515  NULL);
2516  Status2 = NtCreateEvent(&EventHandle,
2519  0,
2520  0);
2521  if (!NT_SUCCESS(Status2))
2522  {
2523  /* Should never really fail */
2524  DPRINT1("SMSS: Unable to create %wZ event - Status == %lx\n",
2525  &EventName, Status2);
2526  ASSERT(NT_SUCCESS(Status2));
2527  }
2528 
2529  /* Now initialize everything else based on the registry parameters */
2530  Status = SmpLoadDataFromRegistry(InitialCommand);
2531  if (NT_SUCCESS(Status))
2532  {
2533  /* Autochk should've run now. Set the event and save the CSRSS handle */
2535  NtSetEvent(EventHandle, 0);
2537  }
2538 
2539  /* All done */
2540  return Status;
2541 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define SMSS_CHECKPOINT(x, y)
Definition: sminit.c:43
UNICODE_STRING PosixName
Definition: sminit.c:18
#define TRUE
Definition: types.h:120
PISECURITY_DESCRIPTOR SmpApiPortSecurityDescriptor
Definition: sminit.c:38
HANDLE SmpWindowsSubSysProcess
Definition: smsubsys.c:20
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
ULONG NTAPI SmpApiLoop(IN PVOID Parameter)
Definition: smloop.c:335
LIST_ENTRY NativeProcessList
Definition: sminit.c:22
#define FALSE
Definition: types.h:117
PVOID SmpHeap
Definition: sminit.c:24
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
ULONG NTAPI RtlCreateTagHeap(IN HANDLE HeapHandle, IN ULONG Flags, IN PWSTR TagName, IN PWSTR TagSubName)
Definition: heap.c:3956
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:212
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:454
#define ASSERT(a)
Definition: mode.c:45
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG SmBaseTag
Definition: sminit.c:25
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
HANDLE SmpDebugPort
Definition: sminit.c:26
static const WCHAR L[]
Definition: oid.c:1250
#define OBJ_PERMANENT
Definition: winternl.h:226
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
LIST_ENTRY SmpSessionListHead
Definition: smsessn.c:27
RTL_CRITICAL_SECTION SmpSessionListLock
Definition: smsessn.c:26
BOOLEAN SmpDbgSsLoaded
Definition: smsessn.c:30
UNICODE_STRING SmpSubsystemName
Definition: sminit.c:18
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1107
UNICODE_STRING Os2Name
Definition: sminit.c:18
ULONG SmpNextSessionIdScanMode
Definition: smsessn.c:29
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI SmpCreateSecurityDescriptors(IN BOOLEAN InitialCall)
Definition: sminit.c:950
ULONG SmpNextSessionId
Definition: smsessn.c:28
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSTATUS NTAPI SmpLoadDataFromRegistry(OUT PUNICODE_STRING InitialCommand)
Definition: sminit.c:2218
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19
IN PUNICODE_STRING PortName
Definition: conport.c:35
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855

Referenced by _main().

◆ SmpLoadSubSystem()

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 at line 138 of file smsubsys.c.

144 {
145  PSMP_SUBSYSTEM Subsystem, NewSubsystem, KnownSubsystem = NULL;
146  HANDLE SubSysProcessId;
148  SB_API_MSG SbApiMsg, SbApiMsg2;
149  RTL_USER_PROCESS_INFORMATION ProcessInformation;
151  PVOID State;
154 
155  /* Make sure this is a found subsystem */
156  if (Flags & SMP_INVALID_PATH)
157  {
158  DPRINT1("SMSS: Unable to find subsystem - %wZ\n", FileName);
160  }
161 
162  /* Don't use a session if the flag is set */
163  if (Flags & 0x80) MuSessionId = 0;
164 
165  /* Lock the subsystems while we do a look up */
167  while (TRUE)
168  {
169  /* Check if we found a subsystem not yet fully initialized */
170  Subsystem = SmpLocateKnownSubSysByType(MuSessionId, -1);
171  if (!Subsystem) break;
173 
174  /* Wait on it to initialize */
175  NtWaitForSingleObject(Subsystem->Event, FALSE, NULL);
176 
177  /* Dereference it and try the next one */
179  SmpDereferenceSubsystem(Subsystem);
180  }
181 
182  /* Check if this is a POSIX subsystem */
183  if (Flags & SMP_POSIX_FLAG)
184  {
185  /* Do we already have it? */
186  Subsystem = SmpLocateKnownSubSysByType(MuSessionId, IMAGE_SUBSYSTEM_POSIX_CUI);
187  }
188  else if (Flags & SMP_OS2_FLAG)
189  {
190  /* This is an OS/2 subsystem, do we we already have it? */
191  Subsystem = SmpLocateKnownSubSysByType(MuSessionId, IMAGE_SUBSYSTEM_OS2_CUI);
192  }
193 
194  /* Check if we already have one of the optional subsystems for the session */
195  if (Subsystem)
196  {
197  /* Dereference and return, no work to do */
198  SmpDereferenceSubsystem(Subsystem);
200  return STATUS_SUCCESS;
201  }
202 
203  /* Allocate a new subsystem! */
204  NewSubsystem = RtlAllocateHeap(SmpHeap, SmBaseTag, sizeof(SMP_SUBSYSTEM));
205  if (!NewSubsystem)
206  {
208  return STATUS_NO_MEMORY;
209  }
210 
211  /* Initialize its header and reference count */
212  NewSubsystem->ReferenceCount = 1;
213  NewSubsystem->MuSessionId = MuSessionId;
214  NewSubsystem->ImageType = -1;
215 
216  /* Clear out all the other data for now */
217  NewSubsystem->Terminating = FALSE;
218  NewSubsystem->ProcessHandle = NULL;
219  NewSubsystem->Event = NULL;
220  NewSubsystem->PortHandle = NULL;
221  NewSubsystem->SbApiPort = NULL;
222 
223  /* Create the event we'll be waiting on for initialization */
224  Status = NtCreateEvent(&NewSubsystem->Event,
226  NULL,
228  FALSE);
229  if (!NT_SUCCESS(Status))
230  {
231  /* This failed, bail out */
232  RtlFreeHeap(SmpHeap, 0, NewSubsystem);
234  return STATUS_NO_MEMORY;
235  }
236 
237  /* Insert the subsystem and release the lock. It can now be found */
238  InsertTailList(&SmpKnownSubSysHead, &NewSubsystem->Entry);
240 
241  /* The OS/2 and POSIX subsystems are actually Windows applications! */
243  {
244  /* Locate the Windows subsystem for this session */
245  KnownSubsystem = SmpLocateKnownSubSysByType(MuSessionId,
247  if (!KnownSubsystem)
248  {
249  DPRINT1("SMSS: SmpLoadSubSystem - SmpLocateKnownSubSysByType Failed\n");
250  goto Quickie2;
251  }
252 
253  /* Fill out all the process details and call CSRSS to launch it */
254  CreateProcess->In.ImageName = FileName;
255  CreateProcess->In.CurrentDirectory = Directory;
256  CreateProcess->In.CommandLine = CommandLine;
257  CreateProcess->In.DllPath = SmpDefaultLibPath.Length ?
259  CreateProcess->In.Flags = Flags | SMP_DEFERRED_FLAG;
260  CreateProcess->In.DebugFlags = SmpDebug;
261  Status = SmpCallCsrCreateProcess(&SbApiMsg,
262  sizeof(*CreateProcess),
263  KnownSubsystem->SbApiPort);
264  if (!NT_SUCCESS(Status))
265  {
266  /* Handle failures */
267  DPRINT1("SMSS: SmpLoadSubSystem - SmpCallCsrCreateProcess Failed with Status %lx\n",
268  Status);
269  goto Quickie2;
270  }
271 
272  /* Save the process information we'll need for the create session */
273  ProcessInformation.ProcessHandle = CreateProcess->Out.ProcessHandle;
274  ProcessInformation.ThreadHandle = CreateProcess->Out.ThreadHandle;
275  ProcessInformation.ClientId = CreateProcess->Out.ClientId;
276  ProcessInformation.ImageInformation.SubSystemType = CreateProcess->Out.SubsystemType;
277  }
278  else
279  {
280  /* This must be CSRSS itself, so just launch it and that's it */
282  Directory,
283  CommandLine,
284  MuSessionId,
286  &ProcessInformation);
287  if (!NT_SUCCESS(Status))
288  {
289  /* Handle failures */
290  DPRINT1("SMSS: SmpLoadSubSystem - SmpExecuteImage Failed with Status %lx\n",
291  Status);
292  goto Quickie2;
293  }
294  }
295 
296  /* Fill out the handle and client ID in the subsystem structure now */
297  NewSubsystem->ProcessHandle = ProcessInformation.ProcessHandle;
298  NewSubsystem->ClientId = ProcessInformation.ClientId;
299 
300  /* Check if we launched a native image or a subsystem-backed image */
301  if (ProcessInformation.ImageInformation.SubSystemType == IMAGE_SUBSYSTEM_NATIVE)
302  {
303  /* This must be CSRSS itself, since it's a native subsystem image */
304  SubSysProcessId = ProcessInformation.ClientId.UniqueProcess;
305  if ((ProcessId) && !(*ProcessId)) *ProcessId = SubSysProcessId;
306 
307  /* Was this the initial CSRSS on Session 0? */
308  if (!MuSessionId)
309  {
310  /* Then save it in the global variables */
311  SmpWindowsSubSysProcessId = SubSysProcessId;
312  SmpWindowsSubSysProcess = ProcessInformation.ProcessHandle;
313  }
315  }
316  else
317  {
318  /* This is the POSIX or OS/2 subsystem process, copy its information */
319  RtlCopyMemory(&CreateSession->ProcessInfo,
320  &ProcessInformation,
321  sizeof(CreateSession->ProcessInfo));
322 
323  /* Not sure these field mean what I think they do -- but clear them */
324  *(PULONGLONG)&CreateSession->ClientId = 0;
325  CreateSession->MuSessionId = 0;
326 
327  /* This should find CSRSS because they are POSIX or OS/2 subsystems */
328  Subsystem = SmpLocateKnownSubSysByType(MuSessionId,
329  ProcessInformation.ImageInformation.SubSystemType);
330  if (!Subsystem)
331  {
332  /* Odd failure -- but handle it anyway */
334  DPRINT1("SMSS: SmpLoadSubSystem - SmpLocateKnownSubSysByType Failed with Status %lx for sessionid %lu\n",
335  Status,
336  MuSessionId);
337  goto Quickie;
338  }
339 
340  /* Duplicate the parent process handle for the subsystem to have */
342  ProcessInformation.ProcessHandle,
343  Subsystem->ProcessHandle,
344  &CreateSession->ProcessInfo.ProcessHandle,
346  0,
347  0);
348  if (!NT_SUCCESS(Status))
349  {
350  /* Fail since this is critical */
351  DPRINT1("SMSS: SmpLoadSubSystem - NtDuplicateObject Failed with Status %lx for sessionid %lu\n",
352  Status,
353  MuSessionId);
354  goto Quickie;
355  }
356 
357  /* Duplicate the initial thread handle for the subsystem to have */
359  ProcessInformation.ThreadHandle,
360  Subsystem->ProcessHandle,
361  &CreateSession->ProcessInfo.ThreadHandle,
363  0,
364  0);
365  if (!NT_SUCCESS(Status))
366  {
367  /* Fail since this is critical */
368  DPRINT1("SMSS: SmpLoadSubSystem - NtDuplicateObject Failed with Status %lx for sessionid %lu\n",
369  Status,
370  MuSessionId);
371  goto Quickie;
372  }
373 
374  /* Allocate an internal Session ID for this subsystem */
375  MuSessionId = SmpAllocateSessionId(Subsystem, 0);
376  CreateSession->SessionId = MuSessionId;
377 
378  /* Send the create session message to the subsystem */
379  SbApiMsg2.ReturnValue = STATUS_SUCCESS;
380  SbApiMsg2.h.u2.ZeroInit = 0;
381  SbApiMsg2.h.u1.s1.DataLength = sizeof(SB_CREATE_SESSION_MSG) + 8;
382  SbApiMsg2.h.u1.s1.TotalLength = sizeof(SB_API_MSG);
384  &SbApiMsg2.h,
385  &SbApiMsg2.h);
386  if (NT_SUCCESS(Status)) Status = SbApiMsg2.ReturnValue;
387  if (!NT_SUCCESS(Status))
388  {
389  /* Delete the session and handle failure if the LPC call failed */
390  SmpDeleteSession(CreateSession->SessionId);
391  DPRINT1("SMSS: SmpLoadSubSystem - NtRequestWaitReplyPort Failed with Status %lx for sessionid %lu\n",
392  Status,
393  CreateSession->SessionId);
394  goto Quickie;
395  }
396  }
397 
398  /* Okay, everything looks good to go, initialize this subsystem now! */
399  Status = NtResumeThread(ProcessInformation.ThreadHandle, NULL);
400  if (!NT_SUCCESS(Status))
401  {
402  /* That didn't work -- back out of everything */
403  DPRINT1("SMSS: SmpLoadSubSystem - NtResumeThread failed Status %lx\n", Status);
404  goto Quickie;
405  }
406 
407  /* Check if this was the subsystem for a different session */
408  if (MuSessionId)
409  {
410  /* Wait up to 60 seconds for it to initialize */
411  Timeout.QuadPart = -600000000;
412  Status = NtWaitForSingleObject(NewSubsystem->Event, FALSE, &Timeout);
413 
414  /* Timeout is done -- does this session still exist? */
415  if (!SmpCheckDuplicateMuSessionId(MuSessionId))
416  {
417  /* Nope, it died. Cleanup should've ocurred in a different path. */
418  DPRINT1("SMSS: SmpLoadSubSystem - session deleted\n");
419  return STATUS_DELETE_PENDING;
420  }
421 
422  /* Check if we timed our or there was another error with the wait */
423  if (Status != STATUS_WAIT_0)
424  {
425  /* Something is wrong with the subsystem, so back out of everything */
426  DPRINT1("SMSS: SmpLoadSubSystem - Timeout waiting for subsystem connect with Status %lx for sessionid %lu\n",
427  Status,
428  MuSessionId);
429  goto Quickie;
430  }
431  }
432  else
433  {
434  /* This a session 0 subsystem, just wait for it to initialize */
435  NtWaitForSingleObject(NewSubsystem->Event, FALSE, NULL);
436  }
437 
438  /* Subsystem is created, resumed, and initialized. Close handles and exit */
439  NtClose(ProcessInformation.ThreadHandle);
441  goto Quickie2;
442 
443 Quickie:
444  /* This is the failure path. First check if we need to detach from session */
445  if ((AttachedSessionId == -1) || (Flags & (SMP_POSIX_FLAG | SMP_OS2_FLAG)))
446  {
447  /* We were not attached, or did not launch subsystems that required it */
448  DPRINT1("SMSS: Did not detach from Session Space: SessionId=%x Flags=%x Status=%x\n",
451  Status);
452  }
453  else
454  {
455  /* Get the privilege we need for detachment */
457  if (!NT_SUCCESS(Status))
458  {
459  /* We can't detach without it */
460  DPRINT1("SMSS: Did not detach from Session Space: SessionId=%x Flags=%x Status=%x\n",
463  Status);
464  }
465  else
466  {
467  /* Now detach from the session */
470  sizeof(AttachedSessionId));
471  if (!NT_SUCCESS(Status))
472  {
473  /* Failed to detach. Note the DPRINT1 has a typo in Windows */
474  DPRINT1("SMSS: SmpStartCsr, Couldn't Detach from Session Space. Status=%x\n", Status);
476  }
477  else
478  {
479  /* Detachment worked, reset our attached session ID */
480  AttachedSessionId = -1;
481  }
482 
483  /* And release the privilege we acquired */
485  }
486  }
487 
488  /* Since this is the failure path, terminate the subsystem process */
489  NtTerminateProcess(ProcessInformation.ProcessHandle, Status);
490  NtClose(ProcessInformation.ThreadHandle);
491 
492 Quickie2:
493  /* This is the cleanup path -- first dereference our subsystems */
495  if (Subsystem) SmpDereferenceSubsystem(Subsystem);
496  if (KnownSubsystem) SmpDereferenceSubsystem(KnownSubsystem);
497 
498  /* In the failure case, destroy the new subsystem we just created */
499  if (!NT_SUCCESS(Status))
500  {
501  RemoveEntryList(&NewSubsystem->Entry);
502  NtSetEvent(NewSubsystem->Event, 0);
503  SmpDereferenceSubsystem(NewSubsystem);
504  }
505 
506  /* Finally, we're all done! */
508  return Status;
509 }
#define STATUS_DELETE_PENDING
Definition: ntstatus.h:322
ULONG ReferenceCount
Definition: smss.h:71
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2706
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define IMAGE_SUBSYSTEM_POSIX_CUI
Definition: ntimage.h:440
HANDLE PortHandle
Definition: smss.h:66
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
Definition: smsessn.c:37
HANDLE SmpWindowsSubSysProcessId
Definition: smsubsys.c:21
ULONG NTAPI SmpAllocateSessionId(IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
Definition: smsessn.c:123
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
PORT_MESSAGE h
Definition: smmsg.h:202
UNICODE_STRING SmpDefaultLibPath
Definition: sminit.c:28
#define TRUE
Definition: types.h:120
ULONG AttachedSessionId
Definition: smss.c:21
LONG NTSTATUS
Definition: precomp.h:26
#define SE_LOAD_DRIVER_PRIVILEGE
Definition: security.c:664
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define STATUS_NO_SUCH_PACKAGE
Definition: ntstatus.h:490
BOOLEAN Terminating
Definition: smss.h:70
VOID NTAPI SmpDeleteSession(IN ULONG SessionId)
Definition: smsessn.c:98
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
struct _SB_API_MSG SB_API_MSG
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define SMP_OS2_FLAG
Definition: smss.h:48
SB_CREATE_SESSION_MSG CreateSession
Definition: smmsg.h:212
#define InsertTailList(ListHead, Entry)
ULONG ImageType
Definition: smss.h:65
HANDLE UniqueProcess
Definition: compat.h:684
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define IMAGE_SUBSYSTEM_OS2_CUI
Definition: ntimage.h:439
HANDLE ProcessHandle
Definition: smss.h:64
SB_CREATE_PROCESS_MSG CreateProcess
Definition: smmsg.h:215
#define FALSE
Definition: types.h:117
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
struct _SB_CREATE_SESSION_MSG SB_CREATE_SESSION_MSG
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19
HANDLE Event
Definition: smss.h:63
#define SMP_POSIX_FLAG
Definition: smss.h:47
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS ReturnValue
Definition: smmsg.h:209
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63
Status
Definition: gdiplustypes.h:24
SECTION_IMAGE_INFORMATION ImageInformation
Definition: rtltypes.h:1571
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:454
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG SmBaseTag
Definition: sminit.c:25
HANDLE SbApiPort
Definition: smss.h:67
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
VOID NTAPI SmpReleasePrivilege(IN PVOID State)
Definition: smutil.c:129
BOOLEAN SmpDebug
Definition: smss.c:22
#define SMP_INVALID_PATH
Definition: smss.h:45
#define CreateProcess
Definition: winbase.h:3598
NTSTATUS NTAPI SmpAcquirePrivilege(IN ULONG Privilege, OUT PVOID *PrivilegeStat)
Definition: smutil.c:40
ULONG MuSessionId
Definition: smss.h:69
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
struct _FileName FileName
Definition: fatprocs.h:893
VOID NTAPI SmpDereferenceSubsystem(IN PSMP_SUBSYSTEM SubSystem)
Definition: smsubsys.c:47
static ULONG Timeout
Definition: ping.c:61
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
LIST_ENTRY Entry
Definition: smss.h:62
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType(IN ULONG MuSessionId, IN ULONG ImageType)
Definition: smsubsys.c:102
#define NULL
Definition: types.h:112
HANDLE SmpWindowsSubSysProcess
Definition: smsubsys.c:20
#define DPRINT1
Definition: precomp.h:8
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:3407
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:384
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:42
base for all directory entries
Definition: entries.h:138
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define SMP_DEFERRED_FLAG
Definition: smss.h:46
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ BOOLEAN _In_ USHORT Directory
Definition: rtlfuncs.h:3872
CLIENT_ID ClientId
Definition: smss.h:68
NTSTATUS NTAPI SmpCallCsrCreateProcess(IN PSB_API_MSG SbApiMsg, IN USHORT MessageLength, IN HANDLE PortHandle)
Definition: smsubsys.c:29
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by SmpExecuteCommand().

◆ SmpLoadSubSystemsForMuSession()

NTSTATUS NTAPI SmpLoadSubSystemsForMuSession ( IN PULONG  MuSessionId,
OUT PHANDLE  ProcessId,
IN PUNICODE_STRING  InitialCommand 
)

Definition at line 513 of file smsubsys.c.

516 {
517  NTSTATUS Status = STATUS_SUCCESS, Status2;
520  PLIST_ENTRY NextEntry;
522  PVOID State;
523 
524  /* Write a few last registry keys with the boot partition information */
526 
527  /* Process "SetupExecute" values */
528  NextEntry = SmpSetupExecuteList.Flink;
529  while (NextEntry != &SmpSetupExecuteList)
530  {
531  /* Execute each one and move on */
533  SmpExecuteCommand(&RegEntry->Name, 0, NULL, 0);
534  NextEntry = NextEntry->Flink;
535  }
536 
537  /* Now process the subsystems */
538  NextEntry = SmpSubSystemList.Flink;
539  while (NextEntry != &SmpSubSystemList)
540  {
541  /* Get the entry and check if this is the special Win32k entry */
543  if (_wcsicmp(RegEntry->Name.Buffer, L"Kmode") == 0)
544  {
545  /* Translate it */
546  if (!RtlDosPathNameToNtPathName_U(RegEntry->Value.Buffer,
547  &NtPath,
548  NULL,
549  NULL))
550  {
552  DPRINT1("Failed: %lx\n", Status);
553  }
554  else
555  {
556  /* Get the driver privilege */
558  if (NT_SUCCESS(Status))
559  {
560  /* Create the new session */
561  ASSERT(AttachedSessionId == -1);
563  MuSessionId,
564  sizeof(*MuSessionId));
565  if (!NT_SUCCESS(Status))
566  {
567  DPRINT1("SMSS: Session space creation failed\n");
569  RtlFreeHeap(RtlGetProcessHeap(), 0, NtPath.Buffer);
570  return Status;
571  }
572  AttachedSessionId = *MuSessionId;
573 
574  /*
575  * Start Win32k.sys on this session. Use a hardcoded value
576  * instead of the Kmode one...
577  */
579  L"\\SystemRoot\\System32\\win32k.sys");
582  sizeof(DestinationString));
583  RtlFreeHeap(RtlGetProcessHeap(), 0, NtPath.Buffer);
585  if (!NT_SUCCESS(Status))
586  {
587  DPRINT1("SMSS: Load of WIN32K failed.\n");
588  return Status;
589  }
590  }
591  }
592  }
593 
594  /* Next entry */
595  NextEntry = NextEntry->Flink;
596  }
597 
598  /* Now parse the required subsystem list */
599  NextEntry = SmpSubSystemsToLoad.Flink;
600  while (NextEntry != &SmpSubSystemsToLoad)
601  {
602  /* Get each entry and check if it's the internal debug or not */
604  if (_wcsicmp(RegEntry->Name.Buffer, L"Debug") == 0)
605  {
606  /* Load the internal debug system */
608  *MuSessionId,
609  ProcessId,
611  }
612  else
613  {
614  /* Load the required subsystem */
616  *MuSessionId,
617  ProcessId,
619  }
620  if (!NT_SUCCESS(Status))
621  {
622  DbgPrint("SMSS: Subsystem execute failed (%wZ)\n", &RegEntry->Value);
623  return Status;
624  }
625 
626  /* Move to the next entry */
627  NextEntry = NextEntry->Flink;
628  }
629 
630  /* Process the "Execute" list now */
631  NextEntry = SmpExecuteList.Blink;
632  if (NextEntry != &SmpExecuteList)
633  {
634  /* Get the custom initial command */
636 
637  /* Write the initial command and wait for 5 seconds (why??!) */
638  *InitialCommand = RegEntry->Name;
639  Timeout.QuadPart = -50000000;
641  }
642  else
643  {
644  /* Use the default Winlogon initial command */
645  RtlInitUnicodeString(InitialCommand, L"winlogon.exe");
647 
648  /* Check if there's a debugger for Winlogon */
649  Status2 = LdrQueryImageFileExecutionOptions(InitialCommand,
650  L"Debugger",
651  REG_SZ,
653  sizeof(InitialCommandBuffer) -
654  InitialCommand->Length,
655  NULL);
656  if ((NT_SUCCESS(Status2)) && (InitialCommandBuffer[0]))
657  {
658  /* Put the debugger string with the Winlogon string */
660  RtlStringCbCatW(InitialCommandBuffer, sizeof(InitialCommandBuffer), InitialCommand->Buffer);
662  }
663  }
664 
665  /* Finally check if there was a custom initial command */
666  NextEntry = SmpExecuteList.Flink;
667  while (NextEntry != &SmpExecuteList)
668  {
669  /* Execute each one */
671  SmpExecuteCommand(&RegEntry->Name, *MuSessionId, NULL, 0);
672  NextEntry = NextEntry->Flink;
673  }
674 
675  /* Return status */
676  return Status;
677 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2706
#define DbgPrint
Definition: loader.c:25
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
ULONG AttachedSessionId
Definition: smss.c:21
LONG NTSTATUS
Definition: precomp.h:26
#define SE_LOAD_DRIVER_PRIVILEGE
Definition: security.c:664
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
NTSTRSAFEAPI RtlStringCbCatW(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:636
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
WCHAR InitialCommandBuffer[256]
Definition: smsubsys.c:23
LIST_ENTRY SmpSubSystemsToLoad
Definition: sminit.c:21
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1868
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
NTSTATUS NTAPI NtDelayExecution(IN BOOLEAN Alertable, IN PLARGE_INTEGER DelayInterval)
Definition: wait.c:879
Status
Definition: gdiplustypes.h:24
LIST_ENTRY SmpSetupExecuteList
Definition: sminit.c:19
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI SmpTranslateSystemPartitionInformation(VOID)
Definition: sminit.c:786
Registry entry.
Definition: regfs.h:30
VOID NTAPI SmpReleasePrivilege(IN PVOID State)
Definition: smutil.c:129
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:119
#define SystemExtendServiceTableInformation
Definition: DriverTester.h:35
NTSTATUS NTAPI SmpAcquirePrivilege(IN ULONG Privilege, OUT PVOID *PrivilegeStat)
Definition: smutil.c:40
NTSTATUS NTAPI LdrQueryImageFileExecutionOptions(IN PUNICODE_STRING SubKey, IN PCWSTR ValueName, IN ULONG Type, OUT PVOID Buffer, IN ULONG BufferSize, OUT PULONG ReturnedLength OPTIONAL)
Definition: ldrinit.c:386
NTSTATUS NTAPI SmpExecuteCommand(IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, OUT PHANDLE ProcessId, IN ULONG Flags)
Definition: smss.c:221
LIST_ENTRY SmpExecuteList
Definition: sminit.c:22
static ULONG Timeout
Definition: ping.c:61
#define SMP_DEBUG_FLAG
Definition: smss.h:41
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:44
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
LIST_ENTRY SmpSubSystemList
Definition: sminit.c:21
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_OBJECT_PATH_SYNTAX_BAD
Definition: ntstatus.h:295
base of all file and directory entries
Definition: entries.h:82
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
#define REG_SZ
Definition: layer.c:22

Referenced by SmpLoadDataFromRegistry().

◆ SmpLocateKnownSubSysByCid()

PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByCid ( IN PCLIENT_ID  ClientId)

Definition at line 68 of file smsubsys.c.

69 {
70  PSMP_SUBSYSTEM Subsystem = NULL;
71  PLIST_ENTRY NextEntry;
72 
73  /* Lock the subsystem database */
75 
76  /* Loop each subsystem in the database */
77  NextEntry = SmpKnownSubSysHead.Flink;
78  while (NextEntry != &SmpKnownSubSysHead)
79  {
80  /* Check if this one matches the client ID and is still valid */
81  Subsystem = CONTAINING_RECORD(NextEntry, SMP_SUBSYSTEM, Entry);
82  if ((*(PULONGLONG)&Subsystem->ClientId == *(PULONGLONG)ClientId) &&
83  !(Subsystem->Terminating))
84  {
85  /* Add a reference and return it */
86  Subsystem->ReferenceCount++;
87  break;
88  }
89 
90  /* Reset the current pointer and keep earching */
91  Subsystem = NULL;
92  NextEntry = NextEntry->Flink;
93  }
94 
95  /* Release the lock and return the subsystem we found */
97  return Subsystem;
98 }
ULONG ReferenceCount
Definition: smss.h:71
BOOLEAN Terminating
Definition: smss.h:70
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
Definition: typedefs.h:119
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
#define NULL
Definition: types.h:112
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:384
base of all file and directory entries
Definition: entries.h:82
CLIENT_ID ClientId
Definition: smss.h:68

Referenced by SmpHandleConnectionRequest().

◆ SmpLocateKnownSubSysByType()

PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType ( IN ULONG  MuSessionId,
IN ULONG  ImageType 
)

Definition at line 102 of file smsubsys.c.

104 {
105  PSMP_SUBSYSTEM Subsystem = NULL;
106  PLIST_ENTRY NextEntry;
107 
108  /* Lock the subsystem database */
110 
111  /* Loop each subsystem in the database */
112  NextEntry = SmpKnownSubSysHead.Flink;
113  while (NextEntry != &SmpKnownSubSysHead)
114  {
115  /* Check if this one matches the image and uID, and is still valid */
116  Subsystem = CONTAINING_RECORD(NextEntry, SMP_SUBSYSTEM, Entry);
117  if ((Subsystem->ImageType == ImageType) &&
118  !(Subsystem->Terminating) &&
119  (Subsystem->MuSessionId == MuSessionId))
120  {
121  /* Return it referenced for the caller */
122  Subsystem->ReferenceCount++;
123  break;
124  }
125 
126  /* Reset the current pointer and keep earching */
127  Subsystem = NULL;
128  NextEntry = NextEntry->Flink;
129  }
130 
131  /* Release the lock and return the subsystem we found */
133  return Subsystem;
134 }
ULONG ReferenceCount
Definition: smss.h:71
BOOLEAN Terminating
Definition: smss.h:70
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
ULONG ImageType
Definition: smss.h:65
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
LIST_ENTRY SmpKnownSubSysHead
Definition: smsubsys.c:19
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
ULONG MuSessionId
Definition: smss.h:69
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
#define NULL
Definition: types.h:112
ImageType
Definition: gdiplusenums.h:192
base of all file and directory entries
Definition: entries.h:82

Referenced by SmpHandleConnectionRequest(), SmpLoadSubSystem(), and SmpSbCreateSession().

◆ SmpPagingFileInitialize()

VOID NTAPI SmpPagingFileInitialize ( VOID  )

Definition at line 75 of file pagefile.c.

76 {
77  /* Initialize the two lists */
80 }
LIST_ENTRY SmpVolumeDescriptorList
Definition: pagefile.c:67
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY SmpPagingFileDescriptorList
Definition: pagefile.c:67

Referenced by SmpLoadDataFromRegistry().

◆ SmpParseCommandLine()

NTSTATUS NTAPI SmpParseCommandLine ( IN PUNICODE_STRING  CommandLine,
OUT PULONG  Flags,
OUT PUNICODE_STRING  FileName,
OUT PUNICODE_STRING  Directory,
OUT PUNICODE_STRING  Arguments 
)

Definition at line 233 of file smutil.c.

238 {
239  ULONG Length;
240  UNICODE_STRING EnvString, PathString, CmdLineCopy, Token;
241  WCHAR PathBuffer[MAX_PATH];
242  PWCHAR FilePart;
244  UNICODE_STRING FullPathString;
245 
246  /* Initialize output arguments to NULL */
248  RtlInitUnicodeString(Arguments, NULL);
250 
251  /* Check if we haven't yet built a full default path or system root yet */
252  if (!SmpSystemRoot.Length)
253  {
254  /* Initialize it based on shared user data string */
256 
257  /* Allocate an empty string for the path */
259  sizeof(L"\\system32;");
260  RtlInitEmptyUnicodeString(&FullPathString,
262  (USHORT)Length);
263  if (FullPathString.Buffer)
264  {
265  /* Append the root, system32;, and then the current library path */
267  RtlAppendUnicodeToString(&FullPathString, L"\\system32;");
270  SmpDefaultLibPath = FullPathString;
271  }
272  }
273 
274  /* Consume the command line */
275  CmdLineCopy = *CommandLine;
276  while (TRUE)
277  {
278  /* Parse the first token and check for modifiers/specifiers */
279  Status = SmpParseToken(&CmdLineCopy, FALSE, &Token);
280  if (!(NT_SUCCESS(Status)) || !(Token.Buffer)) return STATUS_UNSUCCESSFUL;
281  if (!Flags) break;
282 
283  /* Debug requested? */
285  {
286  /* Convert into a flag */
287  *Flags |= SMP_DEBUG_FLAG;
288  }
290  {
291  /* Asynch requested, convert into a flag */
292  *Flags |= SMP_ASYNC_FLAG;
293  }
295  {
296  /* Autochk requested, convert into a flag */
298  }
299  else
300  {
301  /* No specifier found, keep going */
302  break;
303  }
304 
305  /* Get rid of this token and get the next */
307  }
308 
309  /* Initialize a string to hold the current path */
310  RtlInitUnicodeString(&EnvString, L"Path");
311  Length = PAGE_SIZE;
312  RtlInitEmptyUnicodeString(&PathString,
314  (USHORT)Length);
315  if (!PathString.Buffer)
316  {
317  /* Fail if we have no memory for this */
320  }
321 
322  /* Query the path from the environment */
324  &EnvString,
325  &PathString);
327  {
328  /* Our buffer was too small, free it */
329  RtlFreeHeap(SmpHeap, 0, PathString.Buffer);
330 
331  /* And allocate one big enough */
332  Length = PathString.Length + sizeof(UNICODE_NULL);
333  RtlInitEmptyUnicodeString(&PathString,
335  (USHORT)Length);
336  if (!PathString.Buffer)
337  {
338  /* Fail if we have no memory for this */
341  }
342 
343  /* Now try again, this should work */
345  &EnvString,
346  &PathString);
347  }
348  if (!NT_SUCCESS(Status))
349  {
350  /* Another failure means that the kernel hasn't passed the path correctly */
351  DPRINT1("SMSS: %wZ environment variable not defined.\n", &EnvString);
353  }
354  else
355  {
356  /* Check if the caller expects any flags out of here */
357  if (Flags)
358  {
359  /* We can return the image not found flag -- so does the image exist */
360  if (!(RtlDosSearchPath_U(PathString.Buffer,
361  Token.Buffer,
362  L".exe",
363  sizeof(PathBuffer),
364  PathBuffer,
365  &FilePart)) &&
367  Token.Buffer,
368  L".exe",
369  sizeof(PathBuffer),
370  PathBuffer,
371  &FilePart)))
372  {
373  /* It doesn't, let the caller know about it and exit */
375  *FileName = Token;
376  RtlFreeHeap(SmpHeap, 0, PathString.Buffer);
377  return STATUS_SUCCESS;
378  }
379  }
380  else
381  {
382  /* Caller doesn't want flags, probably wants the image itself */
383  RtlStringCbCopyW(PathBuffer, sizeof(PathBuffer), Token.Buffer);
384  }
385  }
386 
387  /* Free tokens and such, all that's left is to convert the image name */
389  RtlFreeHeap(SmpHeap, 0, PathString.Buffer);
390  if (!NT_SUCCESS(Status)) return Status;
391 
392  /* Convert it and bail out if this failed */
393  if (!RtlDosPathNameToNtPathName_U(PathBuffer, FileName, NULL, NULL))
394  {
395  DPRINT1("SMSS: Unable to translate %ws into an NT File Name\n",
396  &PathBuffer);
398  }
399  if (!NT_SUCCESS(Status)) return Status;
400 
401  /* Finally, check if the caller also wanted the directory */
402  if (Directory)
403  {
404  /* Is the file a relative name with no directory? */
405  if (FilePart <= PathBuffer)
406  {
407  /* Clear it */
409  }
410  else
411  {
412  /* There is a directory, and a filename -- separate those two */
413  *--FilePart = UNICODE_NULL;
414  RtlCreateUnicodeString(Directory, PathBuffer);
415  }
416  }
417 
418  /* We are done -- move on to the second pass to get the arguments */
419  return SmpParseToken(&CmdLineCopy, TRUE, Arguments);
420 }
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define SMP_AUTOCHK_FLAG
Definition: smss.h:43
UNICODE_STRING SmpDebugKeyword
Definition: smutil.c:34
USHORT MaximumLength
Definition: env_spec_w32.h:370
UNICODE_STRING SmpDefaultLibPath
Definition: sminit.c:28
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSYSAPI ULONG NTAPI RtlDosSearchPath_U(_In_ PCWSTR Path, _In_ PCWSTR FileName, _In_ PCWSTR Extension, _In_ ULONG BufferSize, _Out_ PWSTR Buffer, _Out_ PWSTR *PartName)
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
PWCHAR SmpDefaultEnvironment
Definition: sminit.c:27
PVOID SmpHeap
Definition: sminit.c:24
NTSTATUS NTAPI SmpParseToken(IN PUNICODE_STRING Input, IN BOOLEAN SecondPass, OUT PUNICODE_STRING Token)
Definition: smutil.c:155
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
UNICODE_STRING SmpASyncKeyword
Definition: smutil.c:34
Status
Definition: gdiplustypes.h:24
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING SmpSystemRoot
Definition: smss.c:20
ULONG SmBaseTag
Definition: sminit.c:25
#define MAX_PATH
Definition: compat.h:34
PCHAR Buffer
Definition: ntsecapi.h:174
UNICODE_STRING SmpAutoChkKeyword
Definition: smutil.c:34
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define SMP_ASYNC_FLAG
Definition: smss.h:42
#define SharedUserData
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static const WCHAR L[]
Definition: oid.c:1250
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SMP_INVALID_PATH
Definition: smss.h:45
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
unsigned short USHORT
Definition: pedump.c:61
#define SMP_DEBUG_FLAG
Definition: smss.h:41
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:293
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
base for all directory entries
Definition: entries.h:138
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)

Referenced by SmpCreatePagingFileDescriptor(), SmpExecuteCommand(), and SmpExecuteInitialCommand().

◆ SmpQueryRegistrySosOption()

BOOLEAN NTAPI SmpQueryRegistrySosOption ( VOID  )

Definition at line 424 of file smutil.c.

425 {
430  ULONG Length;
431  WCHAR ValueBuffer[VALUE_BUFFER_SIZE];
432  PKEY_VALUE_PARTIAL_INFORMATION PartialInfo = (PVOID)ValueBuffer;
433 
434  /* Open the key */
436  L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
438  &KeyName,
440  NULL,
441  NULL);
443  if (!NT_SUCCESS(Status))
444  {
445  DPRINT1("SMSS: Cannot open control key (Status 0x%x)\n", Status);
446  return FALSE;
447  }
448 
449  /* Query the value */
450  RtlInitUnicodeString(&ValueName, L"SystemStartOptions");
452  &ValueName,
454  PartialInfo,
455  sizeof(ValueBuffer),
456  &Length);
459  if (!NT_SUCCESS(Status) ||
460  ((PartialInfo->Type != REG_SZ) && (PartialInfo->Type != REG_EXPAND_SZ)))
461  {
462  DPRINT1("SMSS: Cannot query value key (Type %lu, Status 0x%x)\n",
463  PartialInfo->Type, Status);
464  return FALSE;
465  }
466 
467  /* Check if it's set to SOS or sos */
468  if (!(wcsstr((PWCHAR)PartialInfo->Data, L"SOS")) ||
469  (wcsstr((PWCHAR)PartialInfo->Data, L"sos")))
470  {
471  /* It's not set, return FALSE */
472  return FALSE;
473  }
474 
475  /* It's set, return TRUE */
476  return TRUE;
477 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
LONG NTSTATUS
Definition: precomp.h:26
#define VALUE_BUFFER_SIZE
Definition: smutil.c:23
uint16_t * PWCHAR
Definition: typedefs.h:56
#define FALSE
Definition: types.h:117
void * PVOID
Definition: retypes.h:9
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define ASSERT(a)
Definition: mode.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
static const WCHAR L[]
Definition: oid.c:1250
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_SZ
Definition: layer.c:22

Referenced by SmpInvokeAutoChk().

◆ SmpReleasePrivilege()

VOID NTAPI SmpReleasePrivilege ( IN PVOID  State)

Definition at line 129 of file smutil.c.

130 {
132 
133  /* Adjust the privileges in the token */
134  NtAdjustPrivilegesToken(State->TokenHandle,
135  FALSE,
136  State->OldPrivileges,
137  0,
138  NULL,
139  NULL);
140 
141  /* Check if we used a dynamic buffer */
142  if (State->OldPrivileges != (PTOKEN_PRIVILEGES)&State->OldBuffer)
143  {
144  /* Free it */
145  RtlFreeHeap(SmpHeap, 0, State->OldPrivileges);
146  }
147 
148  /* Close the token handle and free the state structure */
149  NtClose(State->TokenHandle);
151 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define FALSE
Definition: types.h:117
PVOID SmpHeap
Definition: sminit.c:24
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
struct _SMP_PRIVILEGE_STATE * PSMP_PRIVILEGE_STATE
#define NULL
Definition: types.h:112
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtAdjustPrivilegesToken(_In_ HANDLE TokenHandle, _In_ BOOLEAN DisableAllPrivileges, _In_opt_ PTOKEN_PRIVILEGES NewState, _In_ ULONG BufferLength, _Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_PRIVILEGES PreviousState, _When_(PreviousState!=NULL, _Out_) PULONG ReturnLength)
Definition: token.c:3214

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

◆ SmpRestoreBootStatusData()

VOID NTAPI SmpRestoreBootStatusData ( IN BOOLEAN  BootOkay,
IN BOOLEAN  ShutdownOkay 
)

Definition at line 531 of file smutil.c.

533 {
535  PVOID BootState;
536 
537  /* Lock the BSD */
538  Status = RtlLockBootStatusData(&BootState);
539  if (NT_SUCCESS(Status))
540  {
541  /* Write the bootokay and bootshutdown values */
542  RtlGetSetBootStatusData(BootState,
543  FALSE,
545  &BootOkay,
546  sizeof(BootOkay),
547  NULL);
548  RtlGetSetBootStatusData(BootState,
549  FALSE,
551  &ShutdownOkay,
552  sizeof(ShutdownOkay),
553  NULL);
554 
555  /* Unlock the BSD and return */
556  RtlUnlockBootStatusData(BootState);
557  }
558 }
NTSTATUS NTAPI RtlLockBootStatusData(_Out_ PHANDLE FileHandle)
Definition: bootdata.c:231
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI RtlUnlockBootStatusData(_In_ HANDLE FileHandle)
Definition: bootdata.c:267
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
NTSTATUS NTAPI RtlGetSetBootStatusData(_In_ HANDLE FileHandle, _In_ BOOLEAN Read, _In_ RTL_BSD_ITEM_TYPE DataClass, _In_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnLength)
Definition: bootdata.c:161

Referenced by SmpInvokeAutoChk().

◆ SmpSaveAndClearBootStatusData()

BOOLEAN NTAPI SmpSaveAndClearBootStatusData ( OUT PBOOLEAN  BootOkay,
OUT PBOOLEAN  ShutdownOkay 
)

Definition at line 481 of file smutil.c.

483 {
485  BOOLEAN Value = TRUE;
486  PVOID BootStatusDataHandle;
487 
488  /* Assume failure */
489  *BootOkay = FALSE;
490  *ShutdownOkay = FALSE;
491 
492  /* Lock the BSD and fail if we couldn't */
493  Status = RtlLockBootStatusData(&BootStatusDataHandle);
494  if (!NT_SUCCESS(Status)) return FALSE;
495 
496  /* Read the old settings */
497  RtlGetSetBootStatusData(BootStatusDataHandle,
498  TRUE,
500  BootOkay,
501  sizeof(BOOLEAN),
502  NULL);
503  RtlGetSetBootStatusData(BootStatusDataHandle,
504  TRUE,
506  ShutdownOkay,
507  sizeof(BOOLEAN),
508  NULL);
509 
510  /* Set new ones indicating we got at least this far */
511  RtlGetSetBootStatusData(BootStatusDataHandle,
512  FALSE,
514  &Value,
515  sizeof(Value),
516  NULL);
517  RtlGetSetBootStatusData(BootStatusDataHandle,
518  FALSE,
520  &Value,
521  sizeof(Value),
522  NULL);
523 
524  /* Unlock the BSD and return */
525  RtlUnlockBootStatusData(BootStatusDataHandle);
526  return TRUE;
527 }
NTSTATUS NTAPI RtlLockBootStatusData(_Out_ PHANDLE FileHandle)
Definition: bootdata.c:231
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI RtlUnlockBootStatusData(_In_ HANDLE FileHandle)
Definition: bootdata.c:267
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
NTSTATUS NTAPI RtlGetSetBootStatusData(_In_ HANDLE FileHandle, _In_ BOOLEAN Read, _In_ RTL_BSD_ITEM_TYPE DataClass, _In_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnLength)
Definition: bootdata.c:161

Referenced by SmpInvokeAutoChk().

◆ SmpSbCreateSession()

NTSTATUS NTAPI SmpSbCreateSession ( IN PVOID  Reserved,
IN PSMP_SUBSYSTEM  OtherSubsystem,
IN PRTL_USER_PROCESS_INFORMATION  ProcessInformation,
IN ULONG  MuSessionId,
IN PCLIENT_ID  DbgClientId 
)

Definition at line 31 of file smsbapi.c.

36 {
38  PSMP_SUBSYSTEM KnownSubsys;
39  SB_API_MSG SbApiMsg;
41  PSB_CREATE_SESSION_MSG CreateSessionMsg;
42 
43  /* Write out the create session message including its initial process */
44  CreateSessionMsg = &SbApiMsg.CreateSession;
45  CreateSessionMsg->ProcessInfo = *ProcessInformation;
46  CreateSessionMsg->MuSessionId = MuSessionId;
47  if (DbgClientId)
48  {
49  CreateSessionMsg->ClientId = *DbgClientId;
50  }
51  else
52  {
53  CreateSessionMsg->ClientId.UniqueThread = NULL;
54  CreateSessionMsg->ClientId.UniqueProcess = NULL;
55  }
56 
57  /* Find a subsystem responsible for this session */
58  SmpGetProcessMuSessionId(ProcessInformation->ProcessHandle, &MuSessionId);
59  if (!SmpCheckDuplicateMuSessionId(MuSessionId))
60  {
61  NtClose(ProcessInformation->ProcessHandle);
62  NtClose(ProcessInformation->ThreadHandle);
63  DPRINT1("SMSS: CreateSession status=%x\n", STATUS_OBJECT_NAME_NOT_FOUND);
65  }
66 
67  /* Find the subsystem we have for this initial process */
68  KnownSubsys = SmpLocateKnownSubSysByType(MuSessionId,
69  ProcessInformation->
70  ImageInformation.SubSystemType);
71  if (KnownSubsys)
72  {
73  /* Duplicate the process handle into the message */
75  ProcessInformation->ProcessHandle,
76  KnownSubsys->ProcessHandle,
77  &CreateSessionMsg->ProcessInfo.ProcessHandle,
79  0,
80  0);
81  if (NT_SUCCESS(Status))
82  {
83  /* Duplicate the thread handle into the message */
85  ProcessInformation->ThreadHandle,
86  KnownSubsys->ProcessHandle,
87  &CreateSessionMsg->ProcessInfo.ThreadHandle,
89  0,
90  0);
91  if (!NT_SUCCESS(Status))
92  {
93  /* Close everything on failure */
94  NtClose(ProcessInformation->ProcessHandle);
95  NtClose(ProcessInformation->ThreadHandle);
96  SmpDereferenceSubsystem(KnownSubsys);
97  DPRINT1("SmpSbCreateSession: NtDuplicateObject (Thread) Failed %lx\n", Status);
98  return Status;
99  }
100 
101  /* Close the original handles as they are no longer needed */
102  NtClose(ProcessInformation->ProcessHandle);
103  NtClose(ProcessInformation->ThreadHandle);
104 
105  /* Finally, allocate a new SMSS session ID for this session */
106  SessionId = SmpAllocateSessionId(KnownSubsys, OtherSubsystem);
107  CreateSessionMsg->SessionId = SessionId;
108 
109  /* Fill out the LPC message header and send it to the client! */
110  SbApiMsg.ApiNumber = SbpCreateSession;
111  SbApiMsg.h.u2.ZeroInit = 0;
112  SbApiMsg.h.u1.s1.DataLength = sizeof(SB_CREATE_SESSION_MSG) + 8;
113  SbApiMsg.h.u1.s1.TotalLength = sizeof(SbApiMsg);
114  Status = NtRequestWaitReplyPort(KnownSubsys->SbApiPort,
115  &SbApiMsg.h,
116  &SbApiMsg.h);
117  if (!NT_SUCCESS(Status))
118  {
119  /* Bail out */
120  DPRINT1("SmpSbCreateSession: NtRequestWaitReply Failed %lx\n", Status);
121  }
122  else
123  {
124  /* If the API succeeded, get the result value from the LPC */
125  Status = SbApiMsg.ReturnValue;
126  }
127 
128  /* Delete the session on any kind of failure */
130  }
131  else
132  {
133  /* Close the handles on failure */
134  DPRINT1("SmpSbCreateSession: NtDuplicateObject (Process) Failed %lx\n", Status);
135  NtClose(ProcessInformation->ProcessHandle);
136  NtClose(ProcessInformation->ThreadHandle);
137  }
138 
139  /* Dereference the subsystem and return the status of the LPC call */
140  SmpDereferenceSubsystem(KnownSubsys);
141  return Status;
142  }
143 
144  /* If we don't yet have a subsystem, only native images can be launched */
145  if (ProcessInformation->ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
146  {
147  /* Fail */
148  DPRINT1("SMSS: %s SubSystem has not been started.\n",
149  SmpSubSystemNames[ProcessInformation->ImageInformation.SubSystemType]);
151  NtClose(ProcessInformation->ProcessHandle);
152  NtClose(ProcessInformation->ThreadHandle);
153  return Status;
154  }
155 
156 #if 0
157  /* This code handles debug applications, but it seems vestigial... */
158  if ((*(ULONGLONG)&CreateSessionMsg.ClientId) && (SmpDbgSsLoaded))
159  {
160  Process = RtlAllocateHeap(SmpHeap, SmBaseTag, sizeof(SMP_PROCESS));
161  if (!Process)
162  {
163  DPRINT1("Unable to initialize debugging for Native App %lx.%lx -- out of memory\n",
164  ProcessInformation->ClientId.UniqueProcess,
165  ProcessInformation->ClientId.UniqueThread);
166  NtClose(ProcessInformation->ProcessHandle);
167  NtClose(ProcessInformation->ThreadHandle);
168  return STATUS_NO_MEMORY;
169  }
170 
171  Process->DbgClientId = CreateSessionMsg->ClientId;
172  Process->ClientId = ProcessInformation->ClientId;
174  DPRINT1("Native Debug App %lx.%lx\n", Process->ClientId.UniqueProcess, Process->ClientId.UniqueThread);
175 
176  Status = NtSetInformationProcess(ProcessInformation->ProcessHandle, 7, &SmpDebugPort, 4);
178  }
179 #endif
180 
181  /* This is a native application being started as the initial command */
182  DPRINT("Subsystem active, starting thread\n");
183  NtClose(ProcessInformation->ProcessHandle);
184  NtResumeThread(ProcessInformation->ThreadHandle, NULL);
185  NtClose(ProcessInformation->ThreadHandle);
186  return STATUS_SUCCESS;
187 }
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
Definition: smsessn.c:37
ULONG NTAPI SmpAllocateSessionId(IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
Definition: smsessn.c:123
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
PORT_MESSAGE h
Definition: smmsg.h:202
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI SmpDeleteSession(IN ULONG SessionId)
Definition: smsessn.c:98
SB_CREATE_SESSION_MSG CreateSession
Definition: smmsg.h:212
LIST_ENTRY NativeProcessList
Definition: sminit.c:22
HANDLE UniqueProcess
Definition: compat.h:684
NTSTATUS NTAPI SmpGetProcessMuSessionId(IN HANDLE ProcessHandle, OUT PULONG SessionId)
Definition: smsessn.c:168
RTL_USER_PROCESS_INFORMATION ProcessInfo
Definition: smmsg.h:145
HANDLE ProcessHandle
Definition: smss.h:64
PVOID SmpHeap
Definition: sminit.c:24
SB_API_NUMBER ApiNumber
Definition: smmsg.h:208
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
struct _SB_CREATE_SESSION_MSG SB_CREATE_SESSION_MSG
void DPRINT(...)
Definition: polytest.cpp:61
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS ReturnValue
Definition: smmsg.h:209
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
ULONG SmBaseTag
Definition: sminit.c:25
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType(IN ULONG MuSessionId, IN ULONG ImageType)
Definition: smsubsys.c:102
HANDLE SbApiPort
Definition: smss.h:67
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
CLIENT_ID ClientId
Definition: smmsg.h:148
HANDLE UniqueThread
Definition: compat.h:685
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
HANDLE SmpDebugPort
Definition: sminit.c:26
VOID NTAPI SmpDereferenceSubsystem(IN PSMP_SUBSYSTEM SubSystem)
Definition: smsubsys.c:47
BOOLEAN SmpDbgSsLoaded
Definition: smsessn.c:30
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1107
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
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:3407
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
PCHAR SmpSubSystemNames[]
Definition: smsbapi.c:18

Referenced by SmpExecPgm().

◆ SmpSetProcessMuSessionId()

NTSTATUS NTAPI SmpSetProcessMuSessionId ( IN HANDLE  ProcessHandle,
IN ULONG  SessionId 
)

Definition at line 199 of file smsessn.c.

201 {
203 
204  /* Tell the kernel about the session ID */
207  &SessionId,
208  sizeof(SessionId));
209  if (!NT_SUCCESS(Status))
210  {
211  DPRINT1("SMSS: SetProcessMuSessionId, Process=%p, Status=%x\n",
213  }
214 
215  /* Return */
216  return Status;
217 }
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1107
#define DPRINT1
Definition: precomp.h:8
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by SmpExecuteImage().

◆ SmpTerminate()

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

Definition at line 391 of file smss.c.

394 {
396  BOOLEAN Old;
397  ULONG Response;
398 
399  /* Give the shutdown privilege to the thread */
402  {
403  /* Thread doesn't have a token, give it to the entire process */
405  }
406 
407  /* Take down the process/machine with a hard error */
409  ParameterCount,
410  ParameterMask,
411  Parameters,
413  &Response);
414 
415  /* Terminate the process if the hard error didn't already */
417 }
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
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:553
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
Definition: ncftp.h:89
unsigned int ULONG
Definition: retypes.h:1
struct Response Response
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define STATUS_SYSTEM_PROCESS_TERMINATED
Definition: ntstatus.h:670

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

◆ SmpTranslateSystemPartitionInformation()

VOID NTAPI SmpTranslateSystemPartitionInformation ( VOID  )

Definition at line 786 of file sminit.c.

787 {
791  HANDLE KeyHandle, LinkHandle;
793  size_t StrLength;
794  WCHAR LinkBuffer[MAX_PATH];
795  CHAR ValueBuffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 512];
796  PKEY_VALUE_PARTIAL_INFORMATION PartialInfo = (PVOID)ValueBuffer;
797  CHAR DirInfoBuffer[sizeof(OBJECT_DIRECTORY_INFORMATION) + 512];
798  POBJECT_DIRECTORY_INFORMATION DirInfo = (PVOID)DirInfoBuffer;
799 
800  /* Open the setup key */
801  RtlInitUnicodeString(&UnicodeString, L"\\Registry\\Machine\\System\\Setup");
803  &UnicodeString,
805  NULL,
806  NULL);
808  if (!NT_SUCCESS(Status))
809  {
810  DPRINT1("SMSS: Cannot open system setup key for reading: 0x%x\n", Status);
811  return;
812  }
813 
814  /* Query the system partition */
815  RtlInitUnicodeString(&UnicodeString, L"SystemPartition");
817  &UnicodeString,
819  PartialInfo,
820  sizeof(ValueBuffer),
821  &Length);
823  if (!NT_SUCCESS(Status) ||
824  ((PartialInfo->Type != REG_SZ) && (PartialInfo->Type != REG_EXPAND_SZ)))
825  {
826  DPRINT1("SMSS: Cannot query SystemPartition value (Type %lu, Status 0x%x)\n",
827  PartialInfo->Type, Status);
828  return;
829  }
830 
831  /* Initialize the system partition string */
832  RtlInitEmptyUnicodeString(&SystemPartition,
833  (PWCHAR)PartialInfo->Data,
834  PartialInfo->DataLength);
836  SystemPartition.MaximumLength,
837  &StrLength);
838  SystemPartition.Length = (USHORT)StrLength;
839 
840  /* Enumerate the directory looking for the symbolic link string */
841  RtlInitUnicodeString(&SearchString, L"SymbolicLink");
842  RtlInitEmptyUnicodeString(&LinkTarget, LinkBuffer, sizeof(LinkBuffer));
844  DirInfo,
845  sizeof(DirInfoBuffer),
846  TRUE,
847  TRUE,
848  &Context,
849  NULL);
850  if (!NT_SUCCESS(Status))
851  {
852  DPRINT1("SMSS: Cannot find drive letter for system partition\n");
853  return;
854  }
855 
856  /* Keep searching until we find it */
857  do
858  {
859  /* Is this it? */
860  if ((RtlEqualUnicodeString(&DirInfo->TypeName, &SearchString, TRUE)) &&
861  (DirInfo->Name.Length == 2 * sizeof(WCHAR)) &&
862  (DirInfo->Name.Buffer[1] == L':'))
863  {
864  /* Looks like we found it, open the link to get its target */
866  &DirInfo->Name,
869  NULL);
870  Status = NtOpenSymbolicLinkObject(&LinkHandle,
873  if (NT_SUCCESS(Status))
874  {
875  /* Open worked, query the target now */
876  Status = NtQuerySymbolicLinkObject(LinkHandle,
877  &LinkTarget,
878  NULL);
879  NtClose(LinkHandle);
880 
881  /* Check if it matches the string we had found earlier */
882  if ((NT_SUCCESS(Status)) &&
884  &LinkTarget,
885  TRUE)) ||
887  &LinkTarget,
888  TRUE)) &&
889  (LinkTarget.Buffer[SystemPartition.Length / sizeof(WCHAR)] == L'\\'))))
890  {
891  /* All done */
892  break;
893  }
894  }
895  }
896 
897  /* Couldn't find it, try again */
899  DirInfo,
900  sizeof(DirInfoBuffer),
901  TRUE,
902  FALSE,
903  &Context,
904  NULL);
905  } while (NT_SUCCESS(Status));
906  if (!NT_SUCCESS(Status))
907  {
908  DPRINT1("SMSS: Cannot find drive letter for system partition\n");
909  return;
910  }
911 
912  /* Open the setup key again, for full access this time */
914  L"\\Registry\\Machine\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup");
916  &UnicodeString,
918  NULL,
919  NULL);
921  if (!NT_SUCCESS(Status))
922  {
923  DPRINT1("SMSS: Cannot open software setup key for writing: 0x%x\n",
924  Status);
925  return;
926  }
927 
928  /* Wrap up the end of the link buffer */
929  wcsncpy(LinkBuffer, DirInfo->Name.Buffer, 2);
930  LinkBuffer[2] = L'\\';
931  LinkBuffer[3] = L'\0';
932 
933  /* Now set this as the "BootDir" */
936  &UnicodeString,
937  0,
938  REG_SZ,
939  LinkBuffer,
940  4 * sizeof(WCHAR));
941  if (!NT_SUCCESS(Status))
942  {
943  DPRINT1("SMSS: couldn't write BootDir value: 0x%x\n", Status);
944  }
946 }
HANDLE SmpDosDevicesObjectDirectory
Definition: sminit.c:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
_Must_inspect_result_ NTSTRSAFEAPI RtlStringCbLengthW(_In_reads_or_z_(cbMax/sizeof(wchar_t)) STRSAFE_LPCWSTR psz, _In_ _In_range_(1, NTSTRSAFE_MAX_CCH *sizeof(wchar_t)) size_t cbMax, _Out_opt_ _Deref_out_range_(<, cbMax - 1) size_t *pcbLength)
Definition: ntstrsafe.h:1641
uint16_t * PWCHAR
Definition: typedefs.h:56
NTSTATUS NTAPI NtQueryDirectoryObject(IN HANDLE DirectoryHandle, OUT PVOID Buffer, IN ULONG BufferLength, IN BOOLEAN ReturnSingleEntry, IN BOOLEAN RestartScan, IN OUT PULONG Context, OUT PULONG ReturnLength OPTIONAL)
Definition: obdir.c:498
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
_Inout_ PUNICODE_STRING LinkTarget
Definition: zwfuncs.h:292
#define FALSE
Definition: types.h:117
void * PVOID
Definition: retypes.h:9
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static PPARTENTRY SystemPartition
Definition: usetup.c:61
static const WCHAR L[]
Definition: oid.c:1250
struct _OBJECT_DIRECTORY_INFORMATION OBJECT_DIRECTORY_INFORMATION
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
unsigned short USHORT
Definition: pedump.c:61
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define NULL
Definition: types.h:112
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define REG_SZ
Definition: layer.c:22

Referenced by SmpLoadSubSystemsForMuSession().

Variable Documentation

◆ AttachedSessionId

ULONG AttachedSessionId

Definition at line 21 of file smss.c.

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

◆ RegPosixSingleInstance

BOOLEAN RegPosixSingleInstance

Definition at line 22 of file smsubsys.c.

Referenced by SmpConfigureSubSystems().

◆ SmBaseTag

◆ SmpASyncKeyword

UNICODE_STRING SmpASyncKeyword

Definition at line 34 of file smutil.c.

Referenced by SmpLoadDataFromRegistry(), and SmpParseCommandLine().

◆ SmpAutoChkKeyword

UNICODE_STRING SmpAutoChkKeyword

Definition at line 34 of file smutil.c.

Referenced by SmpLoadDataFromRegistry(), and SmpParseCommandLine().

◆ SmpDbgSsLoaded

BOOLEAN SmpDbgSsLoaded

Definition at line 30 of file smsessn.c.

Referenced by SmpInit(), and SmpSbCreateSession().

◆ SmpDebug

BOOLEAN SmpDebug

Definition at line 22 of file smss.c.

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

◆ SmpDebugKeyword

UNICODE_STRING SmpDebugKeyword

Definition at line 34 of file smutil.c.

Referenced by SmpLoadDataFromRegistry(), and SmpParseCommandLine().

◆ SmpDefaultEnvironment

PWCHAR SmpDefaultEnvironment

Definition at line 27 of file sminit.c.

Referenced by SmpExecuteImage(), SmpLoadDataFromRegistry(), and SmpParseCommandLine().

◆ SmpDefaultLibPath

UNICODE_STRING SmpDefaultLibPath

◆ SmpExecuteList

LIST_ENTRY SmpExecuteList

Definition at line 22 of file sminit.c.

Referenced by SmpLoadDataFromRegistry(), and SmpLoadSubSystemsForMuSession().

◆ SmpHeap

◆ SmpKnownSubSysHead

◆ SmpKnownSubSysLock

◆ SmpNextSessionId

ULONG SmpNextSessionId

Definition at line 28 of file smsessn.c.

Referenced by SmpAllocateSessionId(), and SmpInit().

◆ SmpNextSessionIdScanMode

ULONG SmpNextSessionIdScanMode

Definition at line 29 of file smsessn.c.

Referenced by SmpAllocateSessionId(), and SmpInit().

◆ SmpSessionListHead

LIST_ENTRY SmpSessionListHead

Definition at line 27 of file smsessn.c.

Referenced by SmpAllocateSessionId(), SmpInit(), and SmpSessionIdToSession().

◆ SmpSessionListLock

RTL_CRITICAL_SECTION SmpSessionListLock

Definition at line 26 of file smsessn.c.

Referenced by SmpAllocateSessionId(), SmpDeleteSession(), and SmpInit().

◆ SmpSessionsObjectDirectory

HANDLE SmpSessionsObjectDirectory

Definition at line 31 of file smsessn.c.

Referenced by SmpLoadDataFromRegistry().

◆ SmpSetupExecuteList

LIST_ENTRY SmpSetupExecuteList

Definition at line 19 of file sminit.c.

Referenced by SmpLoadDataFromRegistry(), and SmpLoadSubSystemsForMuSession().

◆ SmpSubSystemList

LIST_ENTRY SmpSubSystemList

Definition at line 21 of file sminit.c.

Referenced by SmpLoadDataFromRegistry(), and SmpLoadSubSystemsForMuSession().

◆ SmpSubSystemsToLoad

LIST_ENTRY SmpSubSystemsToLoad

◆ SmpSystemRoot

UNICODE_STRING SmpSystemRoot

Definition at line 20 of file smss.c.

Referenced by SmpParseCommandLine().

◆ SmpWindowsSubSysProcess

HANDLE SmpWindowsSubSysProcess

Definition at line 20 of file smsubsys.c.

Referenced by SmpInit(), and SmpLoadSubSystem().

◆ SmpWindowsSubSysProcessId

HANDLE SmpWindowsSubSysProcessId

Definition at line 21 of file smsubsys.c.

Referenced by SmpLoadDataFromRegistry(), and SmpLoadSubSystem().