mirror of
https://github.com/reactos/reactos.git
synced 2024-09-27 21:16:34 +00:00
[SMLIB][SMSS] Implement SmLoadDeferedSubsystem() client and server-side. (#4821)
Loosely based on the deprecated ReactOS-specific SmExecuteProgram(). On server-side, we lookup into the list of deferred subsystems that has been initialized at init time. Dedicated to Justin Miller (The_DarkFire) work on reviving the POSIX subsystem!
This commit is contained in:
parent
8fea507d9b
commit
9f48c69231
|
@ -26,10 +26,9 @@ typedef struct _SMP_CLIENT_CONTEXT
|
||||||
typedef
|
typedef
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
(NTAPI *PSM_API_HANDLER)(
|
(NTAPI *PSM_API_HANDLER)(
|
||||||
IN PSM_API_MSG SmApiMsg,
|
_In_ PSM_API_MSG SmApiMsg,
|
||||||
IN PSMP_CLIENT_CONTEXT ClientContext,
|
_In_ PSMP_CLIENT_CONTEXT ClientContext,
|
||||||
IN HANDLE SmApiPort
|
_In_ HANDLE SmApiPort);
|
||||||
);
|
|
||||||
|
|
||||||
volatile LONG SmTotalApiThreads;
|
volatile LONG SmTotalApiThreads;
|
||||||
HANDLE SmUniqueProcessId;
|
HANDLE SmUniqueProcessId;
|
||||||
|
@ -139,12 +138,65 @@ SmpExecPgm(IN PSM_API_MSG SmApiMsg,
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
SmpLoadDeferedSubsystem(IN PSM_API_MSG SmApiMsg,
|
SmpLoadDeferedSubsystem(
|
||||||
IN PSMP_CLIENT_CONTEXT ClientContext,
|
_In_ PSM_API_MSG SmApiMsg,
|
||||||
IN HANDLE SmApiPort)
|
_In_ PSMP_CLIENT_CONTEXT ClientContext,
|
||||||
|
_In_ HANDLE SmApiPort)
|
||||||
{
|
{
|
||||||
DPRINT1("%s is not yet implemented\n", __FUNCTION__);
|
NTSTATUS Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
PSM_LOAD_DEFERED_SUBSYSTEM_MSG SmLoadDefered = &SmApiMsg->u.LoadDefered;
|
||||||
|
UNICODE_STRING DeferedSubsystem;
|
||||||
|
ULONG MuSessionId;
|
||||||
|
PLIST_ENTRY NextEntry;
|
||||||
|
PSMP_REGISTRY_VALUE RegEntry;
|
||||||
|
|
||||||
|
/* Validate DeferedSubsystem's length */
|
||||||
|
if ((SmLoadDefered->Length <= 0) ||
|
||||||
|
(SmLoadDefered->Length > sizeof(SmLoadDefered->Buffer)))
|
||||||
|
{
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the name of the subsystem to start */
|
||||||
|
DeferedSubsystem.Length = (USHORT)SmLoadDefered->Length;
|
||||||
|
DeferedSubsystem.MaximumLength = DeferedSubsystem.Length;
|
||||||
|
DeferedSubsystem.Buffer = SmLoadDefered->Buffer;
|
||||||
|
|
||||||
|
/* Find a subsystem responsible for this session */
|
||||||
|
SmpGetProcessMuSessionId(ClientContext->ProcessHandle, &MuSessionId);
|
||||||
|
if (!SmpCheckDuplicateMuSessionId(MuSessionId))
|
||||||
|
{
|
||||||
|
DPRINT1("SMSS: Deferred subsystem load (%wZ) for MuSessionId %u, status=0x%x\n",
|
||||||
|
&DeferedSubsystem, MuSessionId, Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now process the deferred subsystems list */
|
||||||
|
for (NextEntry = SmpSubSystemsToDefer.Flink;
|
||||||
|
NextEntry != &SmpSubSystemsToDefer;
|
||||||
|
NextEntry = NextEntry->Flink)
|
||||||
|
{
|
||||||
|
/* Get each entry and check if it's the subsystem we are looking for */
|
||||||
|
RegEntry = CONTAINING_RECORD(NextEntry, SMP_REGISTRY_VALUE, Entry);
|
||||||
|
if (RtlEqualUnicodeString(&RegEntry->Name, &DeferedSubsystem, TRUE))
|
||||||
|
{
|
||||||
|
// TODO: One may want to extra-flag the command for
|
||||||
|
// specific POSIX or OS2 processing...
|
||||||
|
|
||||||
|
/* Load the deferred subsystem */
|
||||||
|
Status = SmpExecuteCommand(&RegEntry->Value,
|
||||||
|
MuSessionId,
|
||||||
|
NULL,
|
||||||
|
SMP_SUBSYSTEM_FLAG);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
DPRINT1("SMSS: Subsystem execute failed (%wZ)\n", &RegEntry->Value);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return status */
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
|
|
@ -91,9 +91,10 @@ extern UNICODE_STRING SmpSystemRoot;
|
||||||
extern PWCHAR SmpDefaultEnvironment;
|
extern PWCHAR SmpDefaultEnvironment;
|
||||||
extern UNICODE_STRING SmpDefaultLibPath;
|
extern UNICODE_STRING SmpDefaultLibPath;
|
||||||
extern LIST_ENTRY SmpSetupExecuteList;
|
extern LIST_ENTRY SmpSetupExecuteList;
|
||||||
extern LIST_ENTRY SmpSubSystemsToLoad;
|
|
||||||
extern LIST_ENTRY SmpExecuteList;
|
|
||||||
extern LIST_ENTRY SmpSubSystemList;
|
extern LIST_ENTRY SmpSubSystemList;
|
||||||
|
extern LIST_ENTRY SmpSubSystemsToLoad;
|
||||||
|
extern LIST_ENTRY SmpSubSystemsToDefer;
|
||||||
|
extern LIST_ENTRY SmpExecuteList;
|
||||||
extern ULONG AttachedSessionId;
|
extern ULONG AttachedSessionId;
|
||||||
extern BOOLEAN SmpDebug;
|
extern BOOLEAN SmpDebug;
|
||||||
|
|
||||||
|
|
|
@ -295,6 +295,12 @@ SmExecPgm(
|
||||||
_In_ PRTL_USER_PROCESS_INFORMATION ProcessInformation,
|
_In_ PRTL_USER_PROCESS_INFORMATION ProcessInformation,
|
||||||
_In_ BOOLEAN DebugFlag);
|
_In_ BOOLEAN DebugFlag);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
|
SmLoadDeferedSubsystem(
|
||||||
|
_In_ HANDLE SmApiPort,
|
||||||
|
_In_ PUNICODE_STRING DeferedSubsystem);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
SmStartCsr(
|
SmStartCsr(
|
||||||
|
|
|
@ -295,6 +295,58 @@ SmExecPgm(
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* This function is used to make the SM start an environment
|
||||||
|
* subsystem server process.
|
||||||
|
*
|
||||||
|
* @param[in] SmApiPort
|
||||||
|
* Port handle returned by SmConnectToSm().
|
||||||
|
*
|
||||||
|
* @param[in] DeferedSubsystem
|
||||||
|
* Name of the subsystem to start. This must be one of the subsystems
|
||||||
|
* listed by value's name in the SM registry key
|
||||||
|
* \Registry\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
|
||||||
|
* (used by the SM to lookup the corresponding image name).
|
||||||
|
* Default valid names are: "Debug", "Windows", "Posix", "Os2".
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Success status as handed by the SM reply; otherwise a failure
|
||||||
|
* status code.
|
||||||
|
**/
|
||||||
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
|
SmLoadDeferedSubsystem(
|
||||||
|
_In_ HANDLE SmApiPort,
|
||||||
|
_In_ PUNICODE_STRING DeferedSubsystem)
|
||||||
|
{
|
||||||
|
SM_API_MSG SmApiMsg = {0};
|
||||||
|
PSM_LOAD_DEFERED_SUBSYSTEM_MSG LoadDefered = &SmApiMsg.u.LoadDefered;
|
||||||
|
|
||||||
|
#if 0 //def _WIN64
|
||||||
|
/* 64-bit SMSS needs to talk to 32-bit processes so do the LPC conversion */
|
||||||
|
if (SmpIsWow64Process())
|
||||||
|
{
|
||||||
|
return SmpWow64LoadDeferedSubsystem(SmApiPort, DeferedSubsystem);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Validate DeferedSubsystem's length */
|
||||||
|
if (DeferedSubsystem->Length > sizeof(LoadDefered->Buffer))
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
/* Set the message data */
|
||||||
|
/* Buffer stores a counted non-NULL-terminated UNICODE string */
|
||||||
|
LoadDefered->Length = DeferedSubsystem->Length;
|
||||||
|
RtlCopyMemory(LoadDefered->Buffer,
|
||||||
|
DeferedSubsystem->Buffer,
|
||||||
|
DeferedSubsystem->Length);
|
||||||
|
|
||||||
|
/* Send the message and wait for a reply */
|
||||||
|
SmApiMsg.ApiNumber = SmpLoadDeferedSubsystemApi;
|
||||||
|
return SmSendMsgToSm(SmApiPort, &SmApiMsg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Requests the SM to create a new Terminal Services session
|
* Requests the SM to create a new Terminal Services session
|
||||||
|
|
Loading…
Reference in a new issue