summary refs log tree commit diff
path: root/library/std/src/sys/windows
AgeCommit message (Collapse)AuthorLines
2021-04-28Remove `DropGuard` in `sys::windows::process` and use `StaticMutex` insteadChristiaan Dirkx-24/+4
2021-04-25Rollup merge of #84541 - KaiJewson:inline-raw, r=m-ou-seDylan DPC-0/+18
Inline most raw socket, fd and handle conversions Now that file descriptor types on Unix have niches, it is advantageous for user libraries which provide file descriptor wrappers (e.g. `Socket` from socket2) to store a `File` internally instead of a `RawFd`, so that the niche can be taken advantage of. However, doing so will currently result in worse performance as `IntoRawFd`, `FromRawFd` and `AsRawFd` are not inlined. This change adds `#[inline]` to those methods on std types that wrap file descriptors, handles or sockets.
2021-04-25Inline most raw socket, fd and handle conversionsKaiJewson-0/+18
2021-04-25Auto merge of #84115 - CDirkx:rt, r=m-ou-sebors-17/+23
Rework `init` and `cleanup` This PR reworks the code in `std` that runs before and after `main` and centralizes this code respectively in the functions `init` and `cleanup` in both `sys_common` and `sys`. This makes is easy to see what code is executed during initialization and cleanup on each platform just by looking at e.g. `sys::windows::init`. Full list of changes: - new module `rt` in `sys_common` to contain `init` and `cleanup` and the runtime macros. - `at_exit` and the mechanism to register exit handlers has been completely removed. In practice this was only used for closing sockets on windows and flushing stdout, which have been moved to `cleanup`. - <s>On windows `alloc` and `net` initialization is now done in `init`, this saves a runtime check in every allocation and network use.</s>
2021-04-22Document that `init` and `cleanup` are not guaranteed to runChristiaan Dirkx-0/+2
2021-04-22Apply suggestions from reviewChristiaan Dirkx-5/+8
2021-04-22Move most init to `sys::init`Christiaan Dirkx-3/+3
2021-04-22Remove `sys::args::Args::inner_debug` and use `Debug` insteadChristiaan Dirkx-12/+2
2021-04-22Move all cleanup to `sys::cleanup`Christiaan Dirkx-6/+0
2021-04-22Rework `at_exit` to `cleanup`Christiaan Dirkx-7/+14
2021-04-18Rename `NotSupported` to `Unsupported`Christiaan Dirkx-3/+6
2021-04-18Update `decode_error_kind` to decode os errors to `NotSupported`Christiaan Dirkx-0/+1
2021-04-18Add and insta-stabilize `std::io::ErrorKind::NotSupported`Christiaan Dirkx-2/+2
2021-04-14Move `std::sys_common::alloc` to `std::sys::common`Christiaan Dirkx-1/+1
2021-04-02Remove `debug_assert`Christiaan Dirkx-4/+1
2021-04-02Introduce `get_process_heap` and fix atomic ordering.Christiaan Dirkx-13/+22
2021-03-26Cache `GetProcessHeap`Christiaan Dirkx-16/+54
2021-03-26Apply suggestions from code reviewCDirkx-2/+4
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2021-03-26Rework `std::sys::windows::alloc`Christiaan Dirkx-32/+173
Add documentation to the system functions and `SAFETY` comments. Refactored helper functions, fixing the correctness of `get_header`.
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-18/+18
2021-02-24library: Normalize safety-for-unsafe-block commentsMiguel Ojeda-2/+4
Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-17Expose force_quotes on Windows.Yonggang Luo-10/+49
Quotes the arg and not quotes the arg have different effect on Windows when the program called are msys2/cygwin program. Refer to https://github.com/msys2/MSYS2-packages/issues/2176 Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
2021-02-15Rollup merge of #82119 - m-ou-se:typo, r=dtolnayJonas Schievink-1/+1
Fix typo in link to CreateSymbolicLinkW documentation.
2021-02-14Fix typo in link to CreateSymbolicLinkW documentation.Mara Bos-1/+1
2021-02-10Seal the CommandExt, OsStrExt and OsStringExt traitsAmanieu d'Antras-15/+15
2021-02-08Remove outdated comment.Mara Bos-2/+0
2021-01-31Fix calling convention for CRT startupArlie Davis-12/+10
My PR #81478 used the wrong calling convention for a set of functions that are called by the CRT. These functions need to use `extern "C"`. This would only affect x86, which is the only target (that I know of) that has multiple calling conventions.
2021-01-29Resolve DLL imports at CRT startup, not on demandArlie Davis-71/+95
On Windows, libstd uses GetProcAddress to locate some DLL imports, so that libstd can run on older versions of Windows. If a given DLL import is not present, then libstd uses other behavior (such as fallback implementations). This commit uses a feature of the Windows CRT to do these DLL imports during module initialization, before main() (or DllMain()) is called. This is the ideal time to resolve imports, because the module is effectively single-threaded at that point; no other threads can touch the data or code of the module that is being initialized. This avoids several problems. First, it makes the cost of performing the DLL import lookups deterministic. Right now, the DLL imports are done on demand, which means that application threads _might_ have to do the DLL import during some time-sensitive operation. This is a small source of unpredictability. Since threads can race, it's even possible to have more than one thread running the same redundant DLL lookup. This commit also removes using the heap to allocate strings, during the DLL lookups.
2021-01-22Remove delay-binding for Win XP and VistaArlie Davis-145/+81
The minimum supported Windows version is now Windows 7. Windows XP and Windows Vista are no longer supported; both are already broken, and require extra steps to use. This commit removes the delayed-binding support for Windows API functions that are present on all supported Windows targets. This has several benefits: Removes needless complexity. Removes a load and dynamic call on hot paths in mutex acquire / release. This may have performance benefits. * "Drop official support for Windows XP" https://github.com/rust-lang/compiler-team/issues/378 * "Firefox has ended support for Windows XP and Vista" https://support.mozilla.org/en-US/kb/end-support-windows-xp-and-vista
2021-01-13Fix typo saeled -> sealedDavid Tolnay-1/+1
2021-01-13ExitStatusExt windows: Retrospectively seal this traitIan Jackson-1/+15
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-22Update library/std/src/sys/windows/thread_parker.rsLinus Färnstrand-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-12-22Fix compare_and_swap in Windows thread_parkerLinus Färnstrand-1/+1
2020-12-22Migrate standard library away from compare_and_swapLinus Färnstrand-3/+3
2020-12-16Auto merge of #78833 - CDirkx:parse_prefix, r=dtolnaybors-78/+135
Refactor and fix `parse_prefix` on Windows This PR is an extension of #78692 as well as a general refactor of `parse_prefix`: **Fixes**: There are two errors in the current implementation of `parse_prefix`: Firstly, in the current implementation only `\` is recognized as a separator character in device namespace prefixes. This behavior is only correct for verbatim paths; `"\\.\C:/foo"` should be parsed as `"C:"` instead of `"C:/foo"`. Secondly, the current implementation only handles single separator characters. In non-verbatim paths a series of separator characters should be recognized as a single boundary, e.g. the UNC path `"\\localhost\\\\\\C$\foo"` should be parsed as `"\\localhost\\\\\\C$"` and then `UNC(server: "localhost", share: "C$")`, but currently it is not parsed at all, because it starts being parsed as `\\localhost\` and then has an invalid empty share location. Paths like `"\\.\C:/foo"` and `"\\localhost\\\\\\C$\foo"` are valid on Windows, they are equivalent to just `"C:\foo"`. **Refactoring**: All uses of `&[u8]` within `parse_prefix` are extracted to helper functions and`&OsStr` is used instead. This reduces the number of places unsafe is used: - `get_first_two_components` is adapted to the more general `parse_next_component` and used in more places - code for parsing drive prefixes is extracted to `parse_drive`
2020-12-14Auto merge of #77618 - fusion-engineering-forks:windows-parker, r=Amanieubors-0/+299
Add fast futex-based thread parker for Windows. This adds a fast futex-based thread parker for Windows. It either uses WaitOnAddress+WakeByAddressSingle or NT Keyed Events (NtWaitForKeyedEvent+NtReleaseKeyedEvent), depending on which is available. Together, this makes this thread parker work for Windows XP and up. Before this change, park()/unpark() did not work on Windows XP: it needs condition variables, which only exist since Windows Vista. --- Unfortunately, NT Keyed Events are an undocumented Windows API. However: - This API is relatively simple with obvious behaviour, and there are several (unofficial) articles documenting the details. [1] - parking_lot has been using this API for years (on Windows versions before Windows 8). [2] Many big projects extensively use parking_lot, such as servo and the Rust compiler itself. - It is the underlying API used by Windows SRW locks and Windows critical sections. [3] [4] - The source code of the implementations of Wine, ReactOs, and Windows XP are available and match the expected behaviour. - The main risk with an undocumented API is that it might change in the future. But since we only use it for older versions of Windows, that's not a problem. - Even if these functions do not block or wake as we expect (which is unlikely, see all previous points), this implementation would still be memory safe. The NT Keyed Events API is only used to sleep/block in the right place. [1]\: http://www.locklessinc.com/articles/keyed_events/ [2]\: https://github.com/Amanieu/parking_lot/commit/43abbc964e [3]\: https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/november/windows-with-c-the-evolution-of-synchronization-in-windows-and-c [4]\: Windows Internals, Part 1, ISBN 9780735671300 --- The choice of fallback API is inspired by parking_lot(_core), but the implementation of this thread parker is different. While parking_lot has no use for a fast path (park() directly returning if unpark() was already called), this implementation has a fast path that returns without even checking which waiting/waking API to use, as the same atomic variable with compatible states is used in all cases.
2020-12-10Windows TLS: ManuallyDrop instead of mem::forgetRalf Jung-7/+4
2020-11-28Remove now-unnecessary `miri_static_root` invocationoli-13/+0
2020-11-20Auto merge of #79205 - rust-lang:jdm-patch-1, r=m-ou-sebors-0/+1
Extend meta parameters to all generated code in compat_fn. Fixes https://github.com/rust-lang/rust/issues/79203. This addresses a regression from 7e2032390cf34f3ffa726b7bd890141e2684ba63 for UWP targets.
2020-11-19Auto merge of #79060 - dtolnay:symlinkarg, r=Mark-Simulacrumbors-23/+28
Disambiguate symlink argument names The current argument naming in the following standard library functions is horribly ambiguous. - std::os::unix::fs::symlink: https://doc.rust-lang.org/1.47.0/std/os/unix/fs/fn.symlink.html - std::os::windows::fs::symlink_file: https://doc.rust-lang.org/1.47.0/std/os/windows/fs/fn.symlink_file.html - std::os::windows::fs::symlink_dir: https://doc.rust-lang.org/1.47.0/std/os/windows/fs/fn.symlink_dir.html **Notice that Swift uses one of the same names we do (`dst`) to refer to the opposite thing.** <br> | | the&nbsp;one&nbsp;that&nbsp;exists | the&nbsp;one&nbsp;that&nbsp;is<br>being&nbsp;created | reference | | --- | --- | --- | --- | | Rust | `src` | `dst` | | | Swift | `withDestinationPath`<br>`destPath` | `atPath`<br>`path` | <sub>https://developer.apple.com/documentation/foundation/filemanager/1411007-createsymboliclink</sub> | | D | `original` | `link` | <sub>https://dlang.org/library/std/file/symlink.html</sub> | | Go | `oldname` | `newname` | <sub>https://golang.org/pkg/os/#Symlink</sub> | | C++| `target` | `link` | <sub>https://en.cppreference.com/w/cpp/filesystem/create_symlink</sub> | | POSIX | `path1` | `path2` | <sub>https://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html</sub> | | Linux | `target` | `linkpath` | <sub>https://man7.org/linux/man-pages/man2/symlink.2.html</sub> | Out of these I happen to like D's argument names and am proposing that we adopt them.
2020-11-19Extend meta parameters to all generated code in compat_fn.Josh Matthews-0/+1
2020-11-15Make the libstd build script smallerbjorn3-0/+14
Remove all rustc-link-lib from the std build script. Also remove use of feature = "restricted-std" where not necessary.
2020-11-14Disambiguate symlink argument namesDavid Tolnay-23/+28
2020-11-07Refactor `parse_prefix` on WindowsChristiaan Dirkx-78/+135
Refactor `get_first_two_components` to `get_next_component`. Fixes the following behaviour of `parse_prefix`: - series of separator bytes in a prefix are correctly parsed as a single separator - device namespace prefixes correctly recognize both `\\` and `/` as separators
2020-10-11Auto merge of #77727 - thomcc:mach-info-order, r=Amanieubors-19/+17
Avoid SeqCst or static mut in mach_timebase_info and QueryPerformanceFrequency caches This patch went through a couple iterations but the end result is replacing a pattern where an `AtomicUsize` (updated with many SeqCst ops) guards a `static mut` with a single `AtomicU64` that is known to use 0 as a value indicating that it is not initialized. The code in both places exists to cache values used in the conversion of Instants to Durations on macOS, iOS, and Windows. I have no numbers to prove that this improves performance (It seems a little futile to benchmark something like this), but it's much simpler, safer, and in practice we'd expect it to be faster everywhere where Relaxed operations on AtomicU64 are cheaper than SeqCst operations on AtomicUsize, which is a lot of places. Anyway, it also removes a bunch of unsafe code and greatly simplifies the logic, so IMO that alone would be worth it unless it was a regression. If you want to take a look at the assembly output though, see https://godbolt.org/z/rbr6vn for x86_64, https://godbolt.org/z/cqcbqv for aarch64 (Note that this just the output of the mac side, but i'd expect the windows part to be the same and don't feel like doing another godbolt for it). There are several versions of this function in the godbolt: - `info_new`: version in the current patch - `info_less_new`: version in initial PR - `info_original`: version currently in the tree - `info_orig_but_better_orderings`: a version that just tries to change the original code's orderings from SeqCst to the (probably) minimal orderings required for soundness/correctness. The biggest concern I have here is if we can use AtomicU64, or if there are targets that dont have it that this code supports. AFAICT: no. (If that changes in the future, it's easy enough to do something different for them) r? `@Amanieu` because he caught a couple issues last time I tried to do a patch reducing orderings 😅 --- <details> <summary>I rewrote this whole message so the original is inside here</summary> I happened to notice the code we use for caching the result of mach_timebase_info uses SeqCst exclusively. However, thinking a little more, it's actually pretty easy to avoid the static mut by packing the timebase info into an AtomicU64. This entirely avoids needing to do the compare_exchange. The AtomicU64 can be read/written using Relaxed ops, which on current macos/ios platforms (x86_64/aarch64) have no overhead compared to direct loads/stores. This simplifies the code and makes it a lot safer too. I have no numbers to prove that this improves performance (It seems a little futile to benchmark something like this), although it should do that on both targets it applies to. That said, it also removes a bunch of unsafe code and simplifies the logic (arguably at least — there are only two states now, initialized or not), so I think it's a net win even without concrete numbers. If you want to take a look at the assembly output though, see below. It has the new version, the original, and a version of the original with lower Orderings (which is still worse than the version in this PR) - godbolt.org/z/obfqf9 x86_64-apple-darwin - godbolt.org/z/Wz5cWc aarch64-unknown-linux-gnu (godbolt can't do aarch64-apple-ios but that doesn't matter here) A different (and more efficient) option than this would be to just use the AtomicU64 and use the knowledge that after initialization the denominator should be nonzero... That felt like it's relying on too many things I'm not confident in, so I didn't want to do that. </details>
2020-10-09Remove some dead code in windows-gnu stdMateusz Mikuła-64/+0
2020-10-08Implement the same optimization in windows/timeThom Chiovoloni-19/+17
2020-10-06Formatting.Mara Bos-1/+2
2020-10-06Add comment documenting NtWaitForKeyedEvent's timeout interpretation.Mara Bos-2/+4
2020-10-06Add documentation to Windows thread parker implementation.Mara Bos-1/+60