about summary refs log tree commit diff
path: root/library/std/src/sys/windows/c.rs
AgeCommit message (Collapse)AuthorLines
2024-01-11std: begin moving platform support modules into `pal`joboet-480/+0
2023-12-03library: use c string literalsklensy-2/+2
2023-11-24Rollup merge of #117656 - ChrisDenton:invalid, r=thomccMatthias Krüger-0/+2
Update windows-bindgen and define `INVALID_HANDLE_VALUE` ourselves We generate bindings to the Windows API via the `windows-bindgen` crate, which is ultimately what's also used to generate the `windows-sys` and `windows` crates. However, there currently is some custom sauce just for std which makes it a bit different from the vanilla bindings. I would love for us to reduce and eventually remove the differences entirely so that std is using the exact same bindings as everyone else. Maybe in the future we can even just have a normal dependency on `windows-sys`. This PR removes one of those special things. Our definition of `INVALID_HANDLE_VALUE` relies on an experimental nightly feature for strict provenance, so lets bring that back in house. It also excludes it from the codegen step though that isn't strictly necessary as we override it in any case. This PR also updates windows-bingen to 0.52.0.
2023-11-22manual_slice_size_calculationChris Denton-1/+1
2023-11-22allow clippy style in windows/c.rsChris Denton-0/+1
We intentional use the Windows API style here.
2023-11-17Define `INVALID_HANDLE_VALUE` ourselvesChris Denton-0/+2
2023-10-06Remove libcChris Denton-0/+4
We don't use much libc on Windows.
2023-08-28Update windows ffi bindingsChris Denton-5/+1
2023-07-05Revert "use c literals in library"León Orell Valerian Liehr-2/+2
This reverts commit f212ba6d6d60963c8101bb24fc3e53fca80c046f.
2023-06-25Auto merge of #113001 - ChrisDenton:win-arm32-shim, r=thomccbors-0/+44
Move windows-sys arm32 shim to c.rs This moves the arm32 shim in to c.rs instead of appending to the generated file itself. This makes it simpler to change these workarounds if/when needed. The downside is we need to exclude a couple of functions from being generated (see the comment). A metadata solution could help here but they'll be easy enough to add back if that happens.
2023-06-24Remove unnecessary `path` attributeChris Denton-1/+0
2023-06-24Move arm32 shim to c.rsChris Denton-0/+44
2023-06-10Keep uwp specific code in sync with windows-sysbdbai-5/+2
2023-06-10Lazy load ntdll functions on UWPbdbai-0/+58
2023-05-31use c literals in libraryklensy-2/+2
2023-05-05Generate windows-sys bindingsChris Denton-1162/+153
2023-03-21Auto merge of #108262 - ChrisDenton:libntdll, r=Mark-Simulacrumbors-47/+40
Distribute libntdll.a with windows-gnu toolchains This allows the OS loader to load essential functions (e.g. read/write file) at load time instead of lazily doing so at runtime. r? libs
2023-02-27Rollup merge of #107110 - strega-nil:mbtwc-wctmb, r=ChrisDentonMatthias Krüger-2/+30
[stdio][windows] Use MBTWC and WCTMB `MultiByteToWideChar` and `WideCharToMultiByte` are extremely well optimized, and therefore should probably be used when we know we can (specifically in the Windows stdio stuff). Fixes #107092
2023-02-25[stdio][windows] Use MBTWC and WCTMBNicole Mazzuca-2/+30
2023-02-23Fix `is_terminal`'s handling of long paths on Windows.Dan Gohman-8/+0
As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case. This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-20Distribute libntdll.a with windows-gnu toolchainsChris Denton-47/+40
This allows loading some essential functions (e.g. read/write file) at load time instead of lazily.
2023-02-14Revert to using `RtlGenRandom`Chris Denton-9/+4
This is required due to `BCryptGenRandom` failing to load the necessary dll on some systems.
2022-11-05Rollup merge of #103995 - SUPERCILEX:typos, r=Dylan-DPCDylan DPC-1/+1
Small round of typo fixes
2022-11-04Small round of typo fixesAlex Saveau-1/+1
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-27Use stdio in UWP appsChris Denton-30/+27
This has been supported since Windows 10.0.16299. See https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-console-l1-1-0dll
2022-10-21Reduce false positives in msys2 detectionChris Denton-0/+3
This checks that: * the handle is a pipe * the pipe's file name starts with "msys-" or "cygwin-" rather than looking in the full path.
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+8
The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-13Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDentonbors-0/+17
Optimize TLS on Windows This implements the suggestion in the current TLS code to embed the linked list of destructors in the `StaticKey` structure to save allocations. Additionally, locking is avoided when no destructor needs to be run. By using one Windows-provided `Once` per key instead of a global lock, locking is more finely-grained (this unblocks #100579).
2022-10-08std: optimize TLS on Windowsjoboet-0/+17
2022-09-20Remove `RtlGenRandom` (take two)Chris Denton-5/+1
First try to use the system preferred RNG but if that fails (e.g. due to a broken system configuration) then fallback to manually opening an algorithm handle.
2022-09-06Open a BCrypt algorithm handleChris Denton-2/+12
2022-09-03Rollup merge of #101325 - ChrisDenton:BCRYPT_RNG_ALG_HANDLE, r=thomccDylan DPC-1/+1
Windows RNG: Use `BCRYPT_RNG_ALG_HANDLE` by default This only changes a small amount of actual code, the rest is documentation outlining the history of this module as I feel it will be relevant to any future issues that might crop up. The code change is to use the `BCRYPT_RNG_ALG_HANDLE` [pseudo-handle](https://docs.microsoft.com/en-us/windows/win32/seccng/cng-algorithm-pseudo-handles) by default, which simply uses the default RNG. Previously we used `BCRYPT_USE_SYSTEM_PREFERRED_RNG` which has to load the system configuration and then find and load that RNG. I suspect this was the cause of failures on some systems (e.g. due to corrupted config). However, this is admittedly speculation as I can't reproduce the issue myself (and it does seem quite rare even in the wild). Still, removing a possible point of failure is likely worthwhile in any case. r? libs
2022-09-02Use `BCRYPT_RNG_ALG_HANDLE` by defaultChris Denton-1/+1
Also briefly document the history of `sys/windows/rand.rs` as they may be relevant to any future changes.
2022-09-01Use `FILE_ATTRIBUTE_TAG_INFO` to get reparse tagChris Denton-0/+6
This avoid unnecessarily getting the full reparse data when all we need is the tag.
2022-08-31Rollup merge of #101171 - thomcc:fix-winfs-ub, r=ChrisDentonMatthias Krüger-0/+6
Fix UB from misalignment and provenance widening in `std::sys::windows` This fixes two types of UB: 1. Reading past the end of a reference in types like `&c::REPARSE_DATA_BUFFER` (see https://github.com/rust-lang/unsafe-code-guidelines/issues/256). This is fixed by using `addr_of!`. I think there are probably a couple more cases where we do this for other structures, and will look into it in a bit. 2. Failing to ensure that a `[u8; N]` on the stack is sufficiently aligned to convert to a `REPARSE_DATA_BUFFER`. ~~This was done by introducing a new `AlignedAs` struct that allows aligning one type to the alignment of another type. I expect there are other places where we have this issue too, or I wouldn't introduce this type, but will get to them after this lands.~~ ~~Worth noting, it *is* implemented in a way that can cause problems depending on how we fix #81996, but this would be caught by the test I added (and presumably if we decide to fix that in a way that would break this code, we'd also introduce a `#[repr(simple)]` or `#[repr(linear)]` as a replacement for this usage of `#[repr(C)]`).~~ Edit: None of that is still in the code, I just went with a `Align8` since that's all we'll need for almost everything we want to call. These are more or less "potential UB" since it's likely at the moment everything works fine, although the alignment not causing issues might just be down to luck (and x86 being forgiving). ~~NB: I've only ensured this check builds, but will run tests soon.~~ All tests pass, including stage2 compiler tests. r? ``@ChrisDenton``
2022-08-29Fix some possible UB in std::sys::windowsThom Chiovoloni-0/+6
2022-08-28Reinstate preloading of some dll importsChris Denton-3/+0
2022-08-18Windows: Load synch functions togetherChris Denton-14/+12
Attempt to load all the required sync functions and fail if any one of them fails. This reintroduces a macro for optional loading of functions but keeps it separate from the fallback macro rather than having that do two different jobs.
2022-08-04Update after code reviewChris Denton-0/+6
2022-08-04Remove Windows function preloadingChris Denton-11/+7
2022-08-01Auto merge of #98246 - joshtriplett:times, r=m-ou-sebors-1/+7
Support setting file accessed/modified timestamps Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-26Rewrite Windows `compat_fn` macroChris Denton-13/+10
This allows using most delay loaded functions before the init code initializes them. It also only preloads a select few functions, rather than all functions. Co-Authored-By: Mark Rousskov <mark.simulacrum@gmail.com>
2022-07-15Support setting file accessed/modified timestampsJosh Triplett-1/+7
Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-06Windows: Fallback for overlapped I/OChris Denton-1/+13
Try waiting on the file handle once. If that fails then give up.
2022-06-07Windows: No panic if function not (yet) availableChris Denton-4/+5
In some situations it is possible for required functions to be called before they've had a chance to be loaded. Therefore, we make it possible to recover from this situation simply by looking at error codes.
2022-05-19Rollup merge of #97127 - Mark-Simulacrum:revert-96441, r=m-ou-seYuki Okushi-6/+0
Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se" This reverts commit ddb7fbe8434be481607ae199fe2aee976ee2fc2e. Partially addresses https://github.com/rust-lang/rust/issues/97124, but not marking as fixed as we're still pending on a beta backport (for 1.62, which is happening in https://github.com/rust-lang/rust/pull/97088). r? ``@m-ou-se`` ``@ChrisDenton``
2022-05-17Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se"Mark Rousskov-6/+0
This reverts commit ddb7fbe8434be481607ae199fe2aee976ee2fc2e, reversing changes made to baaa3b682986879c7784b5733ecea942e9ae7de3.
2022-05-10Make HashMap fall back to RtlGenRandom if BCryptGenRandom failsChris Martin-0/+4
Issue #84096 changed the hashmap RNG to use BCryptGenRandom instead of RtlGenRandom on Windows. Mozilla Firefox started experiencing random failures in env_logger::Builder::new() (Issue #94098) during initialization of their unsandboxed main process with an "Access Denied" error message from BCryptGenRandom(), which is used by the HashMap contained in env_logger::Builder The root cause appears to be a virus scanner or other software interfering with BCrypt DLLs loading. This change adds a fallback option if BCryptGenRandom is unusable for whatever reason. It will fallback to RtlGenRandom in this case. Fixes #94098
2022-04-26Windows: Make stdin pipes synchronousChris Denton-0/+6
Stdin pipes do not need to be used asynchronously within the standard library.
2022-04-16Use a single ReentrantMutex implementation on all platforms.Mara Bos-14/+0