Program.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. //===- Win32/Program.cpp - Win32 Program Implementation ------- -*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file provides the Win32 specific implementation of the Program class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/ADT/StringExtras.h"
  13. #include "llvm/Support/ConvertUTF.h"
  14. #include "llvm/Support/Errc.h"
  15. #include "llvm/Support/FileSystem.h"
  16. #include "llvm/Support/Path.h"
  17. #include "llvm/Support/Windows/WindowsSupport.h"
  18. #include "llvm/Support/WindowsError.h"
  19. #include "llvm/Support/raw_ostream.h"
  20. #include <psapi.h>
  21. #include <cstdio>
  22. #include <fcntl.h>
  23. #include <io.h>
  24. #include <malloc.h>
  25. #include <numeric>
  26. //===----------------------------------------------------------------------===//
  27. //=== WARNING: Implementation here must contain only Win32 specific code
  28. //=== and must not be UNIX code
  29. //===----------------------------------------------------------------------===//
  30. namespace llvm {
  31. ProcessInfo::ProcessInfo() : Pid(0), Process(0), ReturnCode(0) {}
  32. ErrorOr<std::string> sys::findProgramByName(StringRef Name,
  33. ArrayRef<StringRef> Paths) {
  34. assert(!Name.empty() && "Must have a name!");
  35. if (Name.find_first_of("/\\") != StringRef::npos)
  36. return std::string(Name);
  37. const wchar_t *Path = nullptr;
  38. std::wstring PathStorage;
  39. if (!Paths.empty()) {
  40. PathStorage.reserve(Paths.size() * MAX_PATH);
  41. for (unsigned i = 0; i < Paths.size(); ++i) {
  42. if (i)
  43. PathStorage.push_back(L';');
  44. StringRef P = Paths[i];
  45. SmallVector<wchar_t, MAX_PATH> TmpPath;
  46. if (std::error_code EC = windows::UTF8ToUTF16(P, TmpPath))
  47. return EC;
  48. PathStorage.append(TmpPath.begin(), TmpPath.end());
  49. }
  50. Path = PathStorage.c_str();
  51. }
  52. SmallVector<wchar_t, MAX_PATH> U16Name;
  53. if (std::error_code EC = windows::UTF8ToUTF16(Name, U16Name))
  54. return EC;
  55. SmallVector<StringRef, 12> PathExts;
  56. PathExts.push_back("");
  57. PathExts.push_back(".exe"); // FIXME: This must be in %PATHEXT%.
  58. if (const char *PathExtEnv = std::getenv("PATHEXT"))
  59. SplitString(PathExtEnv, PathExts, ";");
  60. SmallVector<char, MAX_PATH> U8Result;
  61. for (StringRef Ext : PathExts) {
  62. SmallVector<wchar_t, MAX_PATH> U16Result;
  63. DWORD Len = MAX_PATH;
  64. do {
  65. U16Result.resize_for_overwrite(Len);
  66. // Lets attach the extension manually. That is needed for files
  67. // with a point in name like aaa.bbb. SearchPathW will not add extension
  68. // from its argument to such files because it thinks they already had one.
  69. SmallVector<wchar_t, MAX_PATH> U16NameExt;
  70. if (std::error_code EC =
  71. windows::UTF8ToUTF16(Twine(Name + Ext).str(), U16NameExt))
  72. return EC;
  73. Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr,
  74. U16Result.size(), U16Result.data(), nullptr);
  75. } while (Len > U16Result.size());
  76. if (Len == 0)
  77. continue;
  78. U16Result.truncate(Len);
  79. if (std::error_code EC =
  80. windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result))
  81. return EC;
  82. if (sys::fs::can_execute(U8Result))
  83. break; // Found it.
  84. U8Result.clear();
  85. }
  86. if (U8Result.empty())
  87. return mapWindowsError(::GetLastError());
  88. llvm::sys::path::make_preferred(U8Result);
  89. return std::string(U8Result.begin(), U8Result.end());
  90. }
  91. bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix) {
  92. if (!ErrMsg)
  93. return true;
  94. char *buffer = NULL;
  95. DWORD LastError = GetLastError();
  96. DWORD R = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  97. FORMAT_MESSAGE_FROM_SYSTEM |
  98. FORMAT_MESSAGE_MAX_WIDTH_MASK,
  99. NULL, LastError, 0, (LPSTR)&buffer, 1, NULL);
  100. if (R)
  101. *ErrMsg = prefix + ": " + buffer;
  102. else
  103. *ErrMsg = prefix + ": Unknown error";
  104. *ErrMsg += " (0x" + llvm::utohexstr(LastError) + ")";
  105. LocalFree(buffer);
  106. return R != 0;
  107. }
  108. static HANDLE RedirectIO(Optional<StringRef> Path, int fd,
  109. std::string *ErrMsg) {
  110. HANDLE h;
  111. if (!Path) {
  112. if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),
  113. GetCurrentProcess(), &h,
  114. 0, TRUE, DUPLICATE_SAME_ACCESS))
  115. return INVALID_HANDLE_VALUE;
  116. return h;
  117. }
  118. std::string fname;
  119. if (Path->empty())
  120. fname = "NUL";
  121. else
  122. fname = std::string(*Path);
  123. SECURITY_ATTRIBUTES sa;
  124. sa.nLength = sizeof(sa);
  125. sa.lpSecurityDescriptor = 0;
  126. sa.bInheritHandle = TRUE;
  127. SmallVector<wchar_t, 128> fnameUnicode;
  128. if (Path->empty()) {
  129. // Don't play long-path tricks on "NUL".
  130. if (windows::UTF8ToUTF16(fname, fnameUnicode))
  131. return INVALID_HANDLE_VALUE;
  132. } else {
  133. if (sys::windows::widenPath(fname, fnameUnicode))
  134. return INVALID_HANDLE_VALUE;
  135. }
  136. h = CreateFileW(fnameUnicode.data(), fd ? GENERIC_WRITE : GENERIC_READ,
  137. FILE_SHARE_READ, &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS,
  138. FILE_ATTRIBUTE_NORMAL, NULL);
  139. if (h == INVALID_HANDLE_VALUE) {
  140. MakeErrMsg(ErrMsg, fname + ": Can't open file for " +
  141. (fd ? "input" : "output"));
  142. }
  143. return h;
  144. }
  145. }
  146. static bool Execute(ProcessInfo &PI, StringRef Program,
  147. ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env,
  148. ArrayRef<Optional<StringRef>> Redirects,
  149. unsigned MemoryLimit, std::string *ErrMsg,
  150. BitVector *AffinityMask) {
  151. if (!sys::fs::can_execute(Program)) {
  152. if (ErrMsg)
  153. *ErrMsg = "program not executable";
  154. return false;
  155. }
  156. // can_execute may succeed by looking at Program + ".exe". CreateProcessW
  157. // will implicitly add the .exe if we provide a command line without an
  158. // executable path, but since we use an explicit executable, we have to add
  159. // ".exe" ourselves.
  160. SmallString<64> ProgramStorage;
  161. if (!sys::fs::exists(Program))
  162. Program = Twine(Program + ".exe").toStringRef(ProgramStorage);
  163. // Windows wants a command line, not an array of args, to pass to the new
  164. // process. We have to concatenate them all, while quoting the args that
  165. // have embedded spaces (or are empty).
  166. auto Result = flattenWindowsCommandLine(Args);
  167. if (std::error_code ec = Result.getError()) {
  168. SetLastError(ec.value());
  169. MakeErrMsg(ErrMsg, std::string("Unable to convert command-line to UTF-16"));
  170. return false;
  171. }
  172. std::wstring Command = *Result;
  173. // The pointer to the environment block for the new process.
  174. std::vector<wchar_t> EnvBlock;
  175. if (Env) {
  176. // An environment block consists of a null-terminated block of
  177. // null-terminated strings. Convert the array of environment variables to
  178. // an environment block by concatenating them.
  179. for (StringRef E : *Env) {
  180. SmallVector<wchar_t, MAX_PATH> EnvString;
  181. if (std::error_code ec = windows::UTF8ToUTF16(E, EnvString)) {
  182. SetLastError(ec.value());
  183. MakeErrMsg(ErrMsg, "Unable to convert environment variable to UTF-16");
  184. return false;
  185. }
  186. llvm::append_range(EnvBlock, EnvString);
  187. EnvBlock.push_back(0);
  188. }
  189. EnvBlock.push_back(0);
  190. }
  191. // Create a child process.
  192. STARTUPINFOW si;
  193. memset(&si, 0, sizeof(si));
  194. si.cb = sizeof(si);
  195. si.hStdInput = INVALID_HANDLE_VALUE;
  196. si.hStdOutput = INVALID_HANDLE_VALUE;
  197. si.hStdError = INVALID_HANDLE_VALUE;
  198. if (!Redirects.empty()) {
  199. si.dwFlags = STARTF_USESTDHANDLES;
  200. si.hStdInput = RedirectIO(Redirects[0], 0, ErrMsg);
  201. if (si.hStdInput == INVALID_HANDLE_VALUE) {
  202. MakeErrMsg(ErrMsg, "can't redirect stdin");
  203. return false;
  204. }
  205. si.hStdOutput = RedirectIO(Redirects[1], 1, ErrMsg);
  206. if (si.hStdOutput == INVALID_HANDLE_VALUE) {
  207. CloseHandle(si.hStdInput);
  208. MakeErrMsg(ErrMsg, "can't redirect stdout");
  209. return false;
  210. }
  211. if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) {
  212. // If stdout and stderr should go to the same place, redirect stderr
  213. // to the handle already open for stdout.
  214. if (!DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
  215. GetCurrentProcess(), &si.hStdError,
  216. 0, TRUE, DUPLICATE_SAME_ACCESS)) {
  217. CloseHandle(si.hStdInput);
  218. CloseHandle(si.hStdOutput);
  219. MakeErrMsg(ErrMsg, "can't dup stderr to stdout");
  220. return false;
  221. }
  222. } else {
  223. // Just redirect stderr
  224. si.hStdError = RedirectIO(Redirects[2], 2, ErrMsg);
  225. if (si.hStdError == INVALID_HANDLE_VALUE) {
  226. CloseHandle(si.hStdInput);
  227. CloseHandle(si.hStdOutput);
  228. MakeErrMsg(ErrMsg, "can't redirect stderr");
  229. return false;
  230. }
  231. }
  232. }
  233. PROCESS_INFORMATION pi;
  234. memset(&pi, 0, sizeof(pi));
  235. fflush(stdout);
  236. fflush(stderr);
  237. SmallVector<wchar_t, MAX_PATH> ProgramUtf16;
  238. if (std::error_code ec = sys::windows::widenPath(Program, ProgramUtf16)) {
  239. SetLastError(ec.value());
  240. MakeErrMsg(ErrMsg,
  241. std::string("Unable to convert application name to UTF-16"));
  242. return false;
  243. }
  244. unsigned CreateFlags = CREATE_UNICODE_ENVIRONMENT;
  245. if (AffinityMask)
  246. CreateFlags |= CREATE_SUSPENDED;
  247. std::vector<wchar_t> CommandUtf16(Command.size() + 1, 0);
  248. std::copy(Command.begin(), Command.end(), CommandUtf16.begin());
  249. BOOL rc = CreateProcessW(ProgramUtf16.data(), CommandUtf16.data(), 0, 0, TRUE,
  250. CreateFlags, EnvBlock.empty() ? 0 : EnvBlock.data(),
  251. 0, &si, &pi);
  252. DWORD err = GetLastError();
  253. // Regardless of whether the process got created or not, we are done with
  254. // the handles we created for it to inherit.
  255. CloseHandle(si.hStdInput);
  256. CloseHandle(si.hStdOutput);
  257. CloseHandle(si.hStdError);
  258. // Now return an error if the process didn't get created.
  259. if (!rc) {
  260. SetLastError(err);
  261. MakeErrMsg(ErrMsg, std::string("Couldn't execute program '") +
  262. Program.str() + "'");
  263. return false;
  264. }
  265. PI.Pid = pi.dwProcessId;
  266. PI.Process = pi.hProcess;
  267. // Make sure these get closed no matter what.
  268. ScopedCommonHandle hThread(pi.hThread);
  269. // Assign the process to a job if a memory limit is defined.
  270. ScopedJobHandle hJob;
  271. if (MemoryLimit != 0) {
  272. hJob = CreateJobObjectW(0, 0);
  273. bool success = false;
  274. if (hJob) {
  275. JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli;
  276. memset(&jeli, 0, sizeof(jeli));
  277. jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
  278. jeli.ProcessMemoryLimit = uintptr_t(MemoryLimit) * 1048576;
  279. if (SetInformationJobObject(hJob, JobObjectExtendedLimitInformation,
  280. &jeli, sizeof(jeli))) {
  281. if (AssignProcessToJobObject(hJob, pi.hProcess))
  282. success = true;
  283. }
  284. }
  285. if (!success) {
  286. SetLastError(GetLastError());
  287. MakeErrMsg(ErrMsg, std::string("Unable to set memory limit"));
  288. TerminateProcess(pi.hProcess, 1);
  289. WaitForSingleObject(pi.hProcess, INFINITE);
  290. return false;
  291. }
  292. }
  293. // Set the affinity mask
  294. if (AffinityMask) {
  295. ::SetProcessAffinityMask(pi.hProcess,
  296. (DWORD_PTR)AffinityMask->getData().front());
  297. ::ResumeThread(pi.hThread);
  298. }
  299. return true;
  300. }
  301. static bool argNeedsQuotes(StringRef Arg) {
  302. if (Arg.empty())
  303. return true;
  304. return StringRef::npos != Arg.find_first_of("\t \"&\'()*<>\\`^|\n");
  305. }
  306. static std::string quoteSingleArg(StringRef Arg) {
  307. std::string Result;
  308. Result.push_back('"');
  309. while (!Arg.empty()) {
  310. size_t FirstNonBackslash = Arg.find_first_not_of('\\');
  311. size_t BackslashCount = FirstNonBackslash;
  312. if (FirstNonBackslash == StringRef::npos) {
  313. // The entire remainder of the argument is backslashes. Escape all of
  314. // them and just early out.
  315. BackslashCount = Arg.size();
  316. Result.append(BackslashCount * 2, '\\');
  317. break;
  318. }
  319. if (Arg[FirstNonBackslash] == '\"') {
  320. // This is an embedded quote. Escape all preceding backslashes, then
  321. // add one additional backslash to escape the quote.
  322. Result.append(BackslashCount * 2 + 1, '\\');
  323. Result.push_back('\"');
  324. } else {
  325. // This is just a normal character. Don't escape any of the preceding
  326. // backslashes, just append them as they are and then append the
  327. // character.
  328. Result.append(BackslashCount, '\\');
  329. Result.push_back(Arg[FirstNonBackslash]);
  330. }
  331. // Drop all the backslashes, plus the following character.
  332. Arg = Arg.drop_front(FirstNonBackslash + 1);
  333. }
  334. Result.push_back('"');
  335. return Result;
  336. }
  337. namespace llvm {
  338. ErrorOr<std::wstring> sys::flattenWindowsCommandLine(ArrayRef<StringRef> Args) {
  339. std::string Command;
  340. for (StringRef Arg : Args) {
  341. if (argNeedsQuotes(Arg))
  342. Command += quoteSingleArg(Arg);
  343. else
  344. Command += Arg;
  345. Command.push_back(' ');
  346. }
  347. SmallVector<wchar_t, MAX_PATH> CommandUtf16;
  348. if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16))
  349. return ec;
  350. return std::wstring(CommandUtf16.begin(), CommandUtf16.end());
  351. }
  352. ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
  353. bool WaitUntilChildTerminates, std::string *ErrMsg,
  354. Optional<ProcessStatistics> *ProcStat) {
  355. assert(PI.Pid && "invalid pid to wait on, process not started?");
  356. assert((PI.Process && PI.Process != INVALID_HANDLE_VALUE) &&
  357. "invalid process handle to wait on, process not started?");
  358. DWORD milliSecondsToWait = 0;
  359. if (WaitUntilChildTerminates)
  360. milliSecondsToWait = INFINITE;
  361. else if (SecondsToWait > 0)
  362. milliSecondsToWait = SecondsToWait * 1000;
  363. ProcessInfo WaitResult = PI;
  364. if (ProcStat)
  365. ProcStat->reset();
  366. DWORD WaitStatus = WaitForSingleObject(PI.Process, milliSecondsToWait);
  367. if (WaitStatus == WAIT_TIMEOUT) {
  368. if (SecondsToWait) {
  369. if (!TerminateProcess(PI.Process, 1)) {
  370. if (ErrMsg)
  371. MakeErrMsg(ErrMsg, "Failed to terminate timed-out program");
  372. // -2 indicates a crash or timeout as opposed to failure to execute.
  373. WaitResult.ReturnCode = -2;
  374. CloseHandle(PI.Process);
  375. return WaitResult;
  376. }
  377. WaitForSingleObject(PI.Process, INFINITE);
  378. CloseHandle(PI.Process);
  379. } else {
  380. // Non-blocking wait.
  381. return ProcessInfo();
  382. }
  383. }
  384. // Get process execution statistics.
  385. if (ProcStat) {
  386. FILETIME CreationTime, ExitTime, KernelTime, UserTime;
  387. PROCESS_MEMORY_COUNTERS MemInfo;
  388. if (GetProcessTimes(PI.Process, &CreationTime, &ExitTime, &KernelTime,
  389. &UserTime) &&
  390. GetProcessMemoryInfo(PI.Process, &MemInfo, sizeof(MemInfo))) {
  391. auto UserT = std::chrono::duration_cast<std::chrono::microseconds>(
  392. toDuration(UserTime));
  393. auto KernelT = std::chrono::duration_cast<std::chrono::microseconds>(
  394. toDuration(KernelTime));
  395. uint64_t PeakMemory = MemInfo.PeakPagefileUsage / 1024;
  396. *ProcStat = ProcessStatistics{UserT + KernelT, UserT, PeakMemory};
  397. }
  398. }
  399. // Get its exit status.
  400. DWORD status;
  401. BOOL rc = GetExitCodeProcess(PI.Process, &status);
  402. DWORD err = GetLastError();
  403. if (err != ERROR_INVALID_HANDLE)
  404. CloseHandle(PI.Process);
  405. if (!rc) {
  406. SetLastError(err);
  407. if (ErrMsg)
  408. MakeErrMsg(ErrMsg, "Failed getting status for program");
  409. // -2 indicates a crash or timeout as opposed to failure to execute.
  410. WaitResult.ReturnCode = -2;
  411. return WaitResult;
  412. }
  413. if (!status)
  414. return WaitResult;
  415. // Pass 10(Warning) and 11(Error) to the callee as negative value.
  416. if ((status & 0xBFFF0000U) == 0x80000000U)
  417. WaitResult.ReturnCode = static_cast<int>(status);
  418. else if (status & 0xFF)
  419. WaitResult.ReturnCode = status & 0x7FFFFFFF;
  420. else
  421. WaitResult.ReturnCode = 1;
  422. return WaitResult;
  423. }
  424. std::error_code llvm::sys::ChangeStdinMode(sys::fs::OpenFlags Flags){
  425. if (!(Flags & fs::OF_CRLF))
  426. return ChangeStdinToBinary();
  427. return std::error_code();
  428. }
  429. std::error_code llvm::sys::ChangeStdoutMode(sys::fs::OpenFlags Flags){
  430. if (!(Flags & fs::OF_CRLF))
  431. return ChangeStdoutToBinary();
  432. return std::error_code();
  433. }
  434. std::error_code sys::ChangeStdinToBinary() {
  435. int result = _setmode(_fileno(stdin), _O_BINARY);
  436. if (result == -1)
  437. return std::error_code(errno, std::generic_category());
  438. return std::error_code();
  439. }
  440. std::error_code sys::ChangeStdoutToBinary() {
  441. int result = _setmode(_fileno(stdout), _O_BINARY);
  442. if (result == -1)
  443. return std::error_code(errno, std::generic_category());
  444. return std::error_code();
  445. }
  446. std::error_code
  447. llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents,
  448. WindowsEncodingMethod Encoding) {
  449. std::error_code EC;
  450. llvm::raw_fd_ostream OS(FileName, EC, llvm::sys::fs::OF_TextWithCRLF);
  451. if (EC)
  452. return EC;
  453. if (Encoding == WEM_UTF8) {
  454. OS << Contents;
  455. } else if (Encoding == WEM_CurrentCodePage) {
  456. SmallVector<wchar_t, 1> ArgsUTF16;
  457. SmallVector<char, 1> ArgsCurCP;
  458. if ((EC = windows::UTF8ToUTF16(Contents, ArgsUTF16)))
  459. return EC;
  460. if ((EC = windows::UTF16ToCurCP(
  461. ArgsUTF16.data(), ArgsUTF16.size(), ArgsCurCP)))
  462. return EC;
  463. OS.write(ArgsCurCP.data(), ArgsCurCP.size());
  464. } else if (Encoding == WEM_UTF16) {
  465. SmallVector<wchar_t, 1> ArgsUTF16;
  466. if ((EC = windows::UTF8ToUTF16(Contents, ArgsUTF16)))
  467. return EC;
  468. // Endianness guessing
  469. char BOM[2];
  470. uint16_t src = UNI_UTF16_BYTE_ORDER_MARK_NATIVE;
  471. memcpy(BOM, &src, 2);
  472. OS.write(BOM, 2);
  473. OS.write((char *)ArgsUTF16.data(), ArgsUTF16.size() << 1);
  474. } else {
  475. llvm_unreachable("Unknown encoding");
  476. }
  477. if (OS.has_error())
  478. return make_error_code(errc::io_error);
  479. return EC;
  480. }
  481. bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
  482. ArrayRef<StringRef> Args) {
  483. // The documentation on CreateProcessW states that the size of the argument
  484. // lpCommandLine must not be greater than 32767 characters, including the
  485. // Unicode terminating null character. We use smaller value to reduce risk
  486. // of getting invalid command line due to unaccounted factors.
  487. static const size_t MaxCommandStringLength = 32000;
  488. SmallVector<StringRef, 8> FullArgs;
  489. FullArgs.push_back(Program);
  490. FullArgs.append(Args.begin(), Args.end());
  491. auto Result = flattenWindowsCommandLine(FullArgs);
  492. assert(!Result.getError());
  493. return (Result->size() + 1) <= MaxCommandStringLength;
  494. }
  495. }