[CSRSRV] Minimally-adapt CSRSRV to make it able to host other subsystems than Win32.

This is really ReactOS-specific, so I surround them with __REACTOS__
(even if this is our code) to differentiate these from Win2k3 behaviour,
even though they were strongly inspired by what was possible in the beta
versions of NT 3.1 (pre-3.10.404).
Interestingly, Windows 7+ partially re-introduced that functionality
(just in differencing "Windows=On" from "Off").

See https://reactos.org/wiki/User:Hbelusca/CSRSS for more information.
This commit is contained in:
Hermès Bélusca-Maïto 2022-10-23 23:54:06 +02:00
parent 2fef8be892
commit bcbfcd2278
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -31,6 +31,10 @@ PCSR_THREAD CsrSbApiRequestThreadPtr;
HANDLE CsrSmApiPort = NULL; HANDLE CsrSmApiPort = NULL;
HANDLE hSbApiPort = NULL; HANDLE hSbApiPort = NULL;
HANDLE CsrApiPort = NULL; HANDLE CsrApiPort = NULL;
#ifdef __REACTOS__
BOOLEAN CsrWindowsControl;
ULONG CsrSubSystemType; // Known as SessionFirstProcessImageType in Windows 7+
#endif
ULONG CsrMaxApiRequestThreads; ULONG CsrMaxApiRequestThreads;
ULONG CsrTotalPerProcessDataLength; ULONG CsrTotalPerProcessDataLength;
ULONG SessionId; ULONG SessionId;
@ -559,6 +563,10 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
/* Set the Defaults */ /* Set the Defaults */
CsrTotalPerProcessDataLength = 0; CsrTotalPerProcessDataLength = 0;
CsrObjectDirectory = NULL; CsrObjectDirectory = NULL;
#ifdef __REACTOS__
CsrWindowsControl = FALSE;
CsrSubSystemType = IMAGE_SUBSYSTEM_UNKNOWN;
#endif
CsrMaxApiRequestThreads = 16; CsrMaxApiRequestThreads = 16;
/* Save our Session ID, and create a Directory for it */ /* Save our Session ID, and create a Directory for it */
@ -619,7 +627,36 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
} }
else if (_stricmp(ParameterName, "SubSystemType") == 0) else if (_stricmp(ParameterName, "SubSystemType") == 0)
{ {
#ifdef __REACTOS__
/* Well-known subsystems, specified by names */
if (_stricmp(ParameterValue, "windows") == 0)
{
/* Behaviour compatible with Windows 7+ */
if (CsrWindowsControl)
CsrSubSystemType = IMAGE_SUBSYSTEM_WINDOWS_GUI;
else
CsrSubSystemType = IMAGE_SUBSYSTEM_WINDOWS_CUI;
}
else if (_stricmp(ParameterValue, "posix") == 0)
{
CsrSubSystemType = IMAGE_SUBSYSTEM_POSIX_CUI;
}
else if (_stricmp(ParameterValue, "os2") == 0)
{
CsrSubSystemType = IMAGE_SUBSYSTEM_OS2_CUI;
}
else if (_stricmp(ParameterValue, "native") == 0)
{
CsrSubSystemType = IMAGE_SUBSYSTEM_NATIVE;
}
else
{
/* Another subsystem type, specified by a numerical value */
Status = RtlCharToInteger(ParameterValue, 0, &CsrSubSystemType);
}
#else
/* Ignored */ /* Ignored */
#endif
} }
else if (_stricmp(ParameterName, "MaxRequestThreads") == 0) else if (_stricmp(ParameterName, "MaxRequestThreads") == 0)
{ {
@ -634,7 +671,7 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
} }
else if (_stricmp(ParameterName, "ProfileControl") == 0) else if (_stricmp(ParameterName, "ProfileControl") == 0)
{ {
/* Ignored */ /* Related functionality ignored since NT 3.5 */
} }
else if (_stricmp(ParameterName, "SharedSection") == 0) else if (_stricmp(ParameterName, "SharedSection") == 0)
{ {
@ -661,7 +698,7 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
/* Check for the Entry Point */ /* Check for the Entry Point */
if ((*ServerString == ':') && (!EntryPoint)) if ((*ServerString == ':') && (!EntryPoint))
{ {
/* Found it. Add a nullchar and save it */ /* Found it. NULL-terminate and save it. */
*ServerString++ = ANSI_NULL; *ServerString++ = ANSI_NULL;
EntryPoint = ServerString; EntryPoint = ServerString;
} }
@ -696,8 +733,11 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
} }
else if (_stricmp(ParameterName, "Windows") == 0) else if (_stricmp(ParameterName, "Windows") == 0)
{ {
#ifdef __REACTOS__
CsrWindowsControl = (_stricmp(ParameterValue, "On") == 0);
#else
/* Ignored */ /* Ignored */
// Check whether we want to start in pure GUI or pure CLI. #endif
} }
else else
{ {
@ -1042,6 +1082,10 @@ CsrServerInitialization(IN ULONG ArgumentCount,
return Status; return Status;
} }
#ifdef __REACTOS__
if (CsrSubSystemType != IMAGE_SUBSYSTEM_UNKNOWN)
{
#endif
/* Initialize the API Port for SM communication */ /* Initialize the API Port for SM communication */
Status = CsrSbApiPortInitialize(); Status = CsrSbApiPortInitialize();
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -1054,7 +1098,11 @@ CsrServerInitialization(IN ULONG ArgumentCount,
/* We're all set! Connect to SM! */ /* We're all set! Connect to SM! */
Status = SmConnectToSm(&CsrSbApiPortName, Status = SmConnectToSm(&CsrSbApiPortName,
CsrSbApiPort, CsrSbApiPort,
#ifdef __REACTOS__
CsrSubSystemType,
#else
IMAGE_SUBSYSTEM_WINDOWS_GUI, IMAGE_SUBSYSTEM_WINDOWS_GUI,
#endif
&CsrSmApiPort); &CsrSmApiPort);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -1062,6 +1110,9 @@ CsrServerInitialization(IN ULONG ArgumentCount,
__FUNCTION__, Status); __FUNCTION__, Status);
return Status; return Status;
} }
#ifdef __REACTOS__
}
#endif
/* Have us handle Hard Errors */ /* Have us handle Hard Errors */
Status = NtSetDefaultHardErrorPort(CsrApiPort); Status = NtSetDefaultHardErrorPort(CsrApiPort);