summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Windows/Process.inc
AgeCommit message (Collapse)Author
2025-06-24[Support] Remove an outdated MinGW workaround (#145294)Martin Storsjö
mingw-w64 has had the _HEAPOK define since the initial commits in 2007; unclear when/where it was added for mingw.org headers, but it does seem to exist there as well (at least in versions from 2011). This workaround stems from 53fbecce6e8b7d1f024e3dc6df4160fe9a577ff1 from 2004 - it is no longer relevant today.
2024-07-30[Support] Silence warnings when retrieving exported functions (#97905)Alexandre Ganea
Since functions exported from DLLs are type-erased, before this patch I was seeing the new Clang 19 warning `-Wcast-function-type-mismatch`. This happens when building LLVM on Windows. Following discussion in https://github.com/llvm/llvm-project/commit/593f708118aef792f434185547f74fedeaf51dd4#commitcomment-143905744
2024-07-06Revert "[Support] Silence function cast warning when building with Clang ToT ↵Alexandre Ganea
targetting Windows" This reverts commit 593f708118aef792f434185547f74fedeaf51dd4.
2024-07-05[Support] Silence function cast warning when building with Clang ToT ↵Alexandre Ganea
targetting Windows
2024-03-08[llvm][Support] Add and use errnoAsErrorCode (#84423)Michael Spencer
LLVM is inconsistent about how it converts `errno` to `std::error_code`. This can cause problems because values outside of `std::errc` compare differently if one is system and one is generic on POSIX systems. This is even more of a problem on Windows where use of the system category is just wrong, as that is for Windows errors, which have a completely different mapping than POSIX/generic errors. This patch fixes one instance of this mistake in `JSONTransport.cpp`. This patch adds `errnoAsErrorCode()` which makes it so people do not need to think about this issue in the future. It also cleans up a lot of usage of `errno` in LLVM and Clang.
2024-01-31[llvm][Support] Support bright colors in raw_ostream (#80017)Timm Baeder
2023-11-03[Support] Use StringRef::starts_with/ends_with instead of ↵Simon Pilgrim
startswith/endswith. NFC. startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-01-06[Support] On Windows 11 and Windows Server 2022, fix an affinity mask issue ↵Alexandre Ganea
on large core count machines Before Windows 11 and Windows Server 2022, only one 'processor group' is assigned by default to a starting process, then the program is responsible for dispatching its own threads on more 'processor groups'. That is what 8404aeb56a73ab24f9b295111de3b37a37f0b841 was doing, allowing LLVM tools to automatically use all hardware threads in the machine. After Windows 11 and Windows Server 2022, the OS takes care of that. This has an adverse effect reported in #56618 which is that using `GetProcessAffinityMask()` API in some edge cases seems buggy now. That API is used to detect if an affinity mask was set, and adjust accordingly the available threads for a ThreadPool. With this patch, on one hand, we let the OS dispatch threads on all 'processor groups', but only for Windows 11 & Windows Server 2022 and after. We retain the old behavior for older OS versions. On the other hand, a workaround was added to mitigate the `GetProcessAffinityMask()` issue described above (see Threading.inc, L226). Differential Revision: https://reviews.llvm.org/D138747
2022-12-06Process: convert Optional to std::optionalKrzysztof Parzyszek
This applies to GetEnv and FindInEnvPath.
2022-12-05[llvm] Use std::nullopt instead of llvm::None (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26[Support] Apply clang-format on .inc files. NFC.Alexandre Ganea
Apply clang-format on llvm/lib/Support/Windows/ and llvm/lib/Support/Unix/ since .inc files in these folders aren't picked up by default. Eventually we need to add this extension in the monorepo .clang-format file. Differential Revision: https://reviews.llvm.org/D138714
2022-06-01[Windows] Don't try to wildcard expand paths starting with \\?\Martin Storsjö
Paths that start with `\\?\` are absolute paths, and aren't expected to be used with wildcard expressions. Previously, the `?` at the start of the path triggered the condition for a potential wildcard, which caused the path to be split and reassembled. In builds with `LLVM_WINDOWS_PREFER_FORWARD_SLASH=ON`, this caused a path like e.g. `\\?\D:\tmp\hello.cpp` to be reassembled into `\\?\D:\tmp/hello.cpp` which isn't a valid path (as such absolute paths must use backslashes consistently). This fixes https://github.com/mstorsjo/llvm-mingw/issues/280. I'm not sure if there's any straightforward way to add a test for this case, unfortunately. Differential Revision: https://reviews.llvm.org/D126675
2022-05-03[Windows] Fix handling of \" in program name on cmd line.Simon Tatham
Bugzilla #47579: if you invoke clang on Windows via a pathname in which a quoted section closes just after a backslash, e.g. "C:\Program Files\Whatever\"clang.exe then cmd.exe and CreateProcess will correctly find the binary, because when they parse the program name at the start of the command line, they don't regard the \ before the " as having any kind of escaping effect. This is different from the behaviour of the Windows standard C library when it parses the rest of the command line, which would consider that \" not to close the quoted string. But this confuses windows::GetCommandLineArguments, because the Windows API function GetCommandLineW() will return a command line containing that \" sequence, and cl::TokenizeWindowsCommandLine will tokenize the whole string according to the C library's rules. So it will misidentify where the program name stops and the arguments start. To fix this, I've introduced a new variant function cl::TokenizeWindowsCommandLineFull(), intended to be applied to the string returned from GetCommandLineW(). It parses the first word of the command line according to CreateProcess's rules, considering \ to never be an escaping character; thereafter, it switches over to the C library rules for the rest of the command line. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D122914
2022-05-03[Windows] Fix cmd line tokenization of unclosed quotes.Simon Tatham
When cl::TokenizeWindowsCommandLine received a command line with an unterminated double-quoted string at the end, it would discard the text within that string. That doesn't match the behavior of the standard Windows C library, which will return the text in the unclosed quoted string as an argv word. Fixed, and added extra unit tests in that area. In some cases (specifically the one in Bugzilla #47579) this could cause TokenizeWindowsCommandLine to return a zero-length list of arguments, leading to an array overrun at the call site in windows::GetCommandLineArguments. Added a check there, for extra safety: now windows::GetCommandLineArguments will return an error code instead of failing an assertion. (This change was written as part of https://reviews.llvm.org/D122914, but split into a separate commit at the last minute at the code reviewer's suggestion, because it's fixing an unrelated bug in the same area. The rest of D122914 will follow in the next commit.)
2022-01-11Support: Avoid SmallVector::set_size() in Windows codeDuncan P. N. Exon Smith
Replace a few `reserve()` / `set_size()` pairs with `resize_for_overwrite()` / `truncate()` in the platform-specific code for Windows. Differential Revision: https://reviews.llvm.org/D115390
2021-11-05[Support] [Windows] Convert paths to the preferred formMartin Storsjö
This normalizes most paths (except ones input from the user as command line arguments) into the preferred form, if `real_style()` evaluates to `windows_forward`. Differential Revision: https://reviews.llvm.org/D111880
2021-07-28[llvm] Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]]Fangrui Song
[[noreturn]] can be used since Oct 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015. Note: the definition of LLVM_ATTRIBUTE_NORETURN is kept for now.
2021-07-09PR51018: A few more explicit conversions from SmallString to StringRefDavid Blaikie
Follow-up to 1def2579e10dd84405465f403e8c31acebff0c97 with a few more obscure cases.
2021-05-22[Windows] Use TerminateProcess to exit without running destructorsMartin Storsjö
If exiting using _Exit or ExitProcess, DLLs are still unloaded cleanly before exiting, running destructors and other cleanup in those DLLs. When the caller expects to exit without cleanup, running destructors in some loaded DLLs (which can be either libLLVM.dll or e.g. libc++.dll) can cause deadlocks occasionally. This is an alternative to D102684. Differential Revision: https://reviews.llvm.org/D102944
2020-11-18Support: Avoid SmallVector::assign with a range from to-be-replaced vector ↵Duncan P. N. Exon Smith
in Windows GetExecutableName This code wasn't valid, and 5abf76fbe37380874a88cc9aa02164800e4e10f3 started asserting. This is a speculative fix since I don't have a Windows machine handy.
2020-04-16Introduce llvm::sys::Process::getProcessId() and adopt itSergej Jaskiewicz
Differential Revision: https://reviews.llvm.org/D78022
2020-04-07[Support,Windows] Tolerate failure of CryptGenRandomSimon Tatham
Summary: In `Unix/Process.inc`, we seed a random number generator from `/dev/urandom` if possible, but if not, we're happy to fall back to ordinary pseudorandom strategies, like the current time and PID. The corresponding function on Windows calls `CryptGenRandom`, but it //doesn't// have a fallback if that strategy fails. But `CryptGenRandom` //can// fail, if a cryptography provider isn't properly initialized, or occasionally (by our observation) simply intermittently. If it's reasonable on Unix to implement traditional pseudorandom-number seeding as a fallback, then it's surely reasonable to do the same on Windows. So this patch adds a last-ditch use of ordinary rand(), using much the same strategy as the Unix fallback code. Reviewers: hans, sammccall Reviewed By: hans Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77553
2020-02-28llvm-ar: Fix MinGW compilationHans Wennborg
llvm-ar is using CompareStringOrdinal which is available only starting with Windows Vista (WINVER 0x600). Fix this by hoising WindowsSupport.h, which sets _WIN32_WINNT to 0x0601, up to llvm/include/llvm/Support and use it in llvm-ar. Patch by Cristian Adam! Differential revision: https://reviews.llvm.org/D74599
2019-10-23Reland "[Support] Add a way to run a function on a detached thread""Sam McCall
This reverts commit 7bc7fe6b789d25d48d6dc71d533a411e9e981237. The immediate callers have been fixed to pass nullopt where appropriate.
2019-10-23Revert "[Support] Add a way to run a function on a detached thread"Sam McCall
This reverts commit 40668abca4d307e02b33345cfdb7271549ff48d0. This causes clang tests to fail, as stacksize=0 is being explicitly passed and is no longer a no-op.
2019-10-23[Support] Add a way to run a function on a detached threadSam McCall
This roughly mimics `std::thread(...).detach()` except it allows to customize the stack size. Required for https://reviews.llvm.org/D50993. I've decided against reusing the existing `llvm_execute_on_thread` because it's not obvious what to do with the ownership of the passed function/arguments: 1. If we pass possibly owning functions data to `llvm_execute_on_thread`, we'll lose the ability to pass small non-owning non-allocating functions for the joining case (as it's used now). Is it important enough? 2. If we use the non-owning interface in the new use case, we'll force clients to transfer ownership to the spawned thread manually, but similar code would still have to exist inside `llvm_execute_on_thread(_async)` anyway (as we can't just pass the same non-owning pointer to pthreads and Windows implementations, and would be forced to wrap it in some structure, and deal with its ownership. Patch by Dmitry Kozhevnikov! Differential Revision: https://reviews.llvm.org/D51103
2019-05-08[Support] Add error handling to sys::Process::getPageSize().Lang Hames
This patch changes the return type of sys::Process::getPageSize to Expected<unsigned> to account for the fact that the underlying syscalls used to obtain the page size may fail (see below). For clients who use the page size as an optimization only this patch adds a new method, getPageSizeEstimate, which calls through to getPageSize but discards any error returned and substitues a "reasonable" page size estimate estimate instead. All existing LLVM clients are updated to call getPageSizeEstimate rather than getPageSize. On Unix, sys::Process::getPageSize is implemented in terms of getpagesize or sysconf, depending on which macros are set. The sysconf call is documented to return -1 on failure. On Darwin getpagesize is implemented in terms of sysconf and may also fail (though the manpage documentation does not mention this). These failures have been observed in practice when highly restrictive sandbox permissions have been applied. Without this patch, the result is that getPageSize returns -1, which wreaks havoc on any subsequent code that was assuming a sane page size value. <rdar://problem/41654857> Reviewers: dblaikie, echristo Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59107 llvm-svn: 360221
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-06[Windows] Simplify WindowsSupport.hReid Kleckner
Sink Windows version detection code from WindowsSupport.h to Path.inc. These functions don't need to be inlined. I randomly picked Process.inc for the Windows version helpers, since that's the most related file. Sink MakeErrMsg to Program.inc since it's the main client. Move those functions into the llvm namespace, and delete the scoped handle copy and assignment operators. Reviewers: zturner, aganea Differential Revision: https://reviews.llvm.org/D54182 llvm-svn: 346280
2018-09-11[Support] Avoid calling CommandLineToArgvW from shell32.dllReid Kleckner
Summary: Shell32.dll depends on gdi32.dll and user32.dll, which are mostly DLLs for Windows GUI functionality. LLVM's utilities don't typically need GUI functionality, and loading these DLLs seems to be slowing down startup. Also, we already have an implementation of Windows command line tokenization in cl::TokenizeWindowsCommandLine, so we can just use it. The goal is to get the original argv in UTF-8, so that it can pass through most LLVM string APIs. A Windows process starts life with a UTF-16 string for its command line, and it can be retreived with GetCommandLineW from kernel32.dll. Previously, we would: 1. Get the wide command line 2. Call CommandLineToArgvW to handle quoting rules and separate it into arguments. 3. For each wide argument, expand wildcards (* and ?) using FindFirstFileW. 4. Convert each argument to UTF-8 Now we: 1. Get the wide command line, convert the whole thing to UTF-8 2. Tokenize the UTF-8 command line with cl::TokenizeWindowsCommandLine 3. For each argument, expand wildcards if present - This requires converting back to UTF-16 to call FindFirstFileW - Results of FindFirstFileW must be converted back to UTF-8 Reviewers: zturner Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D51941 llvm-svn: 341988
2018-09-04Set console mode when -fansi-escape-codes is enabled David Bolvansky
Summary: Windows console now supports supports ANSI escape codes, but we need to enable it using SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING flag. Fixes https://bugs.llvm.org/show_bug.cgi?id=38817 Tested on Windows 10, screenshot: https://i.imgur.com/bqYq0Uy.png Reviewers: zturner, chandlerc Reviewed By: zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D51611 llvm-svn: 341396
2018-06-13Do not enforce absolute path argv0 in windowsHans Wennborg
Even if we support no-canonical-prefix on clang-cl(https://reviews.llvm.org/D47480), argv0 becomes absolute path in clang-cl and that embeds absolute path in /showIncludes. This patch removes such full path normalization from InitLLVM on windows, and that removes absolute path from clang-cl output (obj/stdout/stderr) when debug flag is disabled. Patch by Takuto Ikuta! Differential Revision https://reviews.llvm.org/D47578 llvm-svn: 334602
2018-06-01Move some function declarations out of WindowsSupport.hZachary Turner
The idea behind WindowsSupport.h is that it's in the source directory so that windows.h'isms don't leak out into the larger LLVM project. To that end, any symbol that references a symbol from windows.h must be in this private header, and not in a public header. However, we had some useful utility functions in WindowsSupport.h which have no dependency on the Windows API, but still only make sense on Windows. Those functions should be usable outside of Support since there is no risk of causing a windows.h leak. Although this introduces some preprocessor logic in some header files, It's not too egregious and it's better than the alternative of duplicating a ton of code. Differential Revision: https://reviews.llvm.org/D47662 llvm-svn: 333798
2018-05-01Remove \brief commands from doxygen comments.Adrian Prantl
We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46290 llvm-svn: 331272
2018-04-17Rename sys::Process::GetArgumentVector -> sys::windows::GetCommandLineArgumentsRui Ueyama
GetArgumentVector (or GetCommandLineArguments) is very Windows-specific. I think it doesn't make much sense to provide that function from sys::Process. I also made a change so that the function takes a BumpPtrAllocator instead of a SpecificBumpPtrAllocator. The latter is the class to call dtors, but since char * is trivially destructible, we should use the former class. Differential Revision: https://reviews.llvm.org/D45641 llvm-svn: 330216
2018-04-02Remove HAVE_LIBPSAPI, HAVE_SHELL32.Nico Weber
These used to be set in the old autoconf build, but the cmake build has had a "TODO: actually check for these" comment since it was checked in, and they were set to 1 on mingw unconditionally. It seems safe to say that they always exist under mingw, so just remove them and assume they're set exactly when on mingw (with msvc, we use `pragma comment` instead of linking these via flags). llvm-svn: 328992
2017-08-18[Support] env vars with empty values on windowsBen Dunbobbin
An environment variable can be in one of three states: 1. undefined. 2. defined with a non-empty value. 3. defined but with an empty value. The windows implementation did not support case 3 (it was not handling errors). The Linux implementation is already correct. Differential Revision: https://reviews.llvm.org/D36394 llvm-svn: 311174
2017-03-31Do not pollute the namespace in a header file.Kristof Beyls
llvm-svn: 299218
2016-10-24Remove TimeValue usage from llvm/SupportPavel Labath
Summary: This is a follow-up to D25416. It removes all usages of TimeValue from llvm/Support library (except for the actual TimeValue declaration), and replaces them with appropriate usages of std::chrono. To facilitate this, I have added small utility functions for converting time points and durations into appropriate OS-specific types (FILETIME, struct timespec, ...). Reviewers: zturner, mehdi_amini Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25730 llvm-svn: 284966
2016-06-20Properly handle short file names on the command line in Windows [TAKE 2]Adrian McCarthy
Trying to expand short names with a relative path doesn't work, so this first gets the module name to get a full path (which can still have short names). llvm-svn: 273171
2016-06-17Revert "Properly handle short file names on the command line in Windows"Adrian McCarthy
This reverts commit 3e5651782cfc985fca9d94595cad63059e587e2f. llvm-svn: 273033
2016-06-16Properly handle short file names on the command line in WindowsAdrian McCarthy
Some build systems use the short (8.3) file names on Windows, especially if the path has spaces in it. The shortening made it impossible for clang to distinguish between clang.exe, clang++.exe, and clang-cl.exe. So this expands short names in the first argument and does wildcard expansion for the rest. Differential Revision: http://reviews.llvm.org/D21420 llvm-svn: 272967
2016-05-04[Support] Creation of minidump after compiler crash on WindowsLeny Kholodov
In the current implementation compiler only prints stack trace to console after crash. This patch adds saving of minidump files which contain a useful subset of the information for further debugging. Differential Revision: http://reviews.llvm.org/D18216 llvm-svn: 268519
2015-11-11Report Windows error code in a fatal error after a system call.Paul Robinson
llvm-svn: 252800
2015-05-04Replace windows_error calls with mapWindowsError.Yaron Keren
After r210687, windows_error does nothing but call mapWindowsError. Other Windows/*.inc files directly call mapWindowsError. This patch updates Path.inc and Process.inc to do the same. llvm-svn: 236409
2015-02-28[raw_ostream] When printing color on Windows, use correct bg color.Zachary Turner
When using SetConsoleTextAttribute() to set the foreground or background color, if you don't explicitly set both colors, then a default value of black will be chosen for whichever you don't specify a value for. This is annoying when you have a non default console background color, for example, and you try to set the foreground color. This patch gets the existing fg/bg color and when you set one attribute, sets the opposite attribute to its existing color prior to comitting the update. Reviewed by: Aaron Ballman Differential Revision: http://reviews.llvm.org/D7967 llvm-svn: 230859
2014-12-04Remove dead code. NFC.Rafael Espindola
This interface was added 2 years ago but users never developed. llvm-svn: 223368
2014-10-07Support: Don't call close again if we get EINTRDavid Majnemer
Most Unix-like operating systems guarantee that the file descriptor is closed after a call to close(2), even if close comes back with EINTR. For these systems, calling close _again_ will either do nothing or close some other file descriptor open(2)'d by another thread. (Linux) However, some operating systems do not have this behavior. They require at least another call to close(2) before guaranteeing that the descriptor is closed. (HP-UX) And some operating systems have an unpredictable blend of the two behaviors! (xnu) Avoid this disaster by blocking all signals before we call close(2). This ensures that a signal will not be delivered to the thread and close(2) will not give us back EINTR. We restore the signal mask once the operation is done. N.B. This isn't a problem on Windows, it doesn't have a notion of EINTR because signals always get delivered to dedicated signal handling threads. llvm-svn: 219189
2014-10-06Support: Add a utility to remap std{in,out,err} to /dev/null if closedDavid Majnemer
It's possible to start a program with one (or all) of the standard file descriptors closed. Subsequent open system calls will give the program a low-numbered file descriptor. This is problematic because we may believe we are writing to standard out instead of a file. Introduce Process::FixupStandardFileDescriptors, a helper function to remap standard file descriptors to /dev/null if they were closed before the program started. llvm-svn: 219170
2014-07-24Windows: Don't wildcard expand /? or -?Hans Wennborg
Even if there's a file called c:\a, we want /? to be preserved as an option, not expanded to a filename. llvm-svn: 213894