ReactOS 0.4.17-dev-769-g1500a35
smloop.c File Reference
#include "smss.h"
#include <debug.h>
Include dependency graph for smloop.c:

Go to the source code of this file.

Classes

struct  _SMP_CLIENT_CONTEXT
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _SMP_CLIENT_CONTEXT SMP_CLIENT_CONTEXT
 
typedef struct _SMP_CLIENT_CONTEXTPSMP_CLIENT_CONTEXT
 
typedef NTSTATUS(NTAPIPSM_API_HANDLER) (_In_ PSM_API_MSG SmApiMsg, _In_ PSMP_CLIENT_CONTEXT ClientContext, _In_ HANDLE SmApiPort)
 

Functions

NTSTATUS NTAPI SmpCreateForeignSession (IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpSessionComplete (IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpTerminateForeignSession (IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpExecPgm (IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpLoadDeferedSubsystem (_In_ PSM_API_MSG SmApiMsg, _In_ PSMP_CLIENT_CONTEXT ClientContext, _In_ HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpStartCsr (IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpStopCsr (IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
 
NTSTATUS NTAPI SmpHandleConnectionRequest (IN HANDLE SmApiPort, IN PSB_API_MSG SbApiMsg)
 
ULONG NTAPI SmpApiLoop (_In_ PVOID Parameter)
 

Variables

volatile LONG SmTotalApiThreads
 
HANDLE SmUniqueProcessId
 
const PSM_API_HANDLER SmpApiDispatch [SmpMaxApiNumber - SmpCreateForeignSessionApi]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file smloop.c.

Typedef Documentation

◆ PSM_API_HANDLER

Definition at line 27 of file smloop.c.

◆ PSMP_CLIENT_CONTEXT

◆ SMP_CLIENT_CONTEXT

Function Documentation

◆ SmpApiLoop()

ULONG NTAPI SmpApiLoop ( _In_ PVOID  Parameter)

Definition at line 437 of file smloop.c.

439{
443 PSM_API_MSG ReplyMsg = NULL;
444 SM_API_MSG RequestMsg;
445 PROCESS_BASIC_INFORMATION ProcessInformation;
447
448 /* Increase the number of API threads for throttling code for later */
450
451 /* Mark us critical */
453
454 /* Set the PID of the SM process itself for later checking */
457 &ProcessInformation,
458 sizeof(ProcessInformation),
459 NULL);
460 SmUniqueProcessId = (HANDLE)ProcessInformation.UniqueProcessId;
461
462 /* Now process incoming messages */
463 while (TRUE)
464 {
465 /* Begin waiting on a request */
468 &ReplyMsg->h,
469 &RequestMsg.h);
471 {
472 /* Ran out of memory, so do a little timeout and try again */
473 if (ReplyMsg) DPRINT1("SMSS: Failed to reply to calling thread, retrying.\n");
474 Timeout.QuadPart = -50000000;
476 continue;
477 }
478
479 /* Check what kind of request we received */
480 switch (RequestMsg.h.u2.s2.Type)
481 {
482 /* A new connection */
484 /* Create the right structures for it */
486 ReplyMsg = NULL;
487 break;
488
489 /* A closed connection */
490 case LPC_PORT_CLOSED:
491 /* Destroy any state we had for this client */
492 DPRINT1("Port closed\n");
493 //if (ClientContext) SmpPushDeferredClientContext(ClientContext);
494 ReplyMsg = NULL;
495 break;
496
497 /* An actual API message */
498 default:
499 {
500 if (!ClientContext)
501 {
502 ReplyMsg = NULL;
503 break;
504 }
505
506#if DBG
507 DPRINT("SMSS: %s Api Request received from %lx.%lx\n",
508 SmpApiName[min(RequestMsg.ApiNumber, SmpMaxApiNumber)],
509 RequestMsg.h.ClientId.UniqueProcess,
510 RequestMsg.h.ClientId.UniqueThread);
511#endif
512
513 RequestMsg.ReturnValue = STATUS_PENDING;
514
515 /* Check if the API is valid */
516 if (RequestMsg.ApiNumber >= SmpMaxApiNumber)
517 {
518 /* It isn't, fail */
519 DPRINT1("SMSS: Invalid Sm Api Number %lx\n", RequestMsg.ApiNumber);
521 }
522 else if ((RequestMsg.ApiNumber <= SmpTerminateForeignSessionApi) &&
523 !(ClientContext->Subsystem))
524 {
525 /* It's valid, but doesn't have a subsystem with it */
526 DPRINT1("SMSS: Invalid session API\n");
528 }
529 else
530 {
531 /* It's totally okay, so call the dispatcher for it */
533 {
534 Status = SmpApiDispatch[RequestMsg.ApiNumber](&RequestMsg,
536 SmApiPort);
537 }
539 {
540 ReplyMsg = NULL;
541 _SEH2_YIELD(break);
542 }
543 _SEH2_END;
544 }
545
546 /* Write the result value and return the message back */
547 RequestMsg.ReturnValue = Status;
548 ReplyMsg = &RequestMsg;
549 break;
550 }
551 }
552 }
553
555 return STATUS_UNSUCCESSFUL;
556}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
@ ProcessBasicInformation
Definition: cicbase.cpp:63
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define LPC_CONNECTION_REQUEST
Definition: port.c:102
#define LPC_PORT_CLOSED
Definition: port.c:97
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI NTSTATUS __cdecl RtlSetThreadIsCritical(_In_ BOOLEAN NewValue, _Out_opt_ PBOOLEAN OldValue, _In_ BOOLEAN NeedBreaks)
_In_ PVOID ClientContext
Definition: netioddk.h:55
#define NtCurrentProcess()
Definition: nt_native.h:1660
NTSTATUS NTAPI NtDelayExecution(IN BOOLEAN Alertable, IN PLARGE_INTEGER DelayInterval)
Definition: wait.c:876
#define UNREACHABLE
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_writes_bytes_to_opt_(ProcessInformationLength, *ReturnLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:211
static ULONG Timeout
Definition: ping.c:61
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:203
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
long __cdecl _InterlockedExchangeAdd(_Interlocked_operand_ long volatile *_Addend, long _Value)
HANDLE SmUniqueProcessId
Definition: smloop.c:34
NTSTATUS NTAPI SmpHandleConnectionRequest(IN HANDLE SmApiPort, IN PSB_API_MSG SbApiMsg)
Definition: smloop.c:287
volatile LONG SmTotalApiThreads
Definition: smloop.c:33
const PSM_API_HANDLER SmpApiDispatch[SmpMaxApiNumber - SmpCreateForeignSessionApi]
Definition: smloop.c:258
@ SmpTerminateForeignSessionApi
Definition: smmsg.h:30
@ SmpMaxApiNumber
Definition: smmsg.h:36
LONG NTAPI SmpUnhandledExceptionFilter(_In_ PEXCEPTION_POINTERS ExceptionInfo)
Definition: smss.c:407
HANDLE SmApiPort
Definition: smss.c:21
#define DPRINT
Definition: sndvol32.h:73
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
CLIENT_ID ClientId
Definition: winternl.h:3337
NTSTATUS ReturnValue
Definition: smmsg.h:106
PORT_MESSAGE h
Definition: smmsg.h:104
SMSRV_API_NUMBER ApiNumber
Definition: smmsg.h:105
#define STATUS_PENDING
Definition: telnetd.h:14
PVOID HANDLE
Definition: typedefs.h:73
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by SmpInit().

◆ SmpCreateForeignSession()

NTSTATUS NTAPI SmpCreateForeignSession ( IN PSM_API_MSG  SmApiMsg,
IN PSMP_CLIENT_CONTEXT  ClientContext,
IN HANDLE  SmApiPort 
)

Definition at line 40 of file smloop.c.

43{
44 DPRINT1("%s is not yet implemented\n", __FUNCTION__);
46}
#define __FUNCTION__
Definition: types.h:116

◆ SmpExecPgm()

NTSTATUS NTAPI SmpExecPgm ( IN PSM_API_MSG  SmApiMsg,
IN PSMP_CLIENT_CONTEXT  ClientContext,
IN HANDLE  SmApiPort 
)

Definition at line 70 of file smloop.c.

73{
77 RTL_USER_PROCESS_INFORMATION ProcessInformation;
79
80 /* Open the client process */
85 &SmApiMsg->h.ClientId);
86 if (!NT_SUCCESS(Status))
87 {
88 /* Fail */
89 DPRINT1("SmExecPgm: NtOpenProcess Failed %lx\n", Status);
90 return Status;
91 }
92
93 /* Copy the process information out of the message */
94 SmExecPgm = &SmApiMsg->u.ExecPgm;
95 ProcessInformation = SmExecPgm->ProcessInformation;
96
97 /* Duplicate the process handle */
99 SmExecPgm->ProcessInformation.ProcessHandle,
101 &ProcessInformation.ProcessHandle,
103 0,
104 0);
105 if (!NT_SUCCESS(Status))
106 {
107 /* Close the handle and fail */
109 DPRINT1("SmExecPgm: NtDuplicateObject (Process) Failed %lx\n", Status);
110 return Status;
111 }
112
113 /* Duplicate the thread handle */
115 SmExecPgm->ProcessInformation.ThreadHandle,
117 &ProcessInformation.ThreadHandle,
119 0,
120 0);
121 if (!NT_SUCCESS(Status))
122 {
123 /* Close both handles and fail */
124 NtClose(ProcessInformation.ProcessHandle);
126 DPRINT1("SmExecPgm: NtDuplicateObject (Thread) Failed %lx\n", Status);
127 return Status;
128 }
129
130 /* Close the process handle and call the internal client API */
133 NULL,
134 &ProcessInformation,
135 0,
136 SmExecPgm->DebugFlag ? &SmApiMsg->h.ClientId : NULL);
137}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define PROCESS_DUP_HANDLE
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:407
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1342
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1327
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3429
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1470
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:3437
NTSTATUS NTAPI SmExecPgm(_In_ HANDLE SmApiPort, _In_ PRTL_USER_PROCESS_INFORMATION ProcessInformation, _In_ BOOLEAN DebugFlag)
Requests the SM to start a process under a new environment session.
Definition: smclient.c:265
NTSTATUS NTAPI SmpSbCreateSession(IN PVOID Reserved, IN PSMP_SUBSYSTEM OtherSubsystem, IN PRTL_USER_PROCESS_INFORMATION ProcessInformation, IN ULONG DbgSessionId, IN PCLIENT_ID DbgUiClientId)
Definition: smsbapi.c:36

◆ SmpHandleConnectionRequest()

NTSTATUS NTAPI SmpHandleConnectionRequest ( IN HANDLE  SmApiPort,
IN PSB_API_MSG  SbApiMsg 
)

Definition at line 287 of file smloop.c.

289{
290 BOOLEAN Accept = TRUE;
291 HANDLE PortHandle, ProcessHandle;
293 UNICODE_STRING SubsystemPort;
297 REMOTE_PORT_VIEW PortView;
298 SECURITY_QUALITY_OF_SERVICE SecurityQos;
299 PSMP_SUBSYSTEM CidSubsystem, TypeSubsystem;
300
301 /* Initialize QoS data */
304 SecurityQos.EffectiveOnly = TRUE;
305
306 /* Check if this is SM connecting to itself */
307 if (SbApiMsg->h.ClientId.UniqueProcess == SmUniqueProcessId)
308 {
309 /* No need to get any handle -- assume session 0 */
311 SessionId = 0;
312 }
313 else
314 {
315 /* Reference the foreign process */
320 &SbApiMsg->h.ClientId);
321 if (!NT_SUCCESS(Status)) Accept = FALSE;
322
323 /* Get its session ID */
325 }
326
327 /* See if we already know about the caller's subsystem */
328 CidSubsystem = SmpLocateKnownSubSysByCid(&SbApiMsg->h.ClientId);
329 if ((CidSubsystem) && (Accept))
330 {
331 /* Check if we already have a subsystem for this kind of image */
333 SbApiMsg->ConnectionInfo.SubsystemType);
334 if (TypeSubsystem == CidSubsystem)
335 {
336 /* Someone is trying to take control of an existing subsystem, fail */
337 Accept = FALSE;
338 DPRINT1("SMSS: Connection from SubSystem rejected\n");
339 DPRINT1("SMSS: Image type already being served\n");
340 }
341 else
342 {
343 /* Set this image type as the type for this subsystem */
344 CidSubsystem->ImageType = SbApiMsg->ConnectionInfo.SubsystemType;
345 }
346
347 /* Drop the reference we had acquired */
348 if (TypeSubsystem) SmpDereferenceSubsystem(TypeSubsystem);
349 }
350
351 /* Check if we'll be accepting the connection */
352 if (Accept)
353 {
354 /* We will, so create a client context for it */
356 if (ClientContext)
357 {
358 ClientContext->ProcessHandle = ProcessHandle;
359 ClientContext->Subsystem = CidSubsystem;
360 ClientContext->Reserved = NULL;
361 ClientContext->PortHandle = NULL;
362 }
363 else
364 {
365 /* Failed to allocate a client context, so reject the connection */
366 DPRINT1("Rejecting connection due to lack of memory\n");
367 Accept = FALSE;
368 }
369 }
370 else
371 {
372 /* Use a bogus context since we're going to reject the message */
374 }
375
376 /* Now send the actual accept reply (which could be a rejection) */
377 PortView.Length = sizeof(PortView);
378 Status = NtAcceptConnectPort(&PortHandle,
380 &SbApiMsg->h,
381 Accept,
382 NULL,
383 &PortView);
384 if (!(Accept) || !(NT_SUCCESS(Status)))
385 {
386 /* Close the process handle, reference the subsystem, and exit */
387 DPRINT1("Accept failed or rejected: %lx\n", Status);
388 if (ClientContext != (PVOID)SbApiMsg) RtlFreeHeap(SmpHeap, 0, ClientContext);
390 if (CidSubsystem) SmpDereferenceSubsystem(CidSubsystem);
391 return Status;
392 }
393
394 /* Save the port handle now that we've accepted it */
395 if (ClientContext) ClientContext->PortHandle = PortHandle;
396 if (CidSubsystem) CidSubsystem->PortHandle = PortHandle;
397
398 /* Complete the port connection */
399 Status = NtCompleteConnectPort(PortHandle);
400 if ((NT_SUCCESS(Status)) && (CidSubsystem))
401 {
402 /* This was an actual subsystem, so connect back to it */
403 SbApiMsg->ConnectionInfo.SbApiPortName[119] = UNICODE_NULL;
404 RtlCreateUnicodeString(&SubsystemPort,
405 SbApiMsg->ConnectionInfo.SbApiPortName);
406 Status = NtConnectPort(&CidSubsystem->SbApiPort,
407 &SubsystemPort,
408 &SecurityQos,
409 NULL,
410 NULL,
411 NULL,
412 NULL,
413 NULL);
414 if (!NT_SUCCESS(Status))
415 {
416 DPRINT1("SMSS: Connect back to Sb %wZ failed %lx\n", &SubsystemPort, Status);
417 }
418 RtlFreeUnicodeString(&SubsystemPort);
419
420 /* Now that we're connected, signal the event handle */
421 NtSetEvent(CidSubsystem->Event, NULL);
422 }
423 else if (CidSubsystem)
424 {
425 /* We failed to complete the connection, so clear the port handle */
426 DPRINT1("Completing the connection failed: %lx\n", Status);
427 CidSubsystem->PortHandle = NULL;
428 }
429
430 /* Dereference the subsystem and return the result */
431 if (CidSubsystem) SmpDereferenceSubsystem(CidSubsystem);
432 return Status;
433}
unsigned char BOOLEAN
Definition: actypes.h:127
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
NTSTATUS NTAPI NtAcceptConnectPort(OUT PHANDLE PortHandle, IN PVOID PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage, IN BOOLEAN AcceptConnection, IN OUT PPORT_VIEW ServerView OPTIONAL, OUT PREMOTE_PORT_VIEW ClientView OPTIONAL)
Definition: complete.c:40
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:423
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
ULONG SessionId
Definition: dllmain.c:28
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:162
@ SecurityIdentification
Definition: lsa.idl:56
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:463
NTSTATUS NTAPI NtConnectPort(OUT PHANDLE PortHandle, IN PUNICODE_STRING PortName, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos, IN OUT PPORT_VIEW ClientView OPTIONAL, IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL, OUT PULONG MaxMessageLength OPTIONAL, IN OUT PVOID ConnectionInformation OPTIONAL, IN OUT PULONG ConnectionInformationLength OPTIONAL)
Definition: connect.c:777
PVOID SmpHeap
Definition: sminit.c:25
struct _SMP_CLIENT_CONTEXT * PSMP_CLIENT_CONTEXT
NTSTATUS NTAPI SmpGetProcessMuSessionId(IN HANDLE ProcessHandle, OUT PULONG SessionId)
Definition: smsessn.c:168
VOID NTAPI SmpDereferenceSubsystem(IN PSMP_SUBSYSTEM SubSystem)
Definition: smsubsys.c:50
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByCid(IN PCLIENT_ID ClientId)
Definition: smsubsys.c:71
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType(IN ULONG MuSessionId, IN ULONG ImageType)
Definition: smsubsys.c:105
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
HANDLE SbApiPort
Definition: smss.h:73
HANDLE Event
Definition: smss.h:69
ULONG ImageType
Definition: smss.h:71
HANDLE PortHandle
Definition: smss.h:72
uint32_t ULONG
Definition: typedefs.h:59
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103

Referenced by SmpApiLoop().

◆ SmpLoadDeferedSubsystem()

NTSTATUS NTAPI SmpLoadDeferedSubsystem ( _In_ PSM_API_MSG  SmApiMsg,
_In_ PSMP_CLIENT_CONTEXT  ClientContext,
_In_ HANDLE  SmApiPort 
)

Definition at line 141 of file smloop.c.

145{
147 PSM_LOAD_DEFERED_SUBSYSTEM_MSG SmLoadDefered = &SmApiMsg->u.LoadDefered;
148 UNICODE_STRING DeferedSubsystem;
149 ULONG MuSessionId;
150 PLIST_ENTRY NextEntry;
151 PSMP_REGISTRY_VALUE RegEntry;
152
153 /* Validate DeferedSubsystem's length */
154 if ((SmLoadDefered->Length <= 0) ||
155 (SmLoadDefered->Length > sizeof(SmLoadDefered->Buffer)))
156 {
158 }
159
160 /* Get the name of the subsystem to start */
161 DeferedSubsystem.Length = (USHORT)SmLoadDefered->Length;
162 DeferedSubsystem.MaximumLength = DeferedSubsystem.Length;
163 DeferedSubsystem.Buffer = SmLoadDefered->Buffer;
164
165 /* Find a subsystem responsible for this session */
166 SmpGetProcessMuSessionId(ClientContext->ProcessHandle, &MuSessionId);
167 if (!SmpCheckDuplicateMuSessionId(MuSessionId))
168 {
169 DPRINT1("SMSS: Deferred subsystem load (%wZ) for MuSessionId %u, status=0x%x\n",
170 &DeferedSubsystem, MuSessionId, Status);
171 return Status;
172 }
173
174 /* Now process the deferred subsystems list */
175 for (NextEntry = SmpSubSystemsToDefer.Flink;
176 NextEntry != &SmpSubSystemsToDefer;
177 NextEntry = NextEntry->Flink)
178 {
179 /* Get each entry and check if it's the subsystem we are looking for */
180 RegEntry = CONTAINING_RECORD(NextEntry, SMP_REGISTRY_VALUE, Entry);
181 if (RtlEqualUnicodeString(&RegEntry->Name, &DeferedSubsystem, TRUE))
182 {
183 // TODO: One may want to extra-flag the command for
184 // specific POSIX or OS2 processing...
185
186 /* Load the deferred subsystem */
187 Status = SmpExecuteCommand(&RegEntry->Value,
188 MuSessionId,
189 NULL,
191 if (!NT_SUCCESS(Status))
192 DPRINT1("SMSS: Subsystem execute failed (%wZ)\n", &RegEntry->Value);
193
194 break;
195 }
196 }
197
198 /* Return status */
199 return Status;
200}
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
unsigned short USHORT
Definition: pedump.c:61
Entry
Definition: section.c:5216
LIST_ENTRY SmpSubSystemsToDefer
Definition: sminit.c:22
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
Definition: smsessn.c:37
NTSTATUS NTAPI SmpExecuteCommand(IN PUNICODE_STRING CommandLine, IN ULONG MuSessionId, OUT PHANDLE ProcessId, IN ULONG Flags)
Definition: smss.c:208
#define SMP_SUBSYSTEM_FLAG
Definition: smss.h:50
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
UNICODE_STRING Name
Definition: smss.h:61
UNICODE_STRING Value
Definition: smss.h:62
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

◆ SmpSessionComplete()

NTSTATUS NTAPI SmpSessionComplete ( IN PSM_API_MSG  SmApiMsg,
IN PSMP_CLIENT_CONTEXT  ClientContext,
IN HANDLE  SmApiPort 
)

Definition at line 50 of file smloop.c.

53{
54 DPRINT1("%s is not yet implemented\n", __FUNCTION__);
56}

◆ SmpStartCsr()

NTSTATUS NTAPI SmpStartCsr ( IN PSM_API_MSG  SmApiMsg,
IN PSMP_CLIENT_CONTEXT  ClientContext,
IN HANDLE  SmApiPort 
)

Definition at line 204 of file smloop.c.

207{
208 PSM_START_CSR_MSG SmStartCsr = &SmApiMsg->u.StartCsr;
209 UNICODE_STRING InitialCommand;
210 HANDLE InitialCommandProcess, InitialCommandProcessId, WindowsSubSysProcessId;
212
214 &WindowsSubSysProcessId,
215 &InitialCommand);
216 if (!NT_SUCCESS(Status))
217 {
218 DPRINT1("SMSS: SmpLoadSubSystemsForMuSession failed with status 0x%08x\n", Status);
219 return Status;
220 }
221
222 if (SmStartCsr->Length)
223 {
224 InitialCommand.Length = InitialCommand.MaximumLength = SmStartCsr->Length;
225 InitialCommand.Buffer = SmStartCsr->Buffer;
226 }
227
229 &InitialCommand,
230 &InitialCommandProcess,
231 &InitialCommandProcessId);
232 if (!NT_SUCCESS(Status))
233 {
234 DPRINT1("SMSS: SmpExecuteInitialCommand failed with status 0x%08x\n", Status);
235 /* FIXME: undo effects of SmpLoadSubSystemsForMuSession */
236 ASSERT(FALSE);
237 return Status;
238 }
239
240 NtClose(InitialCommandProcess);
241
242 SmStartCsr->WindowsSubSysProcessId = WindowsSubSysProcessId;
243 SmStartCsr->SmpInitialCommandProcessId = InitialCommandProcessId;
244
245 return STATUS_SUCCESS;
246}
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI SmStartCsr(_In_ HANDLE SmApiPort, _Out_ PULONG pMuSessionId, _In_opt_ PUNICODE_STRING CommandLine, _Out_ PHANDLE pWindowsSubSysProcessId, _Out_ PHANDLE pInitialCommandProcessId)
Requests the SM to create a new Terminal Services session and start an initial command.
Definition: smclient.c:376
NTSTATUS NTAPI SmpExecuteInitialCommand(IN ULONG MuSessionId, IN PUNICODE_STRING InitialCommand, IN HANDLE InitialCommandProcess, OUT PHANDLE ReturnPid)
Definition: smss.c:281
NTSTATUS NTAPI SmpLoadSubSystemsForMuSession(IN PULONG MuSessionId, OUT PHANDLE ProcessId, IN PUNICODE_STRING InitialCommand)
Definition: smsubsys.c:513

◆ SmpStopCsr()

NTSTATUS NTAPI SmpStopCsr ( IN PSM_API_MSG  SmApiMsg,
IN PSMP_CLIENT_CONTEXT  ClientContext,
IN HANDLE  SmApiPort 
)

Definition at line 250 of file smloop.c.

253{
254 DPRINT1("%s is not yet implemented\n", __FUNCTION__);
256}

◆ SmpTerminateForeignSession()

NTSTATUS NTAPI SmpTerminateForeignSession ( IN PSM_API_MSG  SmApiMsg,
IN PSMP_CLIENT_CONTEXT  ClientContext,
IN HANDLE  SmApiPort 
)

Definition at line 60 of file smloop.c.

63{
64 DPRINT1("%s is not yet implemented\n", __FUNCTION__);
66}

Variable Documentation

◆ SmpApiDispatch

Initial value:
=
{
}
NTSTATUS NTAPI SmpLoadDeferedSubsystem(_In_ PSM_API_MSG SmApiMsg, _In_ PSMP_CLIENT_CONTEXT ClientContext, _In_ HANDLE SmApiPort)
Definition: smloop.c:141
NTSTATUS NTAPI SmpExecPgm(IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
Definition: smloop.c:70
NTSTATUS NTAPI SmpCreateForeignSession(IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
Definition: smloop.c:40
NTSTATUS NTAPI SmpSessionComplete(IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
Definition: smloop.c:50
NTSTATUS NTAPI SmpTerminateForeignSession(IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
Definition: smloop.c:60
NTSTATUS NTAPI SmpStartCsr(IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
Definition: smloop.c:204
NTSTATUS NTAPI SmpStopCsr(IN PSM_API_MSG SmApiMsg, IN PSMP_CLIENT_CONTEXT ClientContext, IN HANDLE SmApiPort)
Definition: smloop.c:250

Definition at line 258 of file smloop.c.

Referenced by SmpApiLoop().

◆ SmTotalApiThreads

volatile LONG SmTotalApiThreads

Definition at line 33 of file smloop.c.

Referenced by SmpApiLoop().

◆ SmUniqueProcessId

HANDLE SmUniqueProcessId

Definition at line 34 of file smloop.c.

Referenced by SmpApiLoop(), and SmpHandleConnectionRequest().