51#define CMD_STRING L"cmd /c "
63 SIZE_T NumberOfBytesWritten;
66 if (!StandardHandle)
return;
84 &NumberOfBytesWritten);
127 if (ImageMajorVersion > 3 ||
128 (ImageMajorVersion == 3 && ImageMinorVersion >= 10))
134 DPRINT1(
"Accepting image version %lu.%lu, although ReactOS is an NT %hu.%hu OS!\n",
161 DPRINT1(
"Egad! This is a ReactOS Compute Server and we should prevent you from using certain APIs...but we won't.");
165 DPRINT1(
"Gasp! This is a ReactOS Storage Server and we should prevent you from using certain APIs...but we won't.");
169 DPRINT1(
"Golly! This is a ReactOS Web Blade Server and we should prevent you from using certain APIs...but we won't.");
249 sizeof(
L"EmbdTrst.DLL"));
257 "ImageOkToRunOnEmbeddedNT");
333 NextEntry = NextEntry->
Flink;
388 &SaferiReplaceProcessThreadTokens,
433 if (Handles->Section)
440 if (Handles->ViewBase.QuadPart)
499 PWCHAR Remaining, DllPathString, ScanChar;
501 PVOID RemoteAppCompatData;
552 if (StartupInfo->lpDesktop)
560 if (StartupInfo->lpReserved)
568 if (StartupInfo->lpTitle)
582 if (!AppCompatData) AppCompatDataSize = 0;
585 ProcessParameters =
NULL;
589 DPRINT(
"CmdLine : '%wZ'\n", &CommandLine);
593 DPRINT(
"Runtime : '%wZ'\n", &Runtime);
626 ScanChar = lpEnvironment;
630 while (*ScanChar++)
while (*ScanChar++);
664 ProcessParameters->
StartingX = StartupInfo->dwX;
665 ProcessParameters->
StartingY = StartupInfo->dwY;
666 ProcessParameters->
CountX = StartupInfo->dwXSize;
667 ProcessParameters->
CountY = StartupInfo->dwYSize;
668 ProcessParameters->
CountCharsX = StartupInfo->dwXCountChars;
669 ProcessParameters->
CountCharsY = StartupInfo->dwYCountChars;
670 ProcessParameters->
FillAttribute = StartupInfo->dwFillAttribute;
671 ProcessParameters->
WindowFlags = StartupInfo->dwFlags;
675 if (StartupInfo->dwFlags &
702 if (!(StartupInfo->dwFlags &
706 if ((InheritHandles) ||
711 if ((InheritHandles) ||
716 if ((InheritHandles) ||
732 if (ParameterFlags & 1)
738 if (ParameterFlags & 2)
745 RemoteParameters =
NULL;
747 (
PVOID*)&RemoteParameters,
771 ProcessParameters->
Length,
777 &RemotePeb->ProcessParameters,
784 RemoteAppCompatData =
NULL;
788 Size = AppCompatDataSize;
790 &RemoteAppCompatData,
808 &RemotePeb->pShimData,
809 &RemoteAppCompatData,
818 &RemotePeb->ImageSubsystem,
820 sizeof(ImageSubsystem),
834 DPRINT1(
"Failure to create process parameters: %lx\n",
Status);
902 (
PVOID)&dwProcessAffinityMask,
930 sizeof(*ShutdownParametersRequest));
961 sizeof(*ShutdownParametersRequest));
1017 lpMinimumWorkingSetSize,
1018 lpMaximumWorkingSetSize,
1042 if ((dwMinimumWorkingSetSize) && (dwMaximumWorkingSetSize))
1056 sizeof(QuotaLimits));
1089 dwMinimumWorkingSetSize,
1090 dwMaximumWorkingSetSize,
1122 lpCreationTime->dwLowDateTime = Kut.
CreateTime.
u.LowPart;
1123 lpCreationTime->dwHighDateTime = Kut.
CreateTime.
u.HighPart;
1124 lpExitTime->dwLowDateTime = Kut.
ExitTime.
u.LowPart;
1125 lpExitTime->dwHighDateTime = Kut.
ExitTime.
u.HighPart;
1126 lpKernelTime->dwLowDateTime = Kut.
KernelTime.
u.LowPart;
1127 lpKernelTime->dwHighDateTime = Kut.
KernelTime.
u.HighPart;
1128 lpUserTime->dwLowDateTime = Kut.
UserTime.
u.LowPart;
1129 lpUserTime->dwHighDateTime = Kut.
UserTime.
u.HighPart;
1178 sizeof(ProcessBasic),
1209 sizeof(ProcessBasic),
1288 lpStartupInfo->lpReserved =
Params->ShellInfo.Buffer;
1289 lpStartupInfo->lpDesktop =
Params->DesktopInfo.Buffer;
1290 lpStartupInfo->lpTitle =
Params->WindowTitle.Buffer;
1291 lpStartupInfo->dwX =
Params->StartingX;
1292 lpStartupInfo->dwY =
Params->StartingY;
1293 lpStartupInfo->dwXSize =
Params->CountX;
1294 lpStartupInfo->dwYSize =
Params->CountY;
1295 lpStartupInfo->dwXCountChars =
Params->CountCharsX;
1296 lpStartupInfo->dwYCountChars =
Params->CountCharsY;
1297 lpStartupInfo->dwFillAttribute =
Params->FillAttribute;
1298 lpStartupInfo->dwFlags =
Params->WindowFlags;
1299 lpStartupInfo->wShowWindow = (
WORD)
Params->ShowWindowFlags;
1300 lpStartupInfo->cbReserved2 =
Params->RuntimeData.Length;
1301 lpStartupInfo->lpReserved2 = (
LPBYTE)
Params->RuntimeData.Buffer;
1309 lpStartupInfo->hStdInput =
Params->StandardInput;
1310 lpStartupInfo->hStdOutput =
Params->StandardOutput;
1311 lpStartupInfo->hStdError =
Params->StandardError;
1323 ANSI_STRING TitleString, ShellString, DesktopString;
1332 while (!StartupInfo)
1337 sizeof(*StartupInfo));
1346 StartupInfo->
cb =
sizeof(*StartupInfo);
1424 lpStartupInfo->cb = StartupInfo->
cb;
1425 lpStartupInfo->lpReserved = StartupInfo->
lpReserved;
1426 lpStartupInfo->lpDesktop = StartupInfo->
lpDesktop;
1427 lpStartupInfo->lpTitle = StartupInfo->
lpTitle;
1428 lpStartupInfo->dwX = StartupInfo->
dwX;
1429 lpStartupInfo->dwY = StartupInfo->
dwY;
1430 lpStartupInfo->dwXSize = StartupInfo->
dwXSize;
1431 lpStartupInfo->dwYSize = StartupInfo->
dwYSize;
1435 lpStartupInfo->dwFlags = StartupInfo->
dwFlags;
1436 lpStartupInfo->wShowWindow = StartupInfo->
wShowWindow;
1437 lpStartupInfo->cbReserved2 = StartupInfo->
cbReserved2;
1438 lpStartupInfo->lpReserved2 = StartupInfo->
lpReserved2;
1441 if (lpStartupInfo->dwFlags &
1445 lpStartupInfo->hStdInput = StartupInfo->
hStdInput;
1446 lpStartupInfo->hStdOutput = StartupInfo->
hStdOutput;
1447 lpStartupInfo->hStdError = StartupInfo->
hStdError;
1506 ExitProcessRequest->
uExitCode = uExitCode;
1510 sizeof(*ExitProcessRequest));
1666 sizeof(PriorityClass),
1700 switch (dwPriorityClass)
1805 sizeof(ProcessBasicInfo),
1833 sizeof(VersionData),
1918 IN BOOL bDisablePriorityBoost)
1960 *pdwHandleCount = phc;
1994 *Wow64Process = (
pbi != 0);
2033 (
PVOID)lpBaseAddress,
2039 if (lpNumberOfBytesRead) *lpNumberOfBytesRead =
nSize;
2070 Base = lpBaseAddress;
2102 if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten =
nSize;
2140 if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten =
nSize;
2205 &SessionInformation,
2206 sizeof(SessionInformation),
2214 *pSessionId = SessionInformation.
SessionId;
2225#define AddToHandle(x,y) (x) = (HANDLE)((ULONG_PTR)(x) | (y));
2226#define RemoveFromHandle(x,y) (x) = (HANDLE)((ULONG_PTR)(x) & ~(y));
2259 ULONG ParameterFlags, PrivilegeValue, HardErrorMode, ErrorResponse;
2261 BOOLEAN InJob, SaferNeeded, UseLargePages, HavePrivilege;
2262 BOOLEAN QuerySection, SkipSaferAndAppCompat;
2272 NTSTATUS Status, AppCompatStatus, SaferStatus, IFEOStatus, ImageDbgStatus;
2290 SIZE_T EnvironmentLength, CmdLineLength;
2295 BOOLEAN SearchRetry, QuotesNeeded, CmdLineIsAppName, HasQuotes;
2301#if _SXS_SUPPORT_ENABLED_
2309 PVOID CapturedStrings[3];
2313 PWCHAR SxsConglomeratedBuffer, StaticBuffer;
2314 ULONG ConglomeratedBufferSizeBytes, StaticBufferSize,
i;
2321 PWCHAR FilePart, PathBuffer, FreeBuffer;
2329 PVOID AppCompatSxsData, AppCompatData;
2330 ULONG AppCompatSxsDataSize, AppCompatDataSize;
2334 ULONG BinarySubType, VdmBinaryType, VdmTask, VdmReserve;
2344 QuerySection =
FALSE;
2346 SkipSaferAndAppCompat =
FALSE;
2353 SectionHandle =
NULL;
2355 ThreadHandle =
NULL;
2359 AppCompatData =
NULL;
2360 AppCompatDataSize = 0;
2361 AppCompatSxsData =
NULL;
2362 AppCompatSxsDataSize = 0;
2363 CaptureBuffer =
NULL;
2364#if _SXS_SUPPORT_ENABLED_
2365 SxsConglomeratedBuffer =
NULL;
2370 DebuggerCmdLine =
NULL;
2380 QuotedCmdLine =
NULL;
2390 VdmWaitObject =
NULL;
2391 UseVdmReserve =
FALSE;
2400#if _SXS_SUPPORT_ENABLED_
2406 RtlZeroMemory(&LocalProcessAttributes,
sizeof(LocalProcessAttributes));
2407 RtlZeroMemory(&LocalThreadAttributes,
sizeof(LocalThreadAttributes));
2410 RtlZeroMemory(lpProcessInformation,
sizeof(*lpProcessInformation));
2411 if (hNewToken) *hNewToken =
NULL;
2415 dwCreationFlags &= ~CREATE_NO_WINDOW;
2417#if _SXS_SUPPORT_ENABLED_
2419 SxsStaticBuffers[0] = &SxsWin32ManifestPath;
2420 SxsStaticBuffers[1] = &SxsWin32PolicyPath;
2421 SxsStaticBuffers[2] = &SxsWin32AssemblyDirectory;
2422 SxsStaticBuffers[3] = &SxsNtManifestPath;
2423 SxsStaticBuffers[4] = &SxsNtPolicyPath;
2424 ExePathPair.
Win32 = &SxsWin32ExePath;
2425 ExePathPair.
Nt = &SxsNtExePath;
2426 ManifestPathPair.
Win32 = &SxsWin32ManifestPath.
String;
2427 ManifestPathPair.
Nt = &SxsNtManifestPath.
String;
2428 PolicyPathPair.
Win32 = &SxsWin32PolicyPath.
String;
2429 PolicyPathPair.
Nt = &SxsNtPolicyPath.
String;
2432 DPRINT(
"CreateProcessInternalW: '%S' '%S' %lx\n", lpApplicationName, lpCommandLine, dwCreationFlags);
2442 DPRINT1(
"Invalid flag combo used\n");
2492 DPRINT1(
"Invalid WOW flags\n");
2508 dwCreationFlags = (dwCreationFlags &~ CREATE_SHARED_WOW_VDM) |
2517 while ((*pcScan) || (*(pcScan + 1))) ++pcScan;
2520 EnvironmentLength = (pcScan +
sizeof(
ANSI_NULL) - (
PCHAR)lpEnvironment);
2563 lpEnvironment = UnicodeEnv.
Buffer;
2567 StartupInfo = *lpStartupInfo;
2574 StartupInfo.
dwFlags &= ~STARTF_USESTDHANDLES;
2603 QuotesNeeded =
FALSE;
2604 CmdLineIsAppName =
FALSE;
2607 if (!lpApplicationName)
2624 lpApplicationName = NullBuffer = ScanString = lpCommandLine;
2627 if (*lpCommandLine ==
L'\"')
2630 SearchRetry =
FALSE;
2632 lpApplicationName = ScanString;
2636 if (*ScanString ==
L'\"')
2639 NullBuffer = ScanString;
2646 NullBuffer = ScanString;
2653 lpApplicationName = lpCommandLine;
2657 if ((*ScanString ==
L' ') || (*ScanString ==
L'\t'))
2660 NullBuffer = ScanString;
2666 NullBuffer = ScanString;
2671 SaveChar = *NullBuffer;
2717 DPRINT(
"Length: %lu Buffer: %S\n",
Length, NameBuffer);
2723 *NullBuffer = SaveChar;
2724 lpApplicationName = NameBuffer;
2768 *NullBuffer = SaveChar;
2769 lpApplicationName = NameBuffer;
2772 if (!(*ScanString) || !(SearchRetry))
2781 NullBuffer = ScanString;
2784 QuotesNeeded =
TRUE;
2789 else if (!(lpCommandLine) || !(*lpCommandLine))
2792 CmdLineIsAppName =
TRUE;
2793 lpCommandLine = (
LPWSTR)lpApplicationName;
2800 &SxsWin32RelativePath);
2801 if (!TranslationStatus)
2804 DPRINT1(
"Path translation for SxS failed\n");
2812 FreeBuffer = PathName.
Buffer;
2823 RtlInitEmptyUnicodeString(&PathBufferString,
NULL, 0);
2842 SxsWin32ExePath = PathBufferString;
2843 PathBuffer = PathBufferString.
Buffer;
2845 DPRINT(
"SxS Path: %S\n", PathBuffer);
2849#if _SXS_SUPPORT_ENABLED_
2850 SxsNtExePath = PathName;
2875 &LocalObjectAttributes,
2885 &LocalObjectAttributes,
2894 DPRINT1(
"Open file failed: %lx (%wZ)\n",
Status, &PathName);
2947 DPRINT1(
"Invalid Blade hashes!\n");
2957 DPRINT1(
"Tampered Blade hashes!\n");
2974 SectionHandle =
NULL;
2990 UseVdmReserve =
TRUE;
2994 SectionHandle =
NULL;
2997 QuerySection =
FALSE;
3002 if (!SkipSaferAndAppCompat)
3014 AppCompatData =
NULL;
3015 AppCompatSxsData =
NULL;
3032 sizeof(ImageInformation),
3040 QuerySection =
TRUE;
3041 ImageMachine = ImageInformation.
Machine;
3053 &AppCompatSxsDataSize,
3058 DPRINT1(
"App compat launch failure: %lx\n", AppCompatStatus);
3075 SectionHandle =
NULL;
3088 if (!(SkipSaferAndAppCompat) &&
3110 SaferNeeded =
FALSE;
3122 (
LPWSTR)lpApplicationName,
3127 if (SaferStatus == 0xFFFFFFFF)
3130 DPRINT1(
"WinSafer blocking process launch\n");
3139 DPRINT1(
"Error checking WinSafer: %lx\n", SaferStatus);
3164 DPRINT1(
"VDM environment for WOW app failed\n");
3172 VdmBinaryType = (dwCreationFlags &
3217 if (UseVdmReserve) VdmReserve = 1;
3227 DPRINT1(
"VDM Configuration failed for WOW\n");
3233 lpCommandLine = VdmString.
Buffer;
3234 lpApplicationName =
NULL;
3255 DPRINT1(
"VDM is not ready for WOW\n");
3268 if (VdmWaitObject)
goto VdmShortCircuit;
3271 bInheritHandles =
FALSE;
3274 if ((lpEnvironment) &&
3281 SkipSaferAndAppCompat =
TRUE;
3309 DPRINT1(
"VDM environment for DOS failed\n");
3345 DPRINT1(
"Detached process but no VDM, not allowed\n");
3358 DPRINT1(
"VDM Configuration failed for DOS\n");
3364 lpCommandLine = VdmString.
Buffer;
3365 lpApplicationName =
NULL;
3378 DPRINT1(
"VDM is not ready for DOS\n");
3391 if (VdmWaitObject)
goto VdmShortCircuit;
3394 bInheritHandles =
FALSE;
3397 if ((lpEnvironment) &&
3404 lpEnvironment = VdmUnicodeEnv.
Buffer;
3416 DPRINT1(
"'%wZ': Invalid EXE, and not a batch or script file\n", &PathName);
3423 CmdQuoteLength = CmdLineIsAppName || HasQuotes;
3424 if (!CmdLineIsAppName)
3426 if (HasQuotes) CmdQuoteLength++;
3434 CmdLineLength =
wcslen(lpCommandLine);
3436 CmdLineLength += CmdQuoteLength +
sizeof(
ANSI_NULL);
3437 CmdLineLength *=
sizeof(
WCHAR);
3443 if (!AnsiCmdCommand)
3452 if ((CmdLineIsAppName) || (HasQuotes))
3454 wcscat(AnsiCmdCommand,
L"\"");
3456 wcscat(AnsiCmdCommand, lpCommandLine);
3457 if ((CmdLineIsAppName) || (HasQuotes))
3459 wcscat(AnsiCmdCommand,
L"\"");
3466 lpCommandLine = DebuggerString.
Buffer;
3467 lpApplicationName =
NULL;
3468 DPRINT1(
"Retrying with: %S\n", lpCommandLine);
3472 SkipSaferAndAppCompat =
TRUE;
3479 DPRINT1(
"64-bit binary, failing\n");
3488 DPRINT1(
"File is offline, failing\n");
3514 dwCreationFlags &= ~CREATE_SEPARATE_WOW_VDM;
3524 sizeof(ImageInformation),
3529 DPRINT1(
"Section query failed\n");
3536 QuerySection =
TRUE;
3543 DPRINT1(
"Trying to launch a DLL, failing\n");
3550 Flags &= ~PROCESS_CREATE_FLAGS_LARGE_PAGES;
3553 ParameterFlags &= ~2;
3569 if (!DebuggerCmdLine)
3575 if (!DebuggerCmdLine)
3596 (ResultSize <
sizeof(
WCHAR)) ||
3600 RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
3601 DebuggerCmdLine =
NULL;
3609 sizeof(UseLargePages),
3611 if ((
NT_SUCCESS(IFEOStatus)) && (UseLargePages))
3629 ErrorParameters[0] = (
ULONG_PTR)&PathName;
3648 DPRINT1(
"Invalid image architecture: %lx\n", ImageInformation.
Machine);
3659 SectionHandle =
NULL;
3660 QuerySection =
FALSE;
3679 DPRINT1(
"Subsystem command line failed\n");
3684 lpCommandLine = DebuggerString.
Buffer;
3685 lpApplicationName =
NULL;
3688 SkipSaferAndAppCompat =
TRUE;
3689 DPRINT1(
"Retrying with: %S\n", lpCommandLine);
3699 DPRINT1(
"Invalid subsystem version: %hu.%hu\n",
3707 if (DebuggerCmdLine)
3714 lpCommandLine = (
LPWSTR)lpApplicationName;
3751 if (!DebuggerString.
Buffer)
3759 RtlInitEmptyUnicodeString(&DebuggerString,
3773 DbgPrint(
"BASE: Calling debugger with '%wZ'\n", &DebuggerString);
3776 lpCommandLine = DebuggerString.
Buffer;
3777 lpApplicationName =
NULL;
3781 SectionHandle =
NULL;
3782 QuerySection =
FALSE;
3789 RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
3790 DebuggerCmdLine =
NULL;
3791 DPRINT1(
"Retrying with: %S\n", lpCommandLine);
3797 lpProcessAttributes,
3803 LocalProcessAttributes = *lpProcessAttributes;
3806 &LocalProcessAttributes,
3824 DPRINT1(
"Failed to connect to DbgUI!\n");
3845 HavePrivilege =
FALSE;
3846 PrivilegeState =
NULL;
3855 HavePrivilege =
TRUE;
3896 RealTimePrivilegeState =
NULL;
3947 DPRINT1(
"Failed to update VDM with wait object\n");
3948 VdmWaitObject =
NULL;
3986 sizeof(ImageInformation),
3998 QuerySection =
TRUE;
4005 DPRINT(
"Image should receive SxS Fusion Isolation\n");
4012 if (lpCurrentDirectory)
4015 DPRINT(
"Current directory: %S\n", lpCurrentDirectory);
4047 DPRINT1(
"Current directory is invalid\n");
4055 if ((QuotesNeeded) || (CmdLineIsAppName))
4070 SaveChar = *NullBuffer;
4075 wcscat(QuotedCmdLine, lpCommandLine);
4081 *NullBuffer = SaveChar;
4082 wcscat(QuotedCmdLine, NullBuffer);
4088 if (QuotesNeeded) QuotesNeeded =
FALSE;
4089 if (CmdLineIsAppName) CmdLineIsAppName =
FALSE;
4094 if (CreateProcessMsg->
Sxs.
Flags & 1) ParameterFlags |= 1;
4097 if ((QuotesNeeded) || (CmdLineIsAppName)) lpCommandLine = QuotedCmdLine;
4108 dwCreationFlags | NoWindow,
4116 DPRINT1(
"BasePushProcessParameters failed\n");
4125 if (!(VdmBinaryType) &&
4126 !(bInheritHandles) &&
4195 LocalThreadAttributes = *lpThreadAttributes;
4198 &LocalThreadAttributes,
4228 DPRINT(
"TODO: WOW64 is not supported yet\n");
4236 switch (ImageInformation.
Machine)
4251 DbgPrint(
"kernel32: No mapping for ImageInformation.Machine == %04x\n",
4302 CreateProcessMsg->
VdmTask = VdmTask;
4304 else if (VdmReserve)
4314 DPRINT1(
"This is an SxS Message -- should not happen yet\n");
4326 sizeof(*CreateProcessMsg));
4332 CaptureBuffer =
NULL;
4339 DPRINT1(
"Failed to tell csrss about new process\n");
4401 lpProcessInformation->hProcess = VdmWaitObject;
4417 lpProcessInformation->hProcess = VdmWaitObject;
4430 lpProcessInformation->hThread = ThreadHandle;
4436 ThreadHandle =
NULL;
4440 if (DebuggerCmdLine)
RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
4446 RtlInitEmptyUnicodeString(&SxsWin32ExePath,
NULL, 0);
4447 SxsWin32ExePath.
Length = 0;
4453#if _SXS_SUPPORT_ENABLED_
4462 if (SxsConglomeratedBuffer)
4465 for (
i = 0;
i < 5;
i++)
4468 ThisBuffer = SxsStaticBuffers[
i];
4473 if ((ThisBuffer != (
PVOID)-8) && (ByteBuffer->
Buffer))
4489 RtlInitEmptyUnicodeString(&ThisBuffer->
String,
4510 lpEnvironment =
NULL;
4514 RtlFreeHeap(RtlGetProcessHeap(), 0, QuotedCmdLine);
4521 if (SectionHandle)
NtClose(SectionHandle);
4535 if (JobHandle)
NtClose(JobHandle);
4577 if (VdmWaitObject)
NtClose(VdmWaitObject);
4597 BOOL bInheritHandles,
4598 DWORD dwCreationFlags,
4608 lpProcessAttributes,
4615 lpProcessInformation,
4625 LPCSTR lpApplicationName,
4626 LPSTR lpCommandLine,
4629 BOOL bInheritHandles,
4630 DWORD dwCreationFlags,
4632 LPCSTR lpCurrentDirectory,
4643 DPRINT(
"dwCreationFlags %x, lpEnvironment %p, lpCurrentDirectory %p, "
4644 "lpStartupInfo %p, lpProcessInformation %p\n",
4645 dwCreationFlags, lpEnvironment, lpCurrentDirectory,
4646 lpStartupInfo, lpProcessInformation);
4649 RtlMoveMemory(&StartupInfo, lpStartupInfo,
sizeof(*lpStartupInfo));
4667 if (lpApplicationName)
4672 if (lpCurrentDirectory)
4675 lpCurrentDirectory);
4699 lpProcessAttributes,
4706 lpProcessInformation,