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 = FindFirstFileW(ArgW.data(), &FileData);
175 if (FindHandle == INVALID_HANDLE_VALUE) {
176 Args.push_back(Arg.data());
177 return EC;
178 }
179
180 // Extract any directory part of the argument.
181 SmallString<MAX_PATH> Dir = Arg;
183 const int DirSize = Dir.size();
184
185 do {
186 SmallString<MAX_PATH> FileName;
187 EC = windows::UTF16ToUTF8(FileData.cFileName, wcslen(FileData.cFileName),
188 FileName);
189 if (EC)
190 break;
191
192 // Append FileName to Dir, and remove it afterwards.
193 llvm::sys::path::append(Dir, FileName);
194 Args.push_back(Saver.save(Dir.str()).data());
195 Dir.resize(DirSize);
196 } while (FindNextFileW(FindHandle, &FileData));
197
198 FindClose(FindHandle);
199 return EC;
200}
201
202static std::error_code GetExecutableName(SmallVectorImpl<char> &Filename) {
203 // The first argument may contain just the name of the executable (e.g.,
204 // "clang") rather than the full path, so swap it with the full path.
205 wchar_t ModuleName[MAX_PATH];
206 size_t Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
207 if (Length == 0 || Length == MAX_PATH) {
208 return mapWindowsError(GetLastError());
209 }
210
211 // If the first argument is a shortened (8.3) name (which is possible even
212 // if we got the module name), the driver will have trouble distinguishing it
213 // (e.g., clang.exe v. clang++.exe), so expand it now.
214 Length = GetLongPathNameW(ModuleName, ModuleName, MAX_PATH);
215 if (Length == 0)
216 return mapWindowsError(GetLastError());
217 if (Length > MAX_PATH) {
218 // We're not going to try to deal with paths longer than MAX_PATH, so we'll
219 // treat this as an error. GetLastError() returns ERROR_SUCCESS, which
220 // isn't useful, so we'll hardcode an appropriate error value.
221 return mapWindowsError(ERROR_INSUFFICIENT_BUFFER);
222 }
223
224 std::error_code EC = windows::UTF16ToUTF8(ModuleName, Length, Filename);
225 if (EC)
226 return EC;
227
228 // Make a copy of the filename since assign makes the StringRef invalid.
229 std::string Base = sys::path::filename(Filename.data()).str();
230 Filename.assign(Base.begin(), Base.end());
231 return std::error_code();
232}
233
234std::error_code
237 const wchar_t *CmdW = GetCommandLineW();
238 assert(CmdW);
239 std::error_code EC;
241 EC = windows::UTF16ToUTF8(CmdW, wcslen(CmdW), Cmd);
242 if (EC)
243 return EC;
244
246 StringSaver Saver(Alloc);
247 cl::TokenizeWindowsCommandLineFull(Cmd, Saver, TmpArgs, /*MarkEOLs=*/false);
248
249 for (const char *Arg : TmpArgs) {
250 EC = WildcardExpand(Arg, Args, Saver);
251 if (EC)
252 return EC;
253 }
254
255 if (Args.size() == 0)
256 return std::make_error_code(std::errc::invalid_argument);
257
258 SmallVector<char, MAX_PATH> Arg0(Args[0], Args[0] + strlen(Args[0]));
261 EC = GetExecutableName(Filename);
262 if (EC)
263 return EC;
266 Args[0] = Saver.save(Arg0).data();
267 return std::error_code();
268}
269
271 return std::error_code();
272}
273
274std::error_code Process::SafelyCloseFileDescriptor(int FD) {
275 if (::close(FD) < 0)
276 return errnoAsErrorCode();
277 return std::error_code();
278}
279
280bool Process::StandardInIsUserInput() { return FileDescriptorIsDisplayed(0); }
281
282bool Process::StandardOutIsDisplayed() { return FileDescriptorIsDisplayed(1); }
283
284bool Process::StandardErrIsDisplayed() { return FileDescriptorIsDisplayed(2); }
285
287 DWORD Mode; // Unused
288 return (GetConsoleMode((HANDLE)_get_osfhandle(fd), &Mode) != 0);
289}
290
292 unsigned Columns = 0;
293 CONSOLE_SCREEN_BUFFER_INFO csbi;
294 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
295 Columns = csbi.dwSize.X;
296 return Columns;
297}
298
300 unsigned Columns = 0;
301 CONSOLE_SCREEN_BUFFER_INFO csbi;
302 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi))
303 Columns = csbi.dwSize.X;
304 return Columns;
305}
306
307// The terminal always has colors.
309 return FileDescriptorIsDisplayed(fd);
310}
311
312bool Process::StandardOutHasColors() { return FileDescriptorHasColors(1); }
313
314bool Process::StandardErrHasColors() { return FileDescriptorHasColors(2); }
315
316static bool UseANSI = false;
317void Process::UseANSIEscapeCodes(bool enable) {
318#if defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
319 if (enable) {
320 HANDLE Console = GetStdHandle(STD_OUTPUT_HANDLE);
321 DWORD Mode;
322 GetConsoleMode(Console, &Mode);
323 Mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
324 SetConsoleMode(Console, Mode);
325 }
326#endif
327 UseANSI = enable;
328}
329
330namespace {
331class DefaultColors {
332private:
333 WORD defaultColor;
334
335public:
336 DefaultColors() : defaultColor(GetCurrentColor()) {}
337 static unsigned GetCurrentColor() {
338 CONSOLE_SCREEN_BUFFER_INFO csbi;
339 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
340 return csbi.wAttributes;
341 return 0;
342 }
343 WORD operator()() const { return defaultColor; }
344};
345
346DefaultColors defaultColors;
347
348WORD fg_color(WORD color) {
349 return color & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY |
350 FOREGROUND_RED);
351}
352
353WORD bg_color(WORD color) {
354 return color & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY |
355 BACKGROUND_RED);
356}
357} // namespace
358
359bool Process::ColorNeedsFlush() { return !UseANSI; }
360
361const char *Process::OutputBold(bool bg) {
362 if (UseANSI)
363 return "\033[1m";
364
365 WORD colors = DefaultColors::GetCurrentColor();
366 if (bg)
367 colors |= BACKGROUND_INTENSITY;
368 else
369 colors |= FOREGROUND_INTENSITY;
370 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
371 return 0;
372}
373
374const char *Process::OutputColor(char code, bool bold, bool bg) {
375 if (UseANSI)
376 return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
377
378 WORD current = DefaultColors::GetCurrentColor();
379 WORD colors;
380 if (bg) {
381 colors = ((code & 1) ? BACKGROUND_RED : 0) |
382 ((code & 2) ? BACKGROUND_GREEN : 0) |
383 ((code & 4) ? BACKGROUND_BLUE : 0);
384 if (bold)
385 colors |= BACKGROUND_INTENSITY;
386 colors |= fg_color(current);
387 } else {
388 colors = ((code & 1) ? FOREGROUND_RED : 0) |
389 ((code & 2) ? FOREGROUND_GREEN : 0) |
390 ((code & 4) ? FOREGROUND_BLUE : 0);
391 if (bold)
392 colors |= FOREGROUND_INTENSITY;
393 colors |= bg_color(current);
394 }
395 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
396 return 0;
397}
398
399static WORD GetConsoleTextAttribute(HANDLE hConsoleOutput) {
400 CONSOLE_SCREEN_BUFFER_INFO info;
401 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
402 return info.wAttributes;
403}
404
405const char *Process::OutputReverse() {
406 if (UseANSI)
407 return "\033[7m";
408
409 const WORD attributes =
410 GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE));
411
412 const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
413 FOREGROUND_RED | FOREGROUND_INTENSITY;
414 const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
415 BACKGROUND_RED | BACKGROUND_INTENSITY;
416 const WORD color_mask = foreground_mask | background_mask;
417
418 WORD new_attributes =
419 ((attributes & FOREGROUND_BLUE) ? BACKGROUND_BLUE : 0) |
420 ((attributes & FOREGROUND_GREEN) ? BACKGROUND_GREEN : 0) |
421 ((attributes & FOREGROUND_RED) ? BACKGROUND_RED : 0) |
422 ((attributes & FOREGROUND_INTENSITY) ? BACKGROUND_INTENSITY : 0) |
423 ((attributes & BACKGROUND_BLUE) ? FOREGROUND_BLUE : 0) |
424 ((attributes & BACKGROUND_GREEN) ? FOREGROUND_GREEN : 0) |
425 ((attributes & BACKGROUND_RED) ? FOREGROUND_RED : 0) |
426 ((attributes & BACKGROUND_INTENSITY) ? FOREGROUND_INTENSITY : 0) | 0;
427 new_attributes = (attributes & ~color_mask) | (new_attributes & color_mask);
428
429 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), new_attributes);
430 return 0;
431}
432
433const char *Process::ResetColor() {
434 if (UseANSI)
435 return "\033[0m";
436 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
437 return 0;
438}
439
440static unsigned GetRandomNumberSeed() {
441 // Generate a random number seed from the millisecond-resolution Windows
442 // system clock and the current process id.
443 FILETIME Time;
444 GetSystemTimeAsFileTime(&Time);
445 DWORD Pid = GetCurrentProcessId();
446 return hash_combine(Time.dwHighDateTime, Time.dwLowDateTime, Pid);
447}
448
449static unsigned GetPseudoRandomNumber() {
450 // Arrange to call srand once when this function is first used, and
451 // otherwise (if GetRandomNumber always succeeds in using
452 // CryptGenRandom) don't bother at all.
453 static int x = (static_cast<void>(::srand(GetRandomNumberSeed())), 0);
454 (void)x;
455 return ::rand();
456}
457
458unsigned Process::GetRandomNumber() {
459 // Try to use CryptGenRandom.
460 HCRYPTPROV HCPC;
461 if (::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
462 CRYPT_VERIFYCONTEXT)) {
463 ScopedCryptContext CryptoProvider(HCPC);
464 unsigned Ret;
465 if (::CryptGenRandom(CryptoProvider, sizeof(Ret),
466 reinterpret_cast<BYTE *>(&Ret)))
467 return Ret;
468 }
469
470 // If that fails, fall back to pseudo-random numbers.
471 return GetPseudoRandomNumber();
472}
473
474typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
475#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
476
477static RTL_OSVERSIONINFOEXW GetWindowsVer() {
478 auto getVer = []() -> RTL_OSVERSIONINFOEXW {
479 HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
480 assert(hMod);
481
482 auto getVer =
483 (RtlGetVersionPtr)(void *)::GetProcAddress(hMod, "RtlGetVersion");
484 assert(getVer);
485
486 RTL_OSVERSIONINFOEXW info{};
487 info.dwOSVersionInfoSize = sizeof(info);
488 NTSTATUS r = getVer((PRTL_OSVERSIONINFOW)&info);
489 (void)r;
490 assert(r == STATUS_SUCCESS);
491
492 return info;
493 };
494 static RTL_OSVERSIONINFOEXW info = getVer();
495 return info;
496}
497
499 RTL_OSVERSIONINFOEXW info = GetWindowsVer();
500 return llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0,
501 info.dwBuildNumber);
502}
503
505 // Windows 8 is version 6.2, service pack 0.
506 return GetWindowsOSVersion() >= llvm::VersionTuple(6, 2, 0, 0);
507}
508
510 RTL_OSVERSIONINFOEXW info = GetWindowsVer();
511 auto ver = llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0,
512 info.dwBuildNumber);
513
514 // Windows Server 2022
515 if (info.wProductType == VER_NT_SERVER)
516 return ver >= llvm::VersionTuple(10, 0, 0, 20348);
517
518 // Windows 11
519 return ver >= llvm::VersionTuple(10, 0, 0, 22000);
520}
521
522[[noreturn]] void Process::ExitNoCleanup(int RetCode) {
523 TerminateProcess(GetCurrentProcess(), RetCode);
524 llvm_unreachable("TerminateProcess doesn't return");
525}
526
527namespace llvm::sys::windows {
528HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
529 // Ensure we load indeed a module from system32 path.
530 // As per GetModuleHandle documentation:
531 // "If lpModuleName does not include a path and there is more than one loaded
532 // module with the same base name and extension, you cannot predict which
533 // module handle will be returned.". This mitigates
534 // https://learn.microsoft.com/en-us/security-updates/securityadvisories/2010/2269637
536 size_t Size = MAX_PATH;
537 do {
539 SetLastError(NO_ERROR);
540 Size = ::GetSystemDirectoryW(Buf.data(), Buf.size());
541 if (Size == 0)
542 return NULL;
543
544 // Try again with larger buffer.
545 } while (Size > Buf.size());
546
547 Buf.truncate(Size);
548 Buf.push_back(L'\\');
549 Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
550 Buf.push_back(0);
551
552 return ::GetModuleHandleW(Buf.data());
553}
554} // 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:396
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