ReactOS  0.4.13-dev-92-gf251225
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 <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 40 of file smss.h.

◆ SMP_AUTOCHK_FLAG

#define SMP_AUTOCHK_FLAG   0x04

Definition at line 41 of file smss.h.

◆ SMP_DEBUG_FLAG

#define SMP_DEBUG_FLAG   0x01

Definition at line 39 of file smss.h.

◆ SMP_DEFERRED_FLAG

#define SMP_DEFERRED_FLAG   0x20

Definition at line 44 of file smss.h.

◆ SMP_INVALID_PATH

#define SMP_INVALID_PATH   0x10

Definition at line 43 of file smss.h.

◆ SMP_OS2_FLAG

#define SMP_OS2_FLAG   0x200

Definition at line 46 of file smss.h.

◆ SMP_POSIX_FLAG

#define SMP_POSIX_FLAG   0x100

Definition at line 45 of file smss.h.

◆ SMP_SUBSYSTEM_FLAG

#define SMP_SUBSYSTEM_FLAG   0x08

Definition at line 42 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:603
NTSTATUS NTAPI NtOpenProcessToken(IN HANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
Definition: security.c:342
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
PVOID SmpHeap
Definition: sminit.c:24
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
enum State_ State
Definition: pofuncs.h:54
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
#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:3219

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:558
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:585
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
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
HANDLE SmApiPort
Definition: smss.c:23
#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:240
while(1)
Definition: macro.lex.yy.c:740
HANDLE SmUniqueProcessId
Definition: smloop.c:35
smooth NULL
Definition: ftsmooth.c:416
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
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:71
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2725
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)
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:119
Definition: typedefs.h:117
ULONG MuSessionId
Definition: smss.h:67
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 }

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 }
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG SmpNumberOfPagingFiles
Definition: pagefile.c:69
#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:603
#define InsertTailList(ListHead, Entry)
NTSYSAPI WCHAR NTAPI RtlUpcaseUnicodeChar(WCHAR Source)
#define STATUS_TOO_MANY_PAGING_FILES
Definition: ntstatus.h:373
#define MEGABYTE
Definition: pagefile.c:23
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 char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
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:585
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
__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:117
#define SMP_PAGEFILE_ON_ANY_DRIVE
Definition: pagefile.c:36
Status
Definition: gdiplustypes.h:24
#define STANDARD_DRIVE_LETTER_OFFSET
Definition: pagefile.c:22
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#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
return STATUS_SUCCESS
Definition: btrfs.c:2725
base of all file and directory entries
Definition: entries.h:82
BOOLEAN SmpRegistrySpecifierPresent
Definition: pagefile.c:68
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

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 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI SmpCreateEmergencyPagingFile(VOID)
Definition: pagefile.c:783
ULONG SmpNumberOfPagingFiles
Definition: pagefile.c:69
LONG NTSTATUS
Definition: precomp.h:26
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
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
#define SMP_PAGEFILE_SYSTEM_MANAGED
Definition: pagefile.c:34
Definition: typedefs.h:117
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define STANDARD_DRIVE_LETTER_OFFSET
Definition: pagefile.c:22
#define DPRINT1
Definition: precomp.h:8
LIST_ENTRY SmpPagingFileDescriptorList
Definition: pagefile.c:67
return STATUS_SUCCESS
Definition: btrfs.c:2725
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:112
NTSTATUS NTAPI SmpCreateVolumeDescriptors(VOID)
Definition: pagefile.c:818
BOOLEAN SmpRegistrySpecifierPresent
Definition: pagefile.c:68
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by SmpLoadDataFromRegistry().

◆ SmpCreateSecurityDescriptors()

NTSTATUS NTAPI SmpCreateSecurityDescriptors ( IN BOOLEAN  InitialCall)

Definition at line 941 of file sminit.c.

942 {
944  PSID WorldSid = NULL, AdminSid = NULL, SystemSid = NULL;
945  PSID RestrictedSid = NULL, OwnerSid = NULL;
949  ULONG AclLength, SidLength;
950  PACL Acl;
952  BOOLEAN ProtectionRequired = FALSE;
953 
954  /* Check if this is the first call */
955  if (InitialCall)
956  {
957  /* Create and set the primary descriptor */
963  TRUE,
964  NULL,
965  FALSE);
967 
968  /* Create and set the liberal descriptor */
974  TRUE,
975  NULL,
976  FALSE);
978 
979  /* Create and set the \KnownDlls descriptor */
985  TRUE,
986  NULL,
987  FALSE);
989 
990  /* Create and Set the \ApiPort descriptor */
996  TRUE,
997  NULL,
998  FALSE);
1000  }
1001 
1002  /* Check if protection was requested in the registry (on by default) */
1003  if (SmpProtectionMode & 1) ProtectionRequired = TRUE;
1004 
1005  /* Exit if there's nothing to do */
1006  if (!(InitialCall || ProtectionRequired)) return STATUS_SUCCESS;
1007 
1008  /* Build the world SID */
1011  0, 0, 0, 0, 0, 0, 0,
1012  &WorldSid);
1013  if (!NT_SUCCESS(Status))
1014  {
1015  WorldSid = NULL;
1016  goto Quickie;
1017  }
1018 
1019  /* Build the admin SID */
1023  0, 0, 0, 0, 0, 0,
1024  &AdminSid);
1025  if (!NT_SUCCESS(Status))
1026  {
1027  AdminSid = NULL;
1028  goto Quickie;
1029  }
1030 
1031  /* Build the owner SID */
1032  Status = RtlAllocateAndInitializeSid(&CreatorAuthority, 1,
1034  0, 0, 0, 0, 0, 0, 0,
1035  &OwnerSid);
1036  if (!NT_SUCCESS(Status))
1037  {
1038  OwnerSid = NULL;
1039  goto Quickie;
1040  }
1041 
1042  /* Build the restricted SID */
1045  0, 0, 0, 0, 0, 0, 0,
1046  &RestrictedSid);
1047  if (!NT_SUCCESS(Status))
1048  {
1049  RestrictedSid = NULL;
1050  goto Quickie;
1051  }
1052 
1053  /* Build the system SID */
1056  0, 0, 0, 0, 0, 0, 0,
1057  &SystemSid);
1058  if (!NT_SUCCESS(Status))
1059  {
1060  SystemSid = NULL;
1061  goto Quickie;
1062  }
1063 
1064  /* Now check if we're creating the core descriptors */
1065  if (!InitialCall)
1066  {
1067  /* We're skipping NextAcl so we have to do this here */
1068  SidLength = RtlLengthSid(WorldSid) + RtlLengthSid(RestrictedSid) + RtlLengthSid(AdminSid);
1069  SidLength *= 2;
1070  goto NotInitial;
1071  }
1072 
1073  /* Allocate an ACL with two ACEs with two SIDs each */
1074  SidLength = RtlLengthSid(SystemSid) + RtlLengthSid(AdminSid);
1075  AclLength = sizeof(ACL) + 2 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
1076  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1077  if (!Acl) Status = STATUS_NO_MEMORY;
1078  if (!NT_SUCCESS(Status)) goto NextAcl;
1079 
1080  /* Now build the ACL and add the two ACEs */
1087 
1088  /* Set this as the DACL */
1090  TRUE,
1091  Acl,
1092  FALSE);
1094 
1095 NextAcl:
1096  /* Allocate an ACL with 6 ACEs, two ACEs per SID */
1097  SidLength = RtlLengthSid(WorldSid) + RtlLengthSid(RestrictedSid) + RtlLengthSid(AdminSid);
1098  SidLength *= 2;
1099  AclLength = sizeof(ACL) + 6 * sizeof(ACCESS_ALLOWED_ACE) + SidLength;
1100  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1101  if (!Acl) Status = STATUS_NO_MEMORY;
1102  if (!NT_SUCCESS(Status)) goto NotInitial;
1103 
1104  /* Now build the ACL and add the six ACEs */
1119 
1120  /* Now edit the last three ACEs and make them inheritable */
1121  Status = RtlGetAce(Acl, 3, (PVOID)&Ace);
1124  Status = RtlGetAce(Acl, 4, (PVOID)&Ace);
1127  Status = RtlGetAce(Acl, 5, (PVOID)&Ace);
1130 
1131  /* Set this as the DACL */
1133  TRUE,
1134  Acl,
1135  FALSE);
1137 
1138 NotInitial:
1139  /* The initial ACLs have been created, are we also protecting objects? */
1140  if (!ProtectionRequired) goto Quickie;
1141 
1142  /* Allocate an ACL with 7 ACEs, two ACEs per SID, and one final owner ACE */
1143  SidLength += RtlLengthSid(OwnerSid);
1144  AclLength = sizeof(ACL) + 7 * sizeof (ACCESS_ALLOWED_ACE) + 2 * SidLength;
1145  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1146  if (!Acl) Status = STATUS_NO_MEMORY;
1147  if (!NT_SUCCESS(Status)) goto Quickie;
1148 
1149  /* Build the ACL and add the seven ACEs */
1166 
1167  /* Edit the last 4 ACEs to make then inheritable */
1168  Status = RtlGetAce(Acl, 3, (PVOID)&Ace);
1171  Status = RtlGetAce(Acl, 4, (PVOID)&Ace);
1174  Status = RtlGetAce(Acl, 5, (PVOID)&Ace);
1177  Status = RtlGetAce(Acl, 6, (PVOID)&Ace);
1180 
1181  /* Set this as the DACL for the primary SD */
1183  TRUE,
1184  Acl,
1185  FALSE);
1187 
1188  /* Allocate an ACL with 7 ACEs, two ACEs per SID, and one final owner ACE */
1189  AclLength = sizeof(ACL) + 7 * sizeof (ACCESS_ALLOWED_ACE) + 2 * SidLength;
1190  Acl = RtlAllocateHeap(RtlGetProcessHeap(), 0, AclLength);
1191  if (!Acl) Status = STATUS_NO_MEMORY;
1192  if (!NT_SUCCESS(Status)) goto Quickie;
1193 
1194  /* Build the ACL and add the seven ACEs */
1211 
1212  /* Edit the last 4 ACEs to make then inheritable */
1213  Status = RtlGetAce(Acl, 3, (PVOID)&Ace);
1216  Status = RtlGetAce(Acl, 4, (PVOID)&Ace);
1219  Status = RtlGetAce(Acl, 5, (PVOID)&Ace);
1222  Status = RtlGetAce(Acl, 6, (PVOID)&Ace);
1225 
1226  /* Now set this as the DACL for the liberal SD */
1228  TRUE,
1229  Acl,
1230  FALSE);
1232 
1233 Quickie:
1234  /* Cleanup the SIDs */
1235  if (OwnerSid) RtlFreeHeap(RtlGetProcessHeap(), 0, OwnerSid);
1236  if (AdminSid) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminSid);
1237  if (WorldSid) RtlFreeHeap(RtlGetProcessHeap(), 0, WorldSid);
1238  if (SystemSid) RtlFreeHeap(RtlGetProcessHeap(), 0, SystemSid);
1239  if (RestrictedSid) RtlFreeHeap(RtlGetProcessHeap(), 0, RestrictedSid);
1240  return Status;
1241 }
#define GENERIC_ALL
Definition: nt_native.h:92
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
#define TRUE
Definition: types.h:120
SECURITY_DESCRIPTOR SmpPrimarySDBody
Definition: sminit.c:35
PISECURITY_DESCRIPTOR SmpPrimarySecurityDescriptor
Definition: sminit.c:37
static PSID AdminSid
Definition: msgina.c:39
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:603
NTSYSAPI NTSTATUS NTAPI RtlGetAce(PACL Acl, ULONG AceIndex, PVOID *Ace)
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
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 WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
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
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
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:585
#define CONTAINER_INHERIT_ACE
Definition: setypes.h:715
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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:124
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define SECURITY_RESTRICTED_CODE_RID
Definition: setypes.h:541
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 GENERIC_EXECUTE
Definition: nt_native.h:91
return STATUS_SUCCESS
Definition: btrfs.c:2725
#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:603
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:603
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:2697
#define SMP_AUTOCHK_FLAG
Definition: smss.h:41
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:603
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI SmpInvokeAutoChk(IN PUNICODE_STRING FileName, IN PUNICODE_STRING Directory, IN PUNICODE_STRING Arguments, IN ULONG Flags)
Definition: smss.c:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SMP_INVALID_PATH
Definition: smss.h:43
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
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:39
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:42
#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
_In_ BOOLEAN _In_ USHORT Directory
Definition: rtlfuncs.h:3718
return STATUS_SUCCESS
Definition: btrfs.c:2725

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)
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
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
PWCHAR SmpDefaultEnvironment
Definition: sminit.c:27
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
smooth NULL
Definition: ftsmooth.c:416
#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)
SECTION_IMAGE_INFORMATION ImageInformation
Definition: rtltypes.h:1544
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
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define SMP_ASYNC_FLAG
Definition: smss.h:40
BOOLEAN SmpDebug
Definition: smss.c:22
Status
Definition: gdiplustypes.h:24
#define SMP_DEBUG_FLAG
Definition: smss.h:39
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:42
#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:44
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
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#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 2391 of file sminit.c.

2393 {
2394  NTSTATUS Status, Status2;
2396  UNICODE_STRING PortName, EventName;
2397  HANDLE EventHandle, PortHandle;
2398  ULONG HardErrorMode;
2399 
2400  /* Create the SMSS Heap */
2401  SmBaseTag = RtlCreateTagHeap(RtlGetProcessHeap(),
2402  0,
2403  L"SMSS!",
2404  L"INIT");
2405  SmpHeap = RtlGetProcessHeap();
2406 
2407  /* Enable hard errors */
2408  HardErrorMode = TRUE;
2411  &HardErrorMode,
2412  sizeof(HardErrorMode));
2413 
2414  /* Initialize the subsystem list and the session list, plus their locks */
2419 
2420  /* Initialize the process list */
2422 
2423  /* Initialize session parameters */
2424  SmpNextSessionId = 1;
2427 
2428  /* Create the initial security descriptors */
2430  if (!NT_SUCCESS(Status))
2431  {
2432  /* Fail */
2434  return Status;
2435  }
2436 
2437  /* Initialize subsystem names */
2438  RtlInitUnicodeString(&SmpSubsystemName, L"NT-Session Manager");
2439  RtlInitUnicodeString(&PosixName, L"POSIX");
2440  RtlInitUnicodeString(&Os2Name, L"OS2");
2441 
2442  /* Create the SM API Port */
2443  RtlInitUnicodeString(&PortName, L"\\SmApiPort");
2445  Status = NtCreatePort(&PortHandle,
2447  sizeof(SB_CONNECTION_INFO),
2448  sizeof(SM_API_MSG),
2449  sizeof(SB_API_MSG) * 32);
2451  SmpDebugPort = PortHandle;
2452 
2453  /* Create two SM API threads */
2455  NULL,
2456  FALSE,
2457  0,
2458  0,
2459  0,
2460  SmpApiLoop,
2461  PortHandle,
2462  NULL,
2463  NULL);
2466  NULL,
2467  FALSE,
2468  0,
2469  0,
2470  0,
2471  SmpApiLoop,
2472  PortHandle,
2473  NULL,
2474  NULL);
2476 
2477  /* Create the write event that autochk can set after running */
2478  RtlInitUnicodeString(&EventName, L"\\Device\\VolumesSafeForWriteAccess");
2480  &EventName,
2481  OBJ_PERMANENT,
2482  NULL,
2483  NULL);
2484  Status2 = NtCreateEvent(&EventHandle,
2487  0,
2488  0);
2489  if (!NT_SUCCESS(Status2))
2490  {
2491  /* Should never really fail */
2492  DPRINT1("SMSS: Unable to create %wZ event - Status == %lx\n",
2493  &EventName, Status2);
2494  ASSERT(NT_SUCCESS(Status2));
2495  }
2496 
2497  /* Now initialize everything else based on the registry parameters */
2498  Status = SmpLoadDataFromRegistry(InitialCommand);
2499  if (NT_SUCCESS(Status))
2500  {
2501  /* Autochk should've run now. Set the event and save the CSRSS handle */
2503  NtSetEvent(EventHandle, 0);
2505  }
2506 
2507  /* All done */
2508  return Status;
2509 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
#define SMSS_CHECKPOINT(x, y)
Definition: sminit.c:43
UNICODE_STRING PosixName
Definition: sminit.c:18
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:100
ULONG NTAPI SmpApiLoop(IN PVOID Parameter)
Definition: smloop.c:335
#define OBJ_PERMANENT
Definition: winternl.h:226
LIST_ENTRY NativeProcessList
Definition: sminit.c:22
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:3884
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
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:458
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HANDLE SmpDebugPort
Definition: sminit.c:26
static const WCHAR L[]
Definition: oid.c:1250
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
Status
Definition: gdiplustypes.h:24
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:1089
UNICODE_STRING Os2Name
Definition: sminit.c:18
ULONG SmpNextSessionIdScanMode
Definition: smsessn.c:29
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI SmpCreateSecurityDescriptors(IN BOOLEAN InitialCall)
Definition: sminit.c:941
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:2186
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:308
ULONG ReferenceCount
Definition: smss.h:69
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IMAGE_SUBSYSTEM_POSIX_CUI
Definition: ntimage.h:440
HANDLE PortHandle
Definition: smss.h:64
#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
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:603
#define STATUS_NO_SUCH_PACKAGE
Definition: ntstatus.h:476
BOOLEAN Terminating
Definition: smss.h:68
VOID NTAPI SmpDeleteSession(IN ULONG SessionId)
Definition: smsessn.c:98
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:100
struct _SB_API_MSG SB_API_MSG
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define SMP_OS2_FLAG
Definition: smss.h:46
SB_CREATE_SESSION_MSG CreateSession
Definition: smmsg.h:212
#define InsertTailList(ListHead, Entry)
ULONG ImageType
Definition: smss.h:63
HANDLE UniqueProcess
Definition: compat.h:474
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define STATUS_WAIT_0
Definition: ntstatus.h:223
#define IMAGE_SUBSYSTEM_OS2_CUI
Definition: ntimage.h:439
HANDLE ProcessHandle
Definition: smss.h:62
SB_CREATE_PROCESS_MSG CreateProcess
Definition: smmsg.h:215
PVOID SmpHeap
Definition: sminit.c:24
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
smooth NULL
Definition: ftsmooth.c:416
#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:61
#define SMP_POSIX_FLAG
Definition: smss.h:45
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:585
NTSTATUS ReturnValue
Definition: smmsg.h:209
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63
SECTION_IMAGE_INFORMATION ImageInformation
Definition: rtltypes.h:1544
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:458
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG SmBaseTag
Definition: sminit.c:25
HANDLE SbApiPort
Definition: smss.h:65
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
VOID NTAPI SmpReleasePrivilege(IN PVOID State)
Definition: smutil.c:129
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN SmpDebug
Definition: smss.c:22
#define SMP_INVALID_PATH
Definition: smss.h:43
#define CreateProcess
Definition: winbase.h:3572
NTSTATUS NTAPI SmpAcquirePrivilege(IN ULONG Privilege, OUT PVOID *PrivilegeStat)
Definition: smutil.c:40
Status
Definition: gdiplustypes.h:24
ULONG MuSessionId
Definition: smss.h:67
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
struct _FileName FileName
Definition: fatprocs.h:884
VOID NTAPI SmpDereferenceSubsystem(IN PSMP_SUBSYSTEM SubSystem)
Definition: smsubsys.c:47
enum State_ State
Definition: pofuncs.h:54
static ULONG Timeout
Definition: ping.c:61
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
LIST_ENTRY Entry
Definition: smss.h:60
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType(IN ULONG MuSessionId, IN ULONG ImageType)
Definition: smsubsys.c:102
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:390
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 SMP_DEFERRED_FLAG
Definition: smss.h:44
_In_ BOOLEAN _In_ USHORT Directory
Definition: rtlfuncs.h:3718
return STATUS_SUCCESS
Definition: btrfs.c:2725
CLIENT_ID ClientId
Definition: smss.h:66
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  wcscat(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:2697
#define DbgPrint
Definition: loader.c:25
struct _LIST_ENTRY * Blink
Definition: typedefs.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:603
#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:1869
smooth NULL
Definition: ftsmooth.c:416
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
LIST_ENTRY SmpSetupExecuteList
Definition: sminit.c:19
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:117
#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
Status
Definition: gdiplustypes.h:24
enum State_ State
Definition: pofuncs.h:54
static ULONG Timeout
Definition: ping.c:61
#define SMP_DEBUG_FLAG
Definition: smss.h:39
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:42
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
LIST_ENTRY SmpSubSystemList
Definition: sminit.c:21
#define STATUS_OBJECT_PATH_SYNTAX_BAD
Definition: ntstatus.h:281
return STATUS_SUCCESS
Definition: btrfs.c:2725
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:69
BOOLEAN Terminating
Definition: smss.h:68
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
smooth NULL
Definition: ftsmooth.c:416
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:119
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
Definition: typedefs.h:117
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
base of all file and directory entries
Definition: entries.h:82
CLIENT_ID ClientId
Definition: smss.h:66

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:69
BOOLEAN Terminating
Definition: smss.h:68
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
ULONG ImageType
Definition: smss.h:63
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
smooth NULL
Definition: ftsmooth.c:416
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:119
Definition: typedefs.h:117
ULONG MuSessionId
Definition: smss.h:67
RTL_CRITICAL_SECTION SmpKnownSubSysLock
Definition: smsubsys.c:18
ImageType
Definition: gdiplusenums.h:191
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  wcscpy(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 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SMP_AUTOCHK_FLAG
Definition: smss.h:41
UNICODE_STRING SmpDebugKeyword
Definition: smutil.c:34
USHORT MaximumLength
Definition: env_spec_w32.h:370
UNICODE_STRING SmpDefaultLibPath
Definition: sminit.c:28
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_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:54
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSYSAPI ULONG NTAPI RtlDosSearchPath_U(_In_ PCWSTR Path, _In_ PCWSTR FileName, _In_ PCWSTR Extension, _In_ ULONG BufferSize, _Out_ PWSTR Buffer, _Out_ PWSTR *PartName)
#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)
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
UNICODE_STRING SmpASyncKeyword
Definition: smutil.c:34
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__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:26
PCHAR Buffer
Definition: ntsecapi.h:174
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
UNICODE_STRING SmpAutoChkKeyword
Definition: smutil.c:34
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define SMP_ASYNC_FLAG
Definition: smss.h:40
#define SharedUserData
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SMP_INVALID_PATH
Definition: smss.h:43
Status
Definition: gdiplustypes.h:24
#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:39
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:279
#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)
return STATUS_SUCCESS
Definition: btrfs.c:2725
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  WCHAR ValueBuffer[VALUE_BUFFER_SIZE];
431  PKEY_VALUE_PARTIAL_INFORMATION PartialInfo = (PVOID)ValueBuffer;
432  ULONG Length;
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: can't open control key: 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  {
461  DPRINT1("SMSS: can't query value key: 0x%x\n", Status);
462  return FALSE;
463  }
464 
465  /* Check if it's set to SOS or sos */
466  if (!(wcsstr((PWCHAR)PartialInfo->Data, L"SOS")) ||
467  (wcsstr((PWCHAR)PartialInfo->Data, L"sos")))
468  {
469  /* It's not set, return FALSE */
470  return FALSE;
471  }
472 
473  /* It's set, return TRUE */
474  return TRUE;
475 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4693
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
#define KEY_READ
Definition: nt_native.h:1023
_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:54
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#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

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:603
PVOID SmpHeap
Definition: sminit.c:24
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
struct _SMP_PRIVILEGE_STATE * PSMP_PRIVILEGE_STATE
_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:3219

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

◆ SmpRestoreBootStatusData()

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

Definition at line 529 of file smutil.c.

531 {
533  PVOID BootState;
534 
535  /* Lock the BSD */
536  Status = RtlLockBootStatusData(&BootState);
537  if (NT_SUCCESS(Status))
538  {
539  /* Write the bootokay and bootshutdown values */
540  RtlGetSetBootStatusData(BootState,
541  FALSE,
543  &BootOkay,
544  sizeof(BootOkay),
545  NULL);
546  RtlGetSetBootStatusData(BootState,
547  FALSE,
549  &ShutdownOkay,
550  sizeof(ShutdownOkay),
551  NULL);
552 
553  /* Unlock the BSD and return */
554  RtlUnlockBootStatusData(BootState);
555  }
556 }
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
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
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 479 of file smutil.c.

481 {
483  BOOLEAN Value = TRUE;
484  PVOID BootStatusDataHandle;
485 
486  /* Assume failure */
487  *BootOkay = FALSE;
488  *ShutdownOkay = FALSE;
489 
490  /* Lock the BSD and fail if we couldn't */
491  Status = RtlLockBootStatusData(&BootStatusDataHandle);
492  if (!NT_SUCCESS(Status)) return FALSE;
493 
494  /* Read the old settings */
495  RtlGetSetBootStatusData(BootStatusDataHandle,
496  TRUE,
498  BootOkay,
499  sizeof(BOOLEAN),
500  NULL);
501  RtlGetSetBootStatusData(BootStatusDataHandle,
502  TRUE,
504  ShutdownOkay,
505  sizeof(BOOLEAN),
506  NULL);
507 
508  /* Set new ones indicating we got at least this far */
509  RtlGetSetBootStatusData(BootStatusDataHandle,
510  FALSE,
512  &Value,
513  sizeof(Value),
514  NULL);
515  RtlGetSetBootStatusData(BootStatusDataHandle,
516  FALSE,
518  &Value,
519  sizeof(Value),
520  NULL);
521 
522  /* Unlock the BSD and return */
523  RtlUnlockBootStatusData(BootStatusDataHandle);
524  return TRUE;
525 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define TRUE
Definition: types.h:120
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
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
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  DbgPrint("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
#define DbgPrint
Definition: loader.c:25
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:474
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:62
PVOID SmpHeap
Definition: sminit.c:24
SB_API_NUMBER ApiNumber
Definition: smmsg.h:208
smooth NULL
Definition: ftsmooth.c:416
#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:585
NTSTATUS ReturnValue
Definition: smmsg.h:209
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
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:65
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
CLIENT_ID ClientId
Definition: smmsg.h:148
HANDLE UniqueThread
Definition: compat.h:475
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
HANDLE SmpDebugPort
Definition: sminit.c:26
Status
Definition: gdiplustypes.h:24
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:1089
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#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
return STATUS_SUCCESS
Definition: btrfs.c:2725
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1089
#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 }
#define TRUE
Definition: types.h:120
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
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
unsigned char BOOLEAN
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define STATUS_NO_TOKEN
Definition: ntstatus.h:346
Definition: ncftp.h:89
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:871
Status
Definition: gdiplustypes.h:24
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:656

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

◆ SmpTranslateSystemPartitionInformation()

VOID NTAPI SmpTranslateSystemPartitionInformation ( VOID  )

Definition at line 786 of file sminit.c.

787 {
789  UNICODE_STRING UnicodeString, LinkTarget, SearchString, SystemPartition;
791  HANDLE KeyHandle, LinkHandle;
792  CHAR ValueBuffer[512 + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
793  PKEY_VALUE_PARTIAL_INFORMATION PartialInfo = (PVOID)ValueBuffer;
795  CHAR DirInfoBuffer[512 + sizeof(OBJECT_DIRECTORY_INFORMATION)];
796  POBJECT_DIRECTORY_INFORMATION DirInfo = (PVOID)DirInfoBuffer;
797  WCHAR LinkBuffer[MAX_PATH];
798 
799  /* Open the setup key */
800  RtlInitUnicodeString(&UnicodeString, L"\\Registry\\Machine\\System\\Setup");
802  &UnicodeString,
804  NULL,
805  NULL);
807  if (!NT_SUCCESS(Status))
808  {
809  DPRINT1("SMSS: can't open system setup key for reading: 0x%x\n", Status);
810  return;
811  }
812 
813  /* Query the system partition */
814  RtlInitUnicodeString(&UnicodeString, L"SystemPartition");
816  &UnicodeString,
818  PartialInfo,
819  sizeof(ValueBuffer),
820  &Length);
822  if (!NT_SUCCESS(Status))
823  {
824  DPRINT1("SMSS: can't query SystemPartition value: 0x%x\n", Status);
825  return;
826  }
827 
828  /* Initialize the system partition string string */
829  RtlInitUnicodeString(&SystemPartition, (PWCHAR)PartialInfo->Data);
830 
831  /* Enumerate the directory looking for the symbolic link string */
832  RtlInitUnicodeString(&SearchString, L"SymbolicLink");
833  RtlInitEmptyUnicodeString(&LinkTarget, LinkBuffer, sizeof(LinkBuffer));
835  DirInfo,
836  sizeof(DirInfoBuffer),
837  TRUE,
838  TRUE,
839  &Context,
840  NULL);
841  if (!NT_SUCCESS(Status))
842  {
843  DPRINT1("SMSS: can't find drive letter for system partition\n");
844  return;
845  }
846 
847  /* Keep searching until we find it */
848  do
849  {
850  /* Is this it? */
851  if ((RtlEqualUnicodeString(&DirInfo->TypeName, &SearchString, TRUE)) &&
852  (DirInfo->Name.Length == 2 * sizeof(WCHAR)) &&
853  (DirInfo->Name.Buffer[1] == L':'))
854  {
855  /* Looks like we found it, open the link to get its target */
857  &DirInfo->Name,
860  NULL);
861  Status = NtOpenSymbolicLinkObject(&LinkHandle,
864  if (NT_SUCCESS(Status))
865  {
866  /* Open worked, query the target now */
867  Status = NtQuerySymbolicLinkObject(LinkHandle,
868  &LinkTarget,
869  NULL);
870  NtClose(LinkHandle);
871 
872  /* Check if it matches the string we had found earlier */
873  if ((NT_SUCCESS(Status)) &&
874  ((RtlEqualUnicodeString(&SystemPartition,
875  &LinkTarget,
876  TRUE)) ||
877  ((RtlPrefixUnicodeString(&SystemPartition,
878  &LinkTarget,
879  TRUE)) &&
880  (LinkTarget.Buffer[SystemPartition.Length / sizeof(WCHAR)] == L'\\'))))
881  {
882  /* All done */
883  break;
884  }
885  }
886  }
887 
888  /* Couldn't find it, try again */
890  DirInfo,
891  sizeof(DirInfoBuffer),
892  TRUE,
893  FALSE,
894  &Context,
895  NULL);
896  } while (NT_SUCCESS(Status));
897  if (!NT_SUCCESS(Status))
898  {
899  DPRINT1("SMSS: can't find drive letter for system partition\n");
900  return;
901  }
902 
903  /* Open the setup key again, for full access this time */
905  L"\\Registry\\Machine\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup");
907  &UnicodeString,
909  NULL,
910  NULL);
912  if (!NT_SUCCESS(Status))
913  {
914  DPRINT1("SMSS: can't open software setup key for writing: 0x%x\n",
915  Status);
916  return;
917  }
918 
919  /* Wrap up the end of the link buffer */
920  wcsncpy(LinkBuffer, DirInfo->Name.Buffer, 2);
921  LinkBuffer[2] = L'\\';
922  LinkBuffer[3] = L'\0';
923 
924  /* Now set this as the "BootDir" */
927  &UnicodeString,
928  0,
929  REG_SZ,
930  LinkBuffer,
931  4 * sizeof(WCHAR));
932  if (!NT_SUCCESS(Status))
933  {
934  DPRINT1("SMSS: couldn't write BootDir value: 0x%x\n", Status);
935  }
937 }
HANDLE SmpDosDevicesObjectDirectory
Definition: sminit.c:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
#define KEY_READ
Definition: nt_native.h:1023
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
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:456
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
_Inout_ PUNICODE_STRING LinkTarget
Definition: zwfuncs.h:292
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
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:26
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
struct _OBJECT_DIRECTORY_INFORMATION OBJECT_DIRECTORY_INFORMATION
Status
Definition: gdiplustypes.h:24
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
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:1012
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().