LLVM 24.0.0git
Process.inc
Go to the documentation of this file.
1//===- Win32/Process.cpp - Win32 Process 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 Process class.
10//
11//===----------------------------------------------------------------------===//
12
19#include <malloc.h>
20#include <optional>
21
22// The Windows.h header must be after LLVM and standard headers.
24
25#include <direct.h>
26#include <io.h>
27#include <psapi.h>
28#include <shellapi.h>
29
30#if !defined(__MINGW32__)
31#pragma comment(lib, "psapi.lib")
32#if !LLVM_WINDOWS_RESTRICTED_APIS
33#pragma comment(lib, "shell32.lib")
34#endif
35#endif
36
37//===----------------------------------------------------------------------===//
38//=== WARNING: Implementation here must contain only Win32 specific code
39//=== and must not be UNIX code
40//===----------------------------------------------------------------------===//
41
42using namespace llvm;
43
45 static_assert(sizeof(Pid) >= sizeof(DWORD),
46 "Process::Pid should be big enough to store DWORD");
47 return Pid(::GetCurrentProcessId());
48}
49
50// This function retrieves the page size using GetNativeSystemInfo() and is
51// present solely so it can be called once to initialize the self_process member
52// below.
53static unsigned computePageSize() {
54 // GetNativeSystemInfo() provides the physical page size which may differ
55 // from GetSystemInfo() in 32-bit applications running under WOW64.
56 SYSTEM_INFO info;
57 GetNativeSystemInfo(&info);
58 // FIXME: FileOffset in MapViewOfFile() should be aligned to not dwPageSize,
59 // but dwAllocationGranularity.
60 return static_cast<unsigned>(info.dwPageSize);
61}
62
63Expected<unsigned> Process::getPageSize() {
64 static unsigned Ret = computePageSize();
65 return Ret;
66}
67
69 _HEAPINFO hinfo;
70 hinfo._pentry = NULL;
71
72 size_t size = 0;
73
74 while (_heapwalk(&hinfo) == _HEAPOK)
75 size += hinfo._size;
76
77 return size;
78}
79
81 std::chrono::nanoseconds &user_time,
82 std::chrono::nanoseconds &sys_time) {
83 elapsed = std::chrono::system_clock::now();
84 ;
85
86 FILETIME ProcCreate, ProcExit, KernelTime, UserTime;
87 if (GetProcessTimes(GetCurrentProcess(), &ProcCreate, &ProcExit, &KernelTime,
88 &UserTime) == 0)
89 return;
90
91 user_time = toDuration(UserTime);
92 sys_time = toDuration(KernelTime);
93}
94
95// Some LLVM programs such as llvm-reduce produce core files as a normal part of
96// their operation. To prevent the disk from filling up, this configuration item
97// does what's necessary to prevent their generation.
99 // Windows does have the concept of core files, called minidumps. However,
100 // disabling minidumps for a particular application extends past the lifetime
101 // of that application, which is the incorrect behavior for this API.
102 // Additionally, the APIs require elevated privileges to disable and re-
103 // enable minidumps, which makes this untenable. For more information, see
104 // WerAddExcludedApplication and WerRemoveExcludedApplication (Vista and
105 // later).
106 //
107 // Windows also has modal pop-up message boxes. As this method is used by
108 // llvm-reduce, preventing these pop-ups is additionally important.
109 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
110 SEM_NOOPENFILEERRORBOX);
111
112 coreFilesPrevented = true;
113}
114
115/// Returns the environment variable \arg Name's value as a string encoded in
116/// UTF-8. \arg Name is assumed to be in UTF-8 encoding.
117std::optional<std::string> Process::GetEnv(StringRef Name) {
118 // Convert the argument to UTF-16 to pass it to _wgetenv().
120 if (windows::UTF8ToUTF16(Name, NameUTF16))
121 return std::nullopt;
122
123 // Environment variable can be encoded in non-UTF8 encoding, and there's no
124 // way to know what the encoding is. The only reliable way to look up
125 // multibyte environment variable is to use GetEnvironmentVariableW().
127 size_t Size = MAX_PATH;
128 do {
130 SetLastError(NO_ERROR);
131 Size = GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.size());
132 if (Size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
133 return std::nullopt;
134
135 // Try again with larger buffer.
136 } while (Size > Buf.size());
137 Buf.truncate(Size);
138
139 // Convert the result from UTF-16 to UTF-8.
141 if (windows::UTF16ToUTF8(Buf.data(), Size, Res))
142 return std::nullopt;
143 return std::string(Res.data());
144}
145
146/// Perform wildcard expansion of Arg, or just push it into Args if it doesn't
147/// have wildcards or doesn't match any files.
148static std::error_code WildcardExpand(StringRef Arg,
150 StringSaver &Saver) {
151 std::error_code EC;
152
153 // Don't expand Arg if it does not contain any wildcard characters. This is
154 // the common case. Also don't wildcard expand /?. Always treat it as an
155 // option. Paths that start with \\?\ are absolute paths, and aren't
156 // expected to be used with wildcard expressions.
157 if (Arg.find_first_of("*?") == StringRef::npos || Arg == "/?" ||
158 Arg == "-?" || Arg.starts_with("\\\\?\\")) {
159 Args.push_back(Arg.data());
160 return EC;
161 }
162
163 // Convert back to UTF-16 so we can call FindFirstFileW.
165 EC = windows::UTF8ToUTF16(Arg, ArgW);
166 if (EC)
167 return EC;
168
169 // Search for matching files.
170 // FIXME: This assumes the wildcard is only in the file name and not in the
171 // directory portion of the file path. For example, it doesn't handle
172 // "*\foo.c" nor "s?c\bar.cpp".
173 WIN32_FIND_DATAW FileData;
174 HANDLE FindHandle = ::FindFirstFileExW(ArgW.data(), FindExInfoBasic,
175 &FileData, FindExSearchNameMatch, NULL,
176 FIND_FIRST_EX_LARGE_FETCH);
177 if (FindHandle == INVALID_HANDLE_VALUE) {
178 Args.push_back(Arg.data());
179 return EC;
180 }
181
182 // Extract any directory part of the argument.
183 SmallString<MAX_PATH> Dir = Arg;
185 const int DirSize = Dir.size();
186
187 do {
188 SmallString<MAX_PATH> FileName;
189 EC = windows::UTF16ToUTF8(FileData.cFileName, wcslen(FileData.cFileName),
190 FileName);
191 if (EC)
192 break;
193
194 // Append FileName to Dir, and remove it afterwards.
195 llvm::sys::path::append(Dir, FileName);
196 Args.push_back(Saver.save(Dir.str()).data());
197 Dir.resize(DirSize);
198 } while (FindNextFileW(FindHandle, &FileData));
199
200 FindClose(FindHandle);
201 return EC;
202}
203
204static std::error_code GetExecutableName(SmallVectorImpl<char> &Filename) {
205 // The first argument may contain just the name of the executable (e.g.,
206 // "clang") rather than the full path, so swap it with the full path.
207 wchar_t ModuleName[MAX_PATH];
208 size_t Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
209 if (Length == 0 || Length == MAX_PATH) {
210 return mapWindowsError(GetLastError());
211 }
212
213 // If the first argument is a shortened (8.3) name (which is possible even
214 // if we got the module name), the driver will have trouble distinguishing it
215 // (e.g., clang.exe v. clang++.exe), so expand it now.
216 Length = GetLongPathNameW(ModuleName, ModuleName, MAX_PATH);
217 if (Length == 0)
218 return mapWindowsError(GetLastError());
219 if (Length > MAX_PATH) {
220 // We're not going to try to deal with paths longer than MAX_PATH, so we'll
221 // treat this as an error. GetLastError() returns ERROR_SUCCESS, which
222 // isn't useful, so we'll hardcode an appropriate error value.
223 return mapWindowsError(ERROR_INSUFFICIENT_BUFFER);
224 }
225
226 std::error_code EC = windows::UTF16ToUTF8(ModuleName, Length, Filename);
227 if (EC)
228 return EC;
229
230 // Make a copy of the filename since assign makes the StringRef invalid.
231 std::string Base = sys::path::filename(Filename.data()).str();
232 Filename.assign(Base.begin(), Base.end());
233 return std::error_code();
234}
235
236std::error_code
239 const wchar_t *CmdW = GetCommandLineW();
240 assert(CmdW);
241 std::error_code EC;
243 EC = windows::UTF16ToUTF8(CmdW, wcslen(CmdW), Cmd);
244 if (EC)
245 return EC;
246
248 StringSaver Saver(Alloc);
249 cl::TokenizeWindowsCommandLineFull(Cmd, Saver, TmpArgs, /*MarkEOLs=*/false);
250
251 for (const char *Arg : TmpArgs) {
252 EC = WildcardExpand(Arg, Args, Saver);
253 if (EC)
254 return EC;
255 }
256
257 if (Args.size() == 0)
258 return std::make_error_code(std::errc::invalid_argument);
259
260 SmallVector<char, MAX_PATH> Arg0(Args[0], Args[0] + strlen(Args[0]));
263 EC = GetExecutableName(Filename);
264 if (EC)
265 return EC;
268 Args[0] = Saver.save(Arg0).data();
269 return std::error_code();
270}
271
273 return std::error_code();
274}
275
276std::error_code Process::SafelyCloseFileDescriptor(int FD) {
277 if (::close(FD) < 0)
278 return errnoAsErrorCode();
279 return std::error_code();
280}
281
282bool Process::StandardInIsUserInput() { return FileDescriptorIsDisplayed(0); }
283
284bool Process::StandardOutIsDisplayed() { return FileDescriptorIsDisplayed(1); }
285
286bool Process::StandardErrIsDisplayed() { return FileDescriptorIsDisplayed(2); }
287
289 DWORD Mode; // Unused
290 return (GetConsoleMode((HANDLE)_get_osfhandle(fd), &Mode) != 0);
291}
292
294 unsigned Columns = 0;
295 CONSOLE_SCREEN_BUFFER_INFO csbi;
296 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
297 Columns = csbi.dwSize.X;
298 return Columns;
299}
300
302 unsigned Columns = 0;
303 CONSOLE_SCREEN_BUFFER_INFO csbi;
304 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi))
305 Columns = csbi.dwSize.X;
306 return Columns;
307}
308
309// The terminal always has colors.
311 return FileDescriptorIsDisplayed(fd);
312}
313
314bool Process::StandardOutHasColors() { return FileDescriptorHasColors(1); }
315
316bool Process::StandardErrHasColors() { return FileDescriptorHasColors(2); }
317
318static bool UseANSI = false;
319void Process::UseANSIEscapeCodes(bool enable) {
320#if defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
321 if (enable) {
322 HANDLE Console = GetStdHandle(STD_OUTPUT_HANDLE);
323 DWORD Mode;
324 GetConsoleMode(Console, &Mode);
325 Mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
326 SetConsoleMode(Console, Mode);
327 }
328#endif
329 UseANSI = enable;
330}
331
332namespace {
333class DefaultColors {
334private:
335 WORD defaultColor;
336
337public:
338 DefaultColors() : defaultColor(GetCurrentColor()) {}
339 static unsigned GetCurrentColor() {
340 CONSOLE_SCREEN_BUFFER_INFO csbi;
341 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
342 return csbi.wAttributes;
343 return 0;
344 }
345 WORD operator()() const { return defaultColor; }
346};
347
348DefaultColors defaultColors;
349
350WORD fg_color(WORD color) {
351 return color & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY |
352 FOREGROUND_RED);
353}
354
355WORD bg_color(WORD color) {
356 return color & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY |
357 BACKGROUND_RED);
358}
359} // namespace
360
361bool Process::ColorNeedsFlush() { return !UseANSI; }
362
363const char *Process::OutputBold(bool bg) {
364 if (UseANSI)
365 return "\033[1m";
366
367 WORD colors = DefaultColors::GetCurrentColor();
368 if (bg)
369 colors |= BACKGROUND_INTENSITY;
370 else
371 colors |= FOREGROUND_INTENSITY;
372 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
373 return 0;
374}
375
376const char *Process::OutputColor(char code, bool bold, bool bg) {
377 if (UseANSI)
378 return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
379
380 WORD current = DefaultColors::GetCurrentColor();
381 WORD colors;
382 if (bg) {
383 colors = ((code & 1) ? BACKGROUND_RED : 0) |
384 ((code & 2) ? BACKGROUND_GREEN : 0) |
385 ((code & 4) ? BACKGROUND_BLUE : 0);
386 if (bold)
387 colors |= BACKGROUND_INTENSITY;
388 colors |= fg_color(current);
389 } else {
390 colors = ((code & 1) ? FOREGROUND_RED : 0) |
391 ((code & 2) ? FOREGROUND_GREEN : 0) |
392 ((code & 4) ? FOREGROUND_BLUE : 0);
393 if (bold)
394 colors |= FOREGROUND_INTENSITY;
395 colors |= bg_color(current);
396 }
397 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
398 return 0;
399}
400
401static WORD GetConsoleTextAttribute(HANDLE hConsoleOutput) {
402 CONSOLE_SCREEN_BUFFER_INFO info;
403 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
404 return info.wAttributes;
405}
406
407const char *Process::OutputReverse() {
408 if (UseANSI)
409 return "\033[7m";
410
411 const WORD attributes =
412 GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE));
413
414 const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
415 FOREGROUND_RED | FOREGROUND_INTENSITY;
416 const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
417 BACKGROUND_RED | BACKGROUND_INTENSITY;
418 const WORD color_mask = foreground_mask | background_mask;
419
420 WORD new_attributes =
421 ((attributes & FOREGROUND_BLUE) ? BACKGROUND_BLUE : 0) |
422 ((attributes & FOREGROUND_GREEN) ? BACKGROUND_GREEN : 0) |
423 ((attributes & FOREGROUND_RED) ? BACKGROUND_RED : 0) |
424 ((attributes & FOREGROUND_INTENSITY) ? BACKGROUND_INTENSITY : 0) |
425 ((attributes & BACKGROUND_BLUE) ? FOREGROUND_BLUE : 0) |
426 ((attributes & BACKGROUND_GREEN) ? FOREGROUND_GREEN : 0) |
427 ((attributes & BACKGROUND_RED) ? FOREGROUND_RED : 0) |
428 ((attributes & BACKGROUND_INTENSITY) ? FOREGROUND_INTENSITY : 0) | 0;
429 new_attributes = (attributes & ~color_mask) | (new_attributes & color_mask);
430
431 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), new_attributes);
432 return 0;
433}
434
435const char *Process::ResetColor() {
436 if (UseANSI)
437 return "\033[0m";
438 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
439 return 0;
440}
441
442static unsigned GetRandomNumberSeed() {
443 // Generate a random number seed from the millisecond-resolution Windows
444 // system clock and the current process id.
445 FILETIME Time;
446 GetSystemTimeAsFileTime(&Time);
447 DWORD Pid = GetCurrentProcessId();
448 return hash_combine(Time.dwHighDateTime, Time.dwLowDateTime, Pid);
449}
450
451static unsigned GetPseudoRandomNumber() {
452 // Arrange to call srand once when this function is first used, and
453 // otherwise (if GetRandomNumber always succeeds in using
454 // CryptGenRandom) don't bother at all.
455 static int x = (static_cast<void>(::srand(GetRandomNumberSeed())), 0);
456 (void)x;
457 return ::rand();
458}
459
460unsigned Process::GetRandomNumber() {
461 // Try to use CryptGenRandom.
462 HCRYPTPROV HCPC;
463 if (::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
464 CRYPT_VERIFYCONTEXT)) {
465 ScopedCryptContext CryptoProvider(HCPC);
466 unsigned Ret;
467 if (::CryptGenRandom(CryptoProvider, sizeof(Ret),
468 reinterpret_cast<BYTE *>(&Ret)))
469 return Ret;
470 }
471
472 // If that fails, fall back to pseudo-random numbers.
473 return GetPseudoRandomNumber();
474}
475
476typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
477#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
478
479static RTL_OSVERSIONINFOEXW GetWindowsVer() {
480 auto getVer = []() -> RTL_OSVERSIONINFOEXW {
481 HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
482 assert(hMod);
483
484 auto getVer =
485 (RtlGetVersionPtr)(void *)::GetProcAddress(hMod, "RtlGetVersion");
486 assert(getVer);
487
488 RTL_OSVERSIONINFOEXW info{};
489 info.dwOSVersionInfoSize = sizeof(info);
490 NTSTATUS r = getVer((PRTL_OSVERSIONINFOW)&info);
491 (void)r;
492 assert(r == STATUS_SUCCESS);
493
494 return info;
495 };
496 static RTL_OSVERSIONINFOEXW info = getVer();
497 return info;
498}
499
501 RTL_OSVERSIONINFOEXW info = GetWindowsVer();
502 return llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0,
503 info.dwBuildNumber);
504}
505
507 // Windows 8 is version 6.2, service pack 0.
508 return GetWindowsOSVersion() >= llvm::VersionTuple(6, 2, 0, 0);
509}
510
512 RTL_OSVERSIONINFOEXW info = GetWindowsVer();
513 auto ver = llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0,
514 info.dwBuildNumber);
515
516 // Windows Server 2022
517 if (info.wProductType == VER_NT_SERVER)
518 return ver >= llvm::VersionTuple(10, 0, 0, 20348);
519
520 // Windows 11
521 return ver >= llvm::VersionTuple(10, 0, 0, 22000);
522}
523
524[[noreturn]] void Process::ExitNoCleanup(int RetCode) {
525 TerminateProcess(GetCurrentProcess(), RetCode);
526 llvm_unreachable("TerminateProcess doesn't return");
527}
528
529namespace llvm::sys::windows {
530HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
531 // Ensure we load indeed a module from system32 path.
532 // As per GetModuleHandle documentation:
533 // "If lpModuleName does not include a path and there is more than one loaded
534 // module with the same base name and extension, you cannot predict which
535 // module handle will be returned.". This mitigates
536 // https://learn.microsoft.com/en-us/security-updates/securityadvisories/2010/2269637
538 size_t Size = MAX_PATH;
539 do {
541 SetLastError(NO_ERROR);
542 Size = ::GetSystemDirectoryW(Buf.data(), Buf.size());
543 if (Size == 0)
544 return NULL;
545
546 // Try again with larger buffer.
547 } while (Size > Buf.size());
548
549 Buf.truncate(Size);
550 Buf.push_back(L'\\');
551 Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
552 Buf.push_back(0);
553
554 return ::GetModuleHandleW(Buf.data());
555}
556} // namespace llvm::sys::windows
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
lazy value info
static constexpr StringLiteral Filename
static bool coreFilesPrevented
Definition Process.cpp:106
static const char colorcodes[2][2][16][11]
Definition Process.cpp:98
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void truncate(size_type N)
Like resize, but requires that N is less than size().
void resize(size_type N)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition StringRef.h:388
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition StringSaver.h:22
StringRef save(const char *S)
Definition StringSaver.h:31
Represents a version number in the form major[.minor[.subminor[.build]]].
static LLVM_ABI void UseANSIEscapeCodes(bool enable)
Enables or disables whether ANSI escape sequences are used to output colors.
static LLVM_ABI std::error_code SafelyCloseFileDescriptor(int FD)
static LLVM_ABI void GetTimeUsage(TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, std::chrono::nanoseconds &sys_time)
This static function will set user_time to the amount of CPU time spent in user (non-kernel) mode and...
static LLVM_ABI std::error_code FixupStandardFileDescriptors()
static LLVM_ABI Pid getProcessId()
Get the process's identifier.
static LLVM_ABI size_t GetMallocUsage()
Return process memory usage.
static LLVM_ABI bool ColorNeedsFlush()
Whether changing colors requires the output to be flushed.
static LLVM_ABI const char * ResetColor()
Resets the terminals colors, or returns an escape sequence to do so.
static LLVM_ABI unsigned GetRandomNumber()
Get the result of a process wide random number generator.
static LLVM_ABI bool FileDescriptorIsDisplayed(int fd)
This function determines if the given file descriptor is connected to a "tty" or "console" window.
static LLVM_ABI Expected< unsigned > getPageSize()
Get the process's page size.
static LLVM_ABI const char * OutputColor(char c, bool bold, bool bg)
This function returns the colorcode escape sequences.
static LLVM_ABI const char * OutputBold(bool bg)
Same as OutputColor, but only enables the bold attribute.
static LLVM_ABI unsigned StandardErrColumns()
This function determines the number of columns in the window if standard error is connected to a "tty...
static LLVM_ABI std::optional< std::string > GetEnv(StringRef name)
static LLVM_ABI bool FileDescriptorHasColors(int fd)
This function determines if the given file descriptor is displayd and supports colors.
static LLVM_ABI bool StandardInIsUserInput()
This function determines if the standard input is connected directly to a user's input (keyboard prob...
static LLVM_ABI void PreventCoreFiles()
This function makes the necessary calls to the operating system to prevent core files or any other ki...
static LLVM_ABI bool StandardErrHasColors()
This function determines whether the terminal connected to standard error supports colors.
static LLVM_ABI const char * OutputReverse()
This function returns the escape sequence to reverse forground and background colors.
static LLVM_ABI bool StandardErrIsDisplayed()
This function determines if the standard error is connected to a "tty" or "console" window.
static LLVM_ABI bool StandardOutHasColors()
This function determines whether the terminal connected to standard output supports colors.
static LLVM_ABI unsigned StandardOutColumns()
This function determines the number of columns in the window if standard output is connected to a "tt...
static LLVM_ABI bool StandardOutIsDisplayed()
This function determines if the standard output is connected to a "tty" or "console" window.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
LLVM_ABI void TokenizeWindowsCommandLineFull(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows full command line, including command name at the start.
LLVM_ABI void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition Path.cpp:485
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:287
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:594
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition Path.cpp:467
LLVM_ABI HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName)
Retrieves the handle to a in-memory system module such as ntdll.dll, while ensuring we're not retriev...
LLVM_ABI std::error_code GetCommandLineArguments(SmallVectorImpl< const char * > &Args, BumpPtrAllocator &Alloc)
std::chrono::nanoseconds toDuration(FILETIME Time)
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition Chrono.h:34
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:577
LLVM_ABI bool RunningWindows8OrGreater()
Determines if the program is running on Windows 8 or newer.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
ScopedHandle< CryptContextTraits > ScopedCryptContext
LLVM_ABI llvm::VersionTuple GetWindowsOSVersion()
Returns the Windows version as Major.Minor.0.BuildNumber.
LLVM_ABI bool RunningWindows11OrGreater()
Determines if the program is running on Windows 11 or Windows Server 2022.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI std::error_code mapWindowsError(unsigned EV)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:307
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Definition Error.h:1256
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391