LLVM 22.0.0git
Program.inc
Go to the documentation of this file.
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
13#include "llvm/ADT/BitVector.h"
16#include "llvm/Support/Errc.h"
18#include "llvm/Support/Path.h"
22#include <cstdio>
23#include <fcntl.h>
24#include <io.h>
25#include <malloc.h>
26#include <numeric>
27#include <psapi.h>
28
29//===----------------------------------------------------------------------===//
30//=== WARNING: Implementation here must contain only Win32 specific code
31//=== and must not be UNIX code
32//===----------------------------------------------------------------------===//
33
34namespace llvm {
35
36ProcessInfo::ProcessInfo() : Pid(0), Process(0), ReturnCode(0) {}
37
38ErrorOr<std::string> sys::findProgramByName(StringRef Name,
39 ArrayRef<StringRef> Paths) {
40 assert(!Name.empty() && "Must have a name!");
41
42 if (Name.find_first_of("/\\") != StringRef::npos)
43 return std::string(Name);
44
45 const wchar_t *Path = nullptr;
46 std::wstring PathStorage;
47 if (!Paths.empty()) {
48 PathStorage.reserve(Paths.size() * MAX_PATH);
49 for (unsigned i = 0; i < Paths.size(); ++i) {
50 if (i)
51 PathStorage.push_back(L';');
52 StringRef P = Paths[i];
53 SmallVector<wchar_t, MAX_PATH> TmpPath;
54 if (std::error_code EC = windows::UTF8ToUTF16(P, TmpPath))
55 return EC;
56 PathStorage.append(TmpPath.begin(), TmpPath.end());
57 }
58 Path = PathStorage.c_str();
59 }
60
61 SmallVector<wchar_t, MAX_PATH> U16Name;
62 if (std::error_code EC = windows::UTF8ToUTF16(Name, U16Name))
63 return EC;
64
65 SmallVector<StringRef, 12> PathExts;
66 PathExts.push_back("");
67 PathExts.push_back(".exe"); // FIXME: This must be in %PATHEXT%.
68 if (const char *PathExtEnv = std::getenv("PATHEXT"))
69 SplitString(PathExtEnv, PathExts, ";");
70
71 SmallVector<char, MAX_PATH> U8Result;
72 for (StringRef Ext : PathExts) {
73 SmallVector<wchar_t, MAX_PATH> U16Result;
74 DWORD Len = MAX_PATH;
75 do {
76 U16Result.resize_for_overwrite(Len);
77 // Lets attach the extension manually. That is needed for files
78 // with a point in name like aaa.bbb. SearchPathW will not add extension
79 // from its argument to such files because it thinks they already had one.
80 SmallVector<wchar_t, MAX_PATH> U16NameExt;
81 if (std::error_code EC =
82 windows::UTF8ToUTF16(Twine(Name + Ext).str(), U16NameExt))
83 return EC;
84
85 Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr, U16Result.size(),
86 U16Result.data(), nullptr);
87 } while (Len > U16Result.size());
88
89 if (Len == 0)
90 continue;
91
92 U16Result.truncate(Len);
93
94 if (std::error_code EC =
95 windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result))
96 return EC;
97
98 if (sys::fs::can_execute(U8Result))
99 break; // Found it.
100
101 U8Result.clear();
102 }
103
104 if (U8Result.empty())
105 return mapWindowsError(::GetLastError());
106
108 return std::string(U8Result.begin(), U8Result.end());
109}
110
111bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix) {
112 if (!ErrMsg)
113 return true;
114 char *buffer = NULL;
115 DWORD LastError = GetLastError();
116 DWORD R = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
117 FORMAT_MESSAGE_FROM_SYSTEM |
118 FORMAT_MESSAGE_MAX_WIDTH_MASK,
119 NULL, LastError, 0, (LPSTR)&buffer, 1, NULL);
120 if (R)
121 *ErrMsg = prefix + ": " + buffer;
122 else
123 *ErrMsg = prefix + ": Unknown error";
124 *ErrMsg += " (0x" + llvm::utohexstr(LastError) + ")";
125
126 LocalFree(buffer);
127 return R != 0;
128}
129
130static HANDLE RedirectIO(std::optional<StringRef> Path, int fd,
131 std::string *ErrMsg) {
132 HANDLE h;
133 if (!Path) {
134 if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),
135 GetCurrentProcess(), &h, 0, TRUE,
136 DUPLICATE_SAME_ACCESS))
137 return INVALID_HANDLE_VALUE;
138 return h;
139 }
140
141 std::string fname;
142 if (Path->empty())
143 fname = "NUL";
144 else
145 fname = std::string(*Path);
146
147 SECURITY_ATTRIBUTES sa;
148 sa.nLength = sizeof(sa);
149 sa.lpSecurityDescriptor = 0;
150 sa.bInheritHandle = TRUE;
151
152 SmallVector<wchar_t, 128> fnameUnicode;
153 if (Path->empty()) {
154 // Don't play long-path tricks on "NUL".
155 if (windows::UTF8ToUTF16(fname, fnameUnicode))
156 return INVALID_HANDLE_VALUE;
157 } else {
158 if (sys::windows::widenPath(fname, fnameUnicode))
159 return INVALID_HANDLE_VALUE;
160 }
161 h = CreateFileW(fnameUnicode.data(), fd ? GENERIC_WRITE : GENERIC_READ,
162 FILE_SHARE_READ, &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS,
163 FILE_ATTRIBUTE_NORMAL, NULL);
164 if (h == INVALID_HANDLE_VALUE) {
165 MakeErrMsg(ErrMsg,
166 fname + ": Can't open file for " + (fd ? "input" : "output"));
167 }
168
169 return h;
170}
171
172} // namespace llvm
173
174static bool Execute(ProcessInfo &PI, StringRef Program,
175 ArrayRef<StringRef> Args,
176 std::optional<ArrayRef<StringRef>> Env,
177 ArrayRef<std::optional<StringRef>> Redirects,
178 unsigned MemoryLimit, std::string *ErrMsg,
179 BitVector *AffinityMask, bool DetachProcess) {
180 if (!sys::fs::can_execute(Program)) {
181 if (ErrMsg)
182 *ErrMsg = "program not executable";
183 return false;
184 }
185
186 // can_execute may succeed by looking at Program + ".exe". CreateProcessW
187 // will implicitly add the .exe if we provide a command line without an
188 // executable path, but since we use an explicit executable, we have to add
189 // ".exe" ourselves.
190 SmallString<64> ProgramStorage;
191 if (!sys::fs::exists(Program))
192 Program = Twine(Program + ".exe").toStringRef(ProgramStorage);
193
194 // Windows wants a command line, not an array of args, to pass to the new
195 // process. We have to concatenate them all, while quoting the args that
196 // have embedded spaces (or are empty).
197 auto Result = flattenWindowsCommandLine(Args);
198 if (std::error_code ec = Result.getError()) {
199 SetLastError(ec.value());
200 MakeErrMsg(ErrMsg, std::string("Unable to convert command-line to UTF-16"));
201 return false;
202 }
203 std::wstring Command = *Result;
204
205 // The pointer to the environment block for the new process.
206 std::vector<wchar_t> EnvBlock;
207
208 if (Env) {
209 // An environment block consists of a null-terminated block of
210 // null-terminated strings. Convert the array of environment variables to
211 // an environment block by concatenating them.
212 for (StringRef E : *Env) {
213 SmallVector<wchar_t, MAX_PATH> EnvString;
214 if (std::error_code ec = windows::UTF8ToUTF16(E, EnvString)) {
215 SetLastError(ec.value());
216 MakeErrMsg(ErrMsg, "Unable to convert environment variable to UTF-16");
217 return false;
218 }
219
220 llvm::append_range(EnvBlock, EnvString);
221 EnvBlock.push_back(0);
222 }
223 // Empty environments need to be terminated with two nulls.
224 if (Env->size() == 0)
225 EnvBlock.push_back(0);
226 EnvBlock.push_back(0);
227 }
228
229 // Create a child process.
230 STARTUPINFOW si;
231 memset(&si, 0, sizeof(si));
232 si.cb = sizeof(si);
233 si.hStdInput = INVALID_HANDLE_VALUE;
234 si.hStdOutput = INVALID_HANDLE_VALUE;
235 si.hStdError = INVALID_HANDLE_VALUE;
236
237 if (!Redirects.empty()) {
238 si.dwFlags = STARTF_USESTDHANDLES;
239
240 si.hStdInput = RedirectIO(Redirects[0], 0, ErrMsg);
241 if (si.hStdInput == INVALID_HANDLE_VALUE) {
242 MakeErrMsg(ErrMsg, "can't redirect stdin");
243 return false;
244 }
245 si.hStdOutput = RedirectIO(Redirects[1], 1, ErrMsg);
246 if (si.hStdOutput == INVALID_HANDLE_VALUE) {
247 CloseHandle(si.hStdInput);
248 MakeErrMsg(ErrMsg, "can't redirect stdout");
249 return false;
250 }
251 if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) {
252 // If stdout and stderr should go to the same place, redirect stderr
253 // to the handle already open for stdout.
254 if (!DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
255 GetCurrentProcess(), &si.hStdError, 0, TRUE,
256 DUPLICATE_SAME_ACCESS)) {
257 CloseHandle(si.hStdInput);
258 CloseHandle(si.hStdOutput);
259 MakeErrMsg(ErrMsg, "can't dup stderr to stdout");
260 return false;
261 }
262 } else {
263 // Just redirect stderr
264 si.hStdError = RedirectIO(Redirects[2], 2, ErrMsg);
265 if (si.hStdError == INVALID_HANDLE_VALUE) {
266 CloseHandle(si.hStdInput);
267 CloseHandle(si.hStdOutput);
268 MakeErrMsg(ErrMsg, "can't redirect stderr");
269 return false;
270 }
271 }
272 }
273
274 PROCESS_INFORMATION pi;
275 memset(&pi, 0, sizeof(pi));
276
277 fflush(stdout);
278 fflush(stderr);
279
280 SmallVector<wchar_t, MAX_PATH> ProgramUtf16;
281 if (std::error_code ec = sys::windows::widenPath(Program, ProgramUtf16)) {
282 SetLastError(ec.value());
283 MakeErrMsg(ErrMsg,
284 std::string("Unable to convert application name to UTF-16"));
285 return false;
286 }
287
288 unsigned CreateFlags = CREATE_UNICODE_ENVIRONMENT;
289 if (AffinityMask)
290 CreateFlags |= CREATE_SUSPENDED;
291 if (DetachProcess)
292 CreateFlags |= DETACHED_PROCESS;
293
294 std::vector<wchar_t> CommandUtf16(Command.size() + 1, 0);
295 std::copy(Command.begin(), Command.end(), CommandUtf16.begin());
296 BOOL rc = CreateProcessW(ProgramUtf16.data(), CommandUtf16.data(), 0, 0, TRUE,
297 CreateFlags, EnvBlock.empty() ? 0 : EnvBlock.data(),
298 0, &si, &pi);
299 DWORD err = GetLastError();
300
301 // Regardless of whether the process got created or not, we are done with
302 // the handles we created for it to inherit.
303 CloseHandle(si.hStdInput);
304 CloseHandle(si.hStdOutput);
305 CloseHandle(si.hStdError);
306
307 // Now return an error if the process didn't get created.
308 if (!rc) {
309 SetLastError(err);
310 MakeErrMsg(ErrMsg,
311 std::string("Couldn't execute program '") + Program.str() + "'");
312 return false;
313 }
314
315 PI.Pid = pi.dwProcessId;
316 PI.Process = pi.hProcess;
317
318 // Make sure these get closed no matter what.
319 ScopedCommonHandle hThread(pi.hThread);
320
321 // Assign the process to a job if a memory limit is defined.
322 ScopedJobHandle hJob;
323 if (MemoryLimit != 0) {
324 hJob = CreateJobObjectW(0, 0);
325 bool success = false;
326 if (hJob) {
327 JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli;
328 memset(&jeli, 0, sizeof(jeli));
329 jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
330 jeli.ProcessMemoryLimit = uintptr_t(MemoryLimit) * 1048576;
331 if (SetInformationJobObject(hJob, JobObjectExtendedLimitInformation,
332 &jeli, sizeof(jeli))) {
333 if (AssignProcessToJobObject(hJob, pi.hProcess))
334 success = true;
335 }
336 }
337 if (!success) {
338 SetLastError(GetLastError());
339 MakeErrMsg(ErrMsg, std::string("Unable to set memory limit"));
340 TerminateProcess(pi.hProcess, 1);
341 WaitForSingleObject(pi.hProcess, INFINITE);
342 return false;
343 }
344 }
345
346 // Set the affinity mask
347 if (AffinityMask) {
348 ::SetProcessAffinityMask(pi.hProcess,
349 (DWORD_PTR)AffinityMask->getData().front());
350 ::ResumeThread(pi.hThread);
351 }
352
353 return true;
354}
355
356static bool argNeedsQuotes(StringRef Arg) {
357 if (Arg.empty())
358 return true;
359 return StringRef::npos != Arg.find_first_of("\t \"&\'()*<>\\`^|\n");
360}
361
362static std::string quoteSingleArg(StringRef Arg) {
363 std::string Result;
364 Result.push_back('"');
365
366 while (!Arg.empty()) {
367 size_t FirstNonBackslash = Arg.find_first_not_of('\\');
368 size_t BackslashCount = FirstNonBackslash;
369 if (FirstNonBackslash == StringRef::npos) {
370 // The entire remainder of the argument is backslashes. Escape all of
371 // them and just early out.
372 BackslashCount = Arg.size();
373 Result.append(BackslashCount * 2, '\\');
374 break;
375 }
376
377 if (Arg[FirstNonBackslash] == '\"') {
378 // This is an embedded quote. Escape all preceding backslashes, then
379 // add one additional backslash to escape the quote.
380 Result.append(BackslashCount * 2 + 1, '\\');
381 Result.push_back('\"');
382 } else {
383 // This is just a normal character. Don't escape any of the preceding
384 // backslashes, just append them as they are and then append the
385 // character.
386 Result.append(BackslashCount, '\\');
387 Result.push_back(Arg[FirstNonBackslash]);
388 }
389
390 // Drop all the backslashes, plus the following character.
391 Arg = Arg.drop_front(FirstNonBackslash + 1);
392 }
393
394 Result.push_back('"');
395 return Result;
396}
397
398namespace llvm {
399ErrorOr<std::wstring> sys::flattenWindowsCommandLine(ArrayRef<StringRef> Args) {
400 std::string Command;
401 for (StringRef Arg : Args) {
402 if (argNeedsQuotes(Arg))
403 Command += quoteSingleArg(Arg);
404 else
405 Command += Arg;
406
407 Command.push_back(' ');
408 }
409
411 if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16))
412 return ec;
413
414 return std::wstring(CommandUtf16.begin(), CommandUtf16.end());
415}
416
418 std::optional<unsigned> SecondsToWait,
419 std::string *ErrMsg,
420 std::optional<ProcessStatistics> *ProcStat,
421 bool Polling) {
422 assert(PI.Pid && "invalid pid to wait on, process not started?");
423 assert((PI.Process && PI.Process != INVALID_HANDLE_VALUE) &&
424 "invalid process handle to wait on, process not started?");
425 DWORD milliSecondsToWait = SecondsToWait ? *SecondsToWait * 1000 : INFINITE;
426
427 ProcessInfo WaitResult = PI;
428 if (ProcStat)
429 ProcStat->reset();
430 DWORD WaitStatus = WaitForSingleObject(PI.Process, milliSecondsToWait);
431 if (WaitStatus == WAIT_TIMEOUT) {
432 if (!Polling && *SecondsToWait > 0) {
433 if (!TerminateProcess(PI.Process, 1)) {
434 if (ErrMsg)
435 MakeErrMsg(ErrMsg, "Failed to terminate timed-out program");
436
437 // -2 indicates a crash or timeout as opposed to failure to execute.
438 WaitResult.ReturnCode = -2;
439 CloseHandle(PI.Process);
440 return WaitResult;
441 }
442 WaitForSingleObject(PI.Process, INFINITE);
443 CloseHandle(PI.Process);
444 } else {
445 // Non-blocking wait.
446 return ProcessInfo();
447 }
448 }
449
450 // Get process execution statistics.
451 if (ProcStat) {
452 FILETIME CreationTime, ExitTime, KernelTime, UserTime;
453 PROCESS_MEMORY_COUNTERS MemInfo;
454 if (GetProcessTimes(PI.Process, &CreationTime, &ExitTime, &KernelTime,
455 &UserTime) &&
456 GetProcessMemoryInfo(PI.Process, &MemInfo, sizeof(MemInfo))) {
457 auto UserT = std::chrono::duration_cast<std::chrono::microseconds>(
458 toDuration(UserTime));
459 auto KernelT = std::chrono::duration_cast<std::chrono::microseconds>(
460 toDuration(KernelTime));
461 uint64_t PeakMemory = MemInfo.PeakPagefileUsage / 1024;
462 *ProcStat = ProcessStatistics{UserT + KernelT, UserT, PeakMemory};
463 }
464 }
465
466 // Get its exit status.
468 BOOL rc = GetExitCodeProcess(PI.Process, &status);
469 DWORD err = GetLastError();
470 if (err != ERROR_INVALID_HANDLE)
471 CloseHandle(PI.Process);
472
473 if (!rc) {
474 SetLastError(err);
475 if (ErrMsg)
476 MakeErrMsg(ErrMsg, "Failed getting status for program");
477
478 // -2 indicates a crash or timeout as opposed to failure to execute.
479 WaitResult.ReturnCode = -2;
480 return WaitResult;
481 }
482
483 if (!status)
484 return WaitResult;
485
486 // Pass 10(Warning) and 11(Error) to the callee as negative value.
487 if ((status & 0xBFFF0000U) == 0x80000000U)
488 WaitResult.ReturnCode = static_cast<int>(status);
489 else if (status & 0xFF)
490 WaitResult.ReturnCode = status & 0x7FFFFFFF;
491 else
492 WaitResult.ReturnCode = 1;
493
494 return WaitResult;
495}
496
497std::error_code llvm::sys::ChangeStdinMode(sys::fs::OpenFlags Flags) {
498 if (!(Flags & fs::OF_CRLF))
499 return ChangeStdinToBinary();
500 return std::error_code();
501}
502
503std::error_code llvm::sys::ChangeStdoutMode(sys::fs::OpenFlags Flags) {
504 if (!(Flags & fs::OF_CRLF))
505 return ChangeStdoutToBinary();
506 return std::error_code();
507}
508
509std::error_code sys::ChangeStdinToBinary() {
510 int result = _setmode(_fileno(stdin), _O_BINARY);
511 if (result == -1)
512 return errnoAsErrorCode();
513 return std::error_code();
514}
515
516std::error_code sys::ChangeStdoutToBinary() {
517 int result = _setmode(_fileno(stdout), _O_BINARY);
518 if (result == -1)
519 return errnoAsErrorCode();
520 return std::error_code();
521}
522
523std::error_code
525 WindowsEncodingMethod Encoding) {
526 std::error_code EC;
528 if (EC)
529 return EC;
530
531 if (Encoding == WEM_UTF8) {
532 OS << Contents;
533 } else if (Encoding == WEM_CurrentCodePage) {
534 SmallVector<wchar_t, 1> ArgsUTF16;
535 SmallVector<char, 1> ArgsCurCP;
536
537 if ((EC = windows::UTF8ToUTF16(Contents, ArgsUTF16)))
538 return EC;
539
540 if ((EC = windows::UTF16ToCurCP(ArgsUTF16.data(), ArgsUTF16.size(),
541 ArgsCurCP)))
542 return EC;
543
544 OS.write(ArgsCurCP.data(), ArgsCurCP.size());
545 } else if (Encoding == WEM_UTF16) {
546 SmallVector<wchar_t, 1> ArgsUTF16;
547
548 if ((EC = windows::UTF8ToUTF16(Contents, ArgsUTF16)))
549 return EC;
550
551 // Endianness guessing
552 char BOM[2];
554 memcpy(BOM, &src, 2);
555 OS.write(BOM, 2);
556 OS.write((char *)ArgsUTF16.data(), ArgsUTF16.size() << 1);
557 } else {
558 llvm_unreachable("Unknown encoding");
559 }
560
561 if (OS.has_error())
563
564 return EC;
565}
566
568 ArrayRef<StringRef> Args) {
569 // The documentation on CreateProcessW states that the size of the argument
570 // lpCommandLine must not be greater than 32767 characters, including the
571 // Unicode terminating null character. We use smaller value to reduce risk
572 // of getting invalid command line due to unaccounted factors.
573 static const size_t MaxCommandStringLength = 32000;
575 FullArgs.push_back(Program);
576 FullArgs.append(Args.begin(), Args.end());
577 auto Result = flattenWindowsCommandLine(FullArgs);
578 assert(!Result.getError());
579 return (Result->size() + 1) <= MaxCommandStringLength;
580}
581} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define UNI_UTF16_BYTE_ORDER_MARK_NATIVE
Definition ConvertUTF.h:143
#define rc(i)
#define P(N)
static bool Execute(ProcessInfo &PI, StringRef Program, ArrayRef< StringRef > Args, std::optional< ArrayRef< StringRef > > Env, ArrayRef< std::optional< StringRef > > Redirects, unsigned MemoryLimit, std::string *ErrMsg, BitVector *AffinityMask, bool DetachProcess)
This file contains some functions that are useful when dealing with strings.
static bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix, int errnum=-1)
This function builds an error message into ErrMsg using the prefix string and the Unix error number g...
Definition Unix.h:53
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Represents either an error or a value T.
Definition ErrorOr.h:56
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A raw_ostream that writes to a file descriptor.
A collection of legacy interfaces for querying information about the current executing process.
Definition Process.h:44
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr double pi
Definition MathExtras.h:53
@ OF_CRLF
The file should use a carriage linefeed '\r '.
Definition FileSystem.h:771
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition FileSystem.h:776
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
void make_preferred(SmallVectorImpl< char > &path, Style style=Style::native)
For Windows path styles, convert path to use the preferred path separators.
Definition Path.h:278
LLVM_ABI std::error_code ChangeStdoutMode(fs::OpenFlags Flags)
std::chrono::nanoseconds toDuration(FILETIME Time)
LLVM_ABI std::error_code ChangeStdinMode(fs::OpenFlags Flags)
LLVM_ABI std::error_code ChangeStdinToBinary()
LLVM_ABI bool commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef< StringRef > Args)
Return true if the given arguments fit within system-specific argument length limits.
LLVM_ABI std::error_code writeFileWithEncoding(StringRef FileName, StringRef Contents, WindowsEncodingMethod Encoding=WEM_UTF8)
Saves the UTF8-encoded contents string into the file FileName using a specific encoding.
WindowsEncodingMethod
File encoding options when writing contents that a non-UTF8 tool will read (on Windows systems).
Definition Program.h:173
@ WEM_CurrentCodePage
Definition Program.h:177
@ WEM_UTF16
Definition Program.h:178
@ WEM_UTF8
UTF-8 is the LLVM native encoding, being the same as "do not performencoding conversion".
Definition Program.h:176
LLVM_ABI std::error_code ChangeStdoutToBinary()
LLVM_ABI ProcessInfo Wait(const ProcessInfo &PI, std::optional< unsigned > SecondsToWait, std::string *ErrMsg=nullptr, std::optional< ProcessStatistics > *ProcStat=nullptr, bool Polling=false)
This function waits for the process specified by PI to finish.
This is an optimization pass for GlobalISel generic memory operations.
ScopedHandle< CommonHandleTraits > ScopedCommonHandle
std::error_code make_error_code(BitcodeError E)
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2116
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
ScopedHandle< JobHandleTraits > ScopedJobHandle
LLVM_ABI void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters,...
@ io_error
Definition Errc.h:58
LLVM_ABI bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix)
LLVM_ABI std::error_code mapWindowsError(unsigned EV)
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Definition Error.h:1240
LogicalResult success(bool IsSuccess=true)
Utility function to generate a LogicalResult.
This struct encapsulates information about a process.
Definition Program.h:47
This struct encapsulates information about a process execution.
Definition Program.h:60