about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2025-03-29Rollup merge of #139081 - joboet:errno_dedup, r=NoratriebMatthias Krüger-0/+8
std: deduplicate `errno` accesses By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
2025-03-29Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboetMatthias Krüger-107/+173
Start using `with_native_path` in `std::sys::fs` Ideally, each platform should use their own native path type internally. This will, for example, allow passing a `CStr` directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated C string. However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this PR does some minimal refactoring which should help progress towards that goal. The changes are Unix-only and even then I avoided functions that require more changes so that this PR is just moving things around. r? joboet
2025-03-29Start using with_native_path in std::sys::fsChris Denton-107/+173
2025-03-29std: make `cmath` functions safejoboet-59/+59
2025-03-29Rollup merge of #138988 - madsmtm:internal-weak-macro-syntax, r=ibraheemdevMatthias Krüger-80/+144
Change the syntax of the internal `weak!` macro Change the syntax to include parameter names and a trailing semicolon. Motivation: - Mirror the `syscall!` macro. - Allow rustfmt to format it (when wrapped in parentheses, and when not inside `cfg_if!`). - For better documentation (having the parameter names available in the source code is a bit nicer). - Allow a future improvement to this macro where we can sometimes use the symbol directly when it's statically known to be available (and thus need the parameter names to be available), see https://github.com/rust-lang/rust/pull/136868. r? libs
2025-03-29Rollup merge of #138757 - rust-wasi-web:wasi-thread-stack-size, r=alexcrichtonMatthias Krüger-2/+2
wasm: increase default thread stack size to 1 MB The default stack size for the [main thread is 1 MB as specified by linker options](https://github.com/rust-lang/rust/blob/38cf49dde8a5b0b284bb6dffd423d223c9f8f7a3/compiler/rustc_target/src/spec/base/wasm.rs#L14). However, the default stack size for threads was only 64 kB. This is surprisingly small and thus we increase it to 1 MB to match the main thread.
2025-03-28std: deduplicate `errno` accessesjoboet-0/+8
By marking `__errno_location` as `#[ffi_const]` and `std::sys::os::errno` as `#[inline]`, this PR allows merging multiple calls to `io::Error::last_os_error()` into one.
2025-03-27Trusty: Implement write_vectored for stdioThalia Archibald-38/+49
Currently, `write` for stdout and stderr on Trusty is implemented with the semantics of `write_all`. Instead, call the underlying syscall only once in `write` and use the default implementation of `write_all` like other platforms. Also, implement `write_vectored` by adding support for `IoSlice`. Refactor stdin to reuse the unsupported type like #136769.
2025-03-27std: get rid of pre-Vista fallback codejoboet-22/+6
We haven't had any Windows XP targets for a long while now...
2025-03-26Change the syntax of the internal `weak!` macroMads Marquart-80/+144
Change the syntax to include parameter names and a trailing semicolon. Motivation: - Mirror the `syscall!` macro. - Allow rustfmt to format it (when wrapped in parentheses). - For better documentation (having the parameter names available in the source code is a bit nicer). - Allow future improvements to this macro where we can sometimes use the symbol directly when it's statically known to be available.
2025-03-25Fix typo in error messageThalia Archibald-1/+1
2025-03-26#[allow(dead_code)]наб-3/+5
2025-03-25Rollup merge of #138875 - thaliaarchi:trusty-build, r=randomPoison,saethlinJacob Pratt-2/+0
Trusty: Fix build for anonymous pipes and std::sys::process PRs #136842 (Add libstd support for Trusty targets), #137793 (Stablize anonymous pipe), and #136929 (std: move process implementations to `sys`) merged around the same time, so update Trusty to take them into account. cc `@randomPoison`
2025-03-25Fix UWP reparse point checkChris Denton-1/+1
2025-03-24Rollup merge of #138662 - Ayush1325:uefi-fs-1, r=nicholasbishop,petrochenkovMatthias Krüger-12/+62
Implement some basics in UEFI fs - Just getting some basics out of the way while waiting for #138236 to be merged. - Adds `fs::canonicalize`. Should be same as absolute in case of UEFI since there is no symlink support and absolute path is guaranteed to be uniqe according to spec. - Make `fs::lstat` same as `fs::stat`. Should be same since UEFI does not have symlink support. - Implement `OptionOptions`. cc ````@nicholasbishop```` ````@dvdhrm````
2025-03-24std: fs: uefi: Implement OpenOptionsAyush Singh-8/+58
UEFI does not have specific modes for create_new, truncate and append. So those need to to be simulated after opening the file. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24std: fs: uefi: Make lstat call statAyush Singh-2/+2
- UEFI does not have symlinks. So lstat and stat should behave the same. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-24std: fs: uefi: Implement canonicalizeAyush Singh-2/+2
- Should be same as absolute in UEFI since there are no symlinks. - Also each absolute path representation should be unique according to the UEFI specification. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-23Trusty: Fix build for anonymous pipes and std::sys::processThalia Archibald-2/+0
PRs #136842 (Add libstd support for Trusty targets), #137793 (Stablize anonymous pipe), and #136929 (std: move process implementations to `sys`) merged around the same time, so update Trusty to take them into account.
2025-03-23Rollup merge of #138671 - ChrisDenton:filetype, r=joshtriplettJacob Pratt-18/+15
Fix `FileType` `PartialEq` implementation on Windows Fixes #138668 On Windows the [`FileType`](https://doc.rust-lang.org/stable/std/fs/struct.FileType.html) struct was deriving `PartialEq` which in turn means it was doing a bit-for-bit comparison on the file attributes and reparse point. This is wrong because `attributes` may contain many things unrelated to file type. `FileType` on Windows allows for four possible combinations (see also [`FileTypeExt`](https://doc.rust-lang.org/stable/std/os/windows/fs/trait.FileTypeExt.html)): `file`, `dir`, `symlink_file` and `symlink_dir`. So the new implementation makes sure both symlink and directory information match (and only those things). This could be considered just a bug fix but it is a behaviour change so someone from libs-api might want to FCP this (or might not)...
2025-03-23Rollup merge of #138667 - Ayush1325:uefi-mkdir, r=joboetMichael Goulet-4/+30
std: uefi: fs: Implement mkdir - Since there is no direct mkdir in UEFI, first check if a file/dir with same path exists and then create the directory. cc `@dvdhrm` `@nicholasbishop`
2025-03-23Rollup merge of #138236 - Ayush1325:uefi-event, r=petrochenkovMichael Goulet-38/+58
uefi: Add OwnedEvent abstraction - Events are going to become quite important for Networking, so needed owned abstractions. - Switch to OwnedEvent abstraction for Exit boot services event. cc ````@nicholasbishop````
2025-03-23Auto merge of #136929 - joboet:move_process_pal, r=Mark-Simulacrumbors-104/+90
std: move process implementations to `sys` As per #117276, this moves the implementations of `Process` and friends out of the `pal` module and into the `sys` module, removing quite a lot of error-prone `#[path]` imports in the process (hah, get it ;-)). I've also made the `zircon` module a dedicated submodule of `pal::unix`, hopefully we can move some other definitions there as well (they are currently quite a lot of duplications in `sys`). Also, the `ensure_no_nuls` function on Windows now lives in `sys::pal::windows` – it's not specific to processes and shared by the argument implementation.
2025-03-23Auto merge of #136769 - thaliaarchi:io-optional-methods/stdio, r=joboetbors-133/+101
Provide optional `Read`/`Write` methods for stdio Override more of the default methods for `io::Read` and `io::Write` for stdio types, when efficient to do so, and deduplicate unsupported types. Tracked in https://github.com/rust-lang/rust/issues/136756. try-job: x86_64-msvc-1
2025-03-22Auto merge of #138841 - matthiaskrgr:rollup-bfkls57, r=matthiaskrgrbors-2/+3
Rollup of 8 pull requests Successful merges: - #138018 (rustdoc: Use own logic to print `#[repr(..)]` attributes in JSON output.) - #138294 (Mark some std tests as requiring `panic = "unwind"`) - #138468 (rustdoc js: add nonnull helper and typecheck src-script.js) - #138675 (Add release notes for 1.85.1) - #138765 (Fix Thread::set_name on cygwin) - #138786 (Move some driver code around) - #138793 (target spec check: better error when llvm-floatabi is missing) - #138822 (De-Stabilize `file_lock`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-22Auto merge of #138831 - matthiaskrgr:rollup-3t0dqiz, r=matthiaskrgrbors-0/+87
Rollup of 7 pull requests Successful merges: - #138609 (Add stack overflow handler for cygwin) - #138639 (Clean UI tests 2 of n) - #138773 (catch_unwind intrinsic: document return value) - #138782 (test(ui): add tuple-struct-where-clause-suggestion ui test for #91520) - #138794 (expand: Do not report `cfg_attr` traces on macros as unused attributes) - #138801 (triagebot: add autolabel rules for D-* and L-*) - #138804 (Allow inlining for `Atomic*::from_ptr`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-22Rollup merge of #138765 - Berrysoft:cygwin-thread-name, r=joboetMatthias Krüger-2/+3
Fix Thread::set_name on cygwin Just like Linux, Cygwin also sets a limitation to thread name. https://github.com/cygwin/cygwin/blob/8e50c7af7c49819245739d6f626f6fecc394ef7f/winsup/cygwin/thread.cc#L3175
2025-03-22std: move process implementations to `sys`joboet-104/+90
As per #117276, this moves the implementations of `Process` and friends out of the `pal` module and into the `sys` module, removing quite a lot of error-prone `#[path]` imports in the process (hah, get it ;-)). I've also made the `zircon` module a dedicated submodule of `pal::unix`, hopefully we can move some other definitions there as well (they are currently quite a lot of duplications in `sys`). Also, the `ensure_no_nuls` function on Windows now lives in `sys::pal::windows` – it's not specific to processes and shared by the argument implementation.
2025-03-22Rollup merge of #138609 - Berrysoft:cygwin-stackoverflow, r=joboetMatthias Krüger-0/+87
Add stack overflow handler for cygwin The cygwin runtime handles stack overflow exception and converts it to `SIGSEGV`, but the passed `si_addr` is obtained from `ExceptionInformation[1]` which is actually an undocumented value when stack overflows. Thus I choose to use Windows API directly to register handler, just like how std does on native Windows. The code is basically copied from the Windows one. Ref: * https://github.com/cygwin/cygwin/blob/5ec497dc80bcb7ad78cc07bb919b2624b361f017/winsup/cygwin/exceptions.cc#L822-L823 * https://learn.microsoft.com/zh-cn/windows/win32/api/winnt/ns-winnt-exception_record
2025-03-22Rollup merge of #138673 - taiki-e:trusty-fix, r=NoratriebMatthias Krüger-1/+1
Fix build failure on Trusty This target is currently broken due to update to 2024 editon. ```console $ cargo new --lib repro $ cd repro $ cargo check -Z build-std=std --target aarch64-unknown-trusty Compiling std v0.0.0 ($HOME/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std) error: extern blocks must be unsafe --> $HOME/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/random/trusty.rs:1:1 | 1 | / extern "C" { 2 | | fn trusty_rng_secure_rand(randomBuffer: *mut core::ffi::c_void, randomBufferLen: libc::size_t); 3 | | } | |_^ error: could not compile `std` (lib) due to 1 previous error ``` cc ```@randomPoison``` ```@ahomescu``` ([target maintainers](https://doc.rust-lang.org/nightly/rustc/platform-support/trusty.html#target-maintainers))
2025-03-22Use unit structs for stateless stdioThalia Archibald-12/+12
This seems to be the pattern for newer pal stdio types.
2025-03-22Implement optional methods for unsupported stdioThalia Archibald-1/+64
Match what `std::io::Empty` does, since it is very similar. However, still evaluate the `fmt::Arguments` in `write_fmt` to be consistent with other platforms.
2025-03-21Fix Thread::set_name on cygwin王宇逸-2/+3
2025-03-20wasm: increase default thread stack size to 1 MBSebastian Urban-2/+2
The default stack size for the main thread is 1 MB as specified by linker options. However, the default stack size for threads was only 64 kB. This is surprisingly small and thus we increase it to 1 MB to match the main thread.
2025-03-19Auto merge of #138653 - matthiaskrgr:rollup-fwwqmr7, r=matthiaskrgrbors-6/+18
Rollup of 7 pull requests Successful merges: - #136320 (exit: document interaction with C) - #138080 (Leave a breadcrumb towards bootstrap config documentation in `bootstrap.toml`) - #138301 (Implement `read_buf` for Hermit) - #138569 (rustdoc-json: Add tests for `#[repr(...)]`) - #138635 (Extract `for_each_immediate_subpat` from THIR pattern visitors) - #138642 (Unvacation myself) - #138644 (Add `#[cfg(test)]` for Transition in dfa in `rustc_transmute`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-18fix pthread-based tls on apple targetsAndrei Damian-0/+1
2025-03-18Windows: fix FileType PartialEq implementationChris Denton-18/+15
2025-03-19Fix build failure on TrustyTaiki Endo-1/+1
2025-03-18Add stack overflow handler for cygwinBerrysoft-0/+87
2025-03-18std: uefi: fs: Implement mkdirAyush Singh-4/+30
- Since there is no direct mkdir in UEFI, first check if a file/dir with same path exists and then create the directory. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-18Rollup merge of #138301 - thaliaarchi:io-optional-methods/hermit, r=tgross35Matthias Krüger-6/+18
Implement `read_buf` for Hermit Following https://github.com/hermit-os/kernel/pull/1606, it is now safe to implement `Read::read_buf` for file descriptors on Hermit. cc ```@mkroening```
2025-03-18Auto merge of #135368 - Ayush1325:uefi-fs-2, r=jhpratt,nicholasbishopbors-5/+138
uefi: fs: Implement exists Also adds the initial file abstractions. The file opening algorithm is inspired from UEFI shell. It starts by classifying if the Path is Shell mapping, text representation of device path protocol, or a relative path and converts into an absolute text representation of device path protocol. After that, it queries all handles supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and opens the volume that matches the device path protocol prefix (similar to Windows drive). After that, it opens the file in the volume using the remaining pat. It also introduces OwnedDevicePath and BorrowedDevicePath abstractions to allow working with the base UEFI and Shell device paths efficiently. DevicePath in UEFI behaves like an a group of nodes laied out in the memory contiguously and thus can be modeled using iterators. This is an effort to break the original PR (https://github.com/rust-lang/rust/pull/129700) into much smaller chunks for faster upstreaming.
2025-03-18uefi: fs: Implement existsAyush Singh-5/+138
Also adds the initial file abstractions. The file opening algorithm is inspired from UEFI shell. It starts by classifying if the Path is Shell mapping, text representation of device path protocol, or a relative path and converts into an absolute text representation of device path protocol. After that, it queries all handles supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and opens the volume that matches the device path protocol prefix (similar to Windows drive). After that, it opens the file in the volume using the remaining pat. It also introduces OwnedDevicePath and BorrowedDevicePath abstractions to allow working with the base UEFI and Shell device paths efficiently. DevicePath in UEFI behaves like an a group of nodes laied out in the memory contiguously and thus can be modeled using iterators. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-17Implement read_buf for HermitThalia Archibald-6/+18
2025-03-17Rollup merge of #137793 - NobodyXu:stablise-annoymous-pipe, r=joshtriplettJacob Pratt-207/+68
Stablize anonymous pipe Since #135822 is staled, I create this PR to stablise anonymous pipe Closes #127154 try-job: test-various
2025-03-17Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboetJacob Pratt-11/+65
Add std support to cygwin target
2025-03-16Rollup merge of #138573 - Noratrieb:no-unsound-bad-bonk-bonk, r=workingjubileeJacob Pratt-2/+2
Make `_Unwind_Action` a type alias, not enum It's bitflags in practice, so an enum is unsound, as an enum must only have the described values. The x86_64 psABI declares it as a `typedef int _Unwind_Action`, which seems reasonable. I made a newtype first but that was more annoying than just a typedef. We don't really use this value for much other than a short check. I ran `x check library --target aarch64-unknown-linux-gnu,x86_64-pc-windows-gnu,x86_64-fortanix-unknown-sgx,x86_64-unknown-haiku,x86_64-unknown-fuchsi a,x86_64-unknown-freebsd,x86_64-unknown-dragonfly,x86_64-unknown-netbsd,x86_64-unknown-openbsd,x86_64-unknown-redox,riscv64-linux-android,armv7-unknown-freebsd` (and some more but they failed to build for other reasons :D) fixes #138558 r? workingjubilee have fun
2025-03-16make `_Unwind_Action` a type alias, not enumNoratrieb-2/+2
It's bitflags in practice, so an enum is unsound, as an enum must only have the described values. The x86_64 psABI declares it as a `typedef int _Unwind_Action`, which seems reasonable. I made a newtype first but that was more annoying than just a typedef. We don't really use this value for much other than a short check.
2025-03-17uefi: Add OwnedEvent abstractionAyush Singh-38/+58
- Events are going to become quite important for Networking, so needed owned abstractions. - Switch to OwnedEvent abstraction for Exit boot services event. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-14Auto merge of #137424 - Ayush1325:uefi-path-node, r=nicholasbishop,cuviperbors-0/+179
uefi: helpers: Add DevicePathNode abstractions - UEFI device path is a series of nodes layed out in a contiguous memory region. So it makes sense to use Iterator abstraction for modeling DevicePaths - This PR has been split off from #135368 for easier review. The allow dead_code will be removed in #135368 cc `@nicholasbishop`