about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2025-03-09std: move stdio to `sys`joboet-150/+77
As per #117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
2025-03-09Rollup merge of #138276 - bdbai:fix-uwp-ntopenfile, r=ChrisDentonMatthias Krüger-0/+11
Lazy load NtOpenFile for UWP Lazily load `NtOpenFile` to allow libraries targeting UWP to build and link. Fixes #138257 . r? `@ChrisDenton`
2025-03-09Lazy load NtOpenFile for UWPbdbai-0/+11
2025-03-08Move fs into sysThalia Archibald-45/+121
2025-03-07Return OutOfMemoryError and update docsChris Denton-2/+2
2025-03-07Windows: Use MoveFileEx by default in `fs:rename`Chris Denton-123/+56
2025-03-07Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgrbors-121/+101
Rollup of 6 pull requests Successful merges: - #137674 (Enable `f16` for LoongArch) - #138034 (library: Use `size_of` from the prelude instead of imported) - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work) - #138073 (Break critical edges in inline asm before code generation) - #138107 (`librustdoc`: clippy fixes) - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-07Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35Matthias Krüger-121/+101
library: Use `size_of` from the prelude instead of imported Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80. try-job: test-various try-job: x86_64-gnu try-job: x86_64-msvc-1
2025-03-07Rollup merge of #137777 - thaliaarchi:os_string-push-str, r=joboetMatthias Krüger-0/+10
Specialize `OsString::push` and `OsString as From` for UTF-8 When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case. The WTF-8 version of `OsString` tracks whether it is known to be valid UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so this can be set for UTF-8 string types. Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro. r? ``@ChrisDenton``
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-121/+101
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-05Rollup merge of #137477 - Ayush1325:uefi-service-binding, r=Noratrieb许杰友 Jieyou Xu (Joe)-1/+60
uefi: Add Service Binding Protocol abstraction - Some UEFI protocols such as TCP4, TCP6, UDP4, UDP6, etc are managed by service binding protocol. - A new instance of such protocols is created and destroyed using the corresponding service binding protocol. - This PR adds abstractions to make using such protocols simpler using Rust Drop trait. - The reason to add these abstractions in a seperate PR from TCP4 Protocol is to make review easier. [EFI_SERVICE_BINDING_PROTCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol) cc ````@nicholasbishop````
2025-03-05Rollup merge of #137463 - sunshowers:illumos-posix-spawn, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-1/+16
[illumos] attempt to use posix_spawn to spawn processes illumos has `posix_spawn`, and the very newest versions also have `_addchdir`, so use that. POSIX standardized this function so I also added a weak symbol lookup for the non `_np` version. (illumos has both.) This probably also works on Solaris, but I don't have access to an installation to validate this so I decided to focus on illumos instead. This is a nice ~4x performance improvement for process creation. My go-to as usual is nextest against the clap repo, which acts as a stress test for process creation -- with [this commit]: ```console $ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)' before: Summary [ 1.747s] 879 tests run: 879 passed, 2 skipped after: Summary [ 0.445s] 879 tests run: 879 passed, 2 skipped ``` [this commit]: https://github.com/clap-rs/clap/commit/fde45f9aea766fb8de46e3d46e6575f393c3b6b9
2025-03-04Fix some typosfuyangpengqi-1/+1
Signed-off-by: fuyangpengqi <995764973@qq.com>
2025-03-02uefi: Add Service Binding Protocol abstractionAyush Singh-1/+60
- Some UEFI protocols such as TCP4, TCP6, UDP4, UDP6, etc are managed by service binding protocol. - A new instance of such protocols is created and destroyed using the corresponding service binding protocol. - This PR adds abstractions to make using such protocols simpler using Rust Drop trait. - The reason to add these abstractions in a seperate PR from TCP4 Protocol is to make review easier. [EFI_SERVICE_BINDING_PROTCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol) Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-01Rollup merge of #137809 - Noratrieb:io-error-casing, r=thomccMatthias Krüger-70/+70
Use correct error message casing for `io::const_error`s Error messages are supposed to start with lowercase letters, but a lot of `io::const_error` messages did not. This fixes them to start with a lowercase letter. I did consider adding a const check for this to the macro, but some of them start with proper nouns that make sense to uppercase them. See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-02-28Specialize OsString::push for stringsThalia Archibald-0/+10
When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case. Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro.
2025-02-28Use correct error message casing for `io::const_error`sNoratrieb-70/+70
Error messages are supposed to start with lowercase letters, but a lot of `io::const_error` messages did not. This fixes them to start with a lowercase letter. I did consider adding a const check for this to the macro, but some of them start with proper nouns that make sense to uppercase them. See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-02-28Rollup merge of #137673 - ChrisDenton:search-path-bug, r=dtolnay许杰友 Jieyou Xu (Joe)-1/+2
Fix Windows `Command` search path bug Currently `Command::new` on Windows works differently depending on whether any environment variable is set. For example, ```rust // Searches for "myapp" in the application and system paths first (aka Windows native behaviour). Command::new("myapp").spawn(); // Search for "myapp" in `PATH` first Command::new("myapp").env("a", "b").spawn(); ``` This is a bug because the search path should only change if `PATH` is changed for the child (i.e. `.env("PATH", "...")`). This was discussed in a libs-api meeting where the exact semantics of `Command::new` was not decided but there seemed to be broad agreement that this particular thing is just a bug that can be fixed. r? libs-api
2025-02-26Rollup merge of #137620 - SergioGasquez:fix/espidf-maybeunit, r=ChrisDentonLeón Orell Valerian Liehr-1/+1
Fix `attr` cast for espidf https://github.com/rust-lang/rust/pull/136826 broke ESP-IDF builds with: https://github.com/esp-rs/esp-idf-template/actions/runs/13516221587/job/37765336588. This PR fixes it. cc: ``@ivmarkov`` ``@xizheyin``
2025-02-26Fix Windows `Command` search path bugChris Denton-1/+2
2025-02-26Rollup merge of #137154 - thaliaarchi:wtf8-fast-paths, r=ChrisDentonLeón Orell Valerian Liehr-2/+2
Add UTF-8 validation fast paths in `Wtf8Buf` This adds two more fast paths for UTF-8 validation in `Wtf8Buf`, making use of the `is_known_utf8` flag added in https://github.com/rust-lang/rust/pull/96869 (Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8). r? `@ChrisDenton`
2025-02-25fix: attr cast for espidfSergio Gasquez-1/+1
2025-02-24Rollup merge of #137349 - thaliaarchi:io-optional-methods/zkvm, r=NoratriebTrevor Gross-1/+9
Implement `read_buf` for zkVM stdin For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See https://github.com/risc0/risc0/issues/2853. cc `@bobbobbio,` `@flaub` r? `@Noratrieb` Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-23Win: use existing wrappers for `SetFileInformationByHandle` in ↵Dennis Duda-25/+11
`File::open_native`
2025-02-23Rollup merge of #136826 - xizheyin:issue-136737, r=thomccJacob Pratt-26/+45
Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in Unix As discussion in #136737. - Replace `mem::zeroed()` with `MaybeUninit::uninit()` for `sockaddr_storage` in `accept()` and `recvfrom()` since these functions fill in the address structure - Replace `mem::zeroed()` with `MaybeUninit::uninit()` for `pthread_attr_t` in thread-related functions since `pthread_attr_init()` initializes the structure - Add references to man pages to document this behavior
2025-02-23[illumos] attempt to use posix_spawn to spawn processesRain-1/+16
illumos has `posix_spawn`, and the very newest versions also have `_addchdir`, so use that. This is a nice ~4x performance improvement for process creation. My go-to as usual is nextest against the clap repo, which acts as a stress test for process creation -- with [this commit]: ```console $ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)' before: Summary [ 1.747s] 879 tests run: 879 passed, 2 skipped after: Summary [ 0.445s] 879 tests run: 879 passed, 2 skipped ``` [this commit]: https://github.com/clap-rs/clap/commit/fde45f9aea766fb8de46e3d46e6575f393c3b6b9
2025-02-23Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3Matthias Krüger-2/+2
Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of https://github.com/rust-lang/rust/pull/135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in #135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in https://github.com/rust-lang/rust/pull/136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
2025-02-21Rollup merge of #137353 - thaliaarchi:io-optional-methods/wasi-stdin, ↵Matthias Krüger-1/+6
r=alexcrichton Implement `read_buf` for WASI stdin `WasiFd::read_buf` already exists. Simply use it in `Stdin`. cc `@alexcrichton` Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-21Replace some instances of `pub` with `pub(crate)`Trevor Gross-2/+2
The recent fixes to private dependencies exposed some cases in the UEFI module where private dependencies are exposed in a public interface. These do not need to be crate-public, so change them to `pub(crate)`.
2025-02-21Auto merge of #137192 - kornelski:windows-tls-lto, r=ChrisDentonbors-3/+1
Remove obsolete Windows ThinLTO+TLS workaround The bug #109797 has been fixed by #129079, so this workaround is no longer needed.
2025-02-20Implement read_buf for WASI stdinThalia Archibald-1/+6
2025-02-20Implement read_buf for zkVM stdinThalia Archibald-1/+9
For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See https://github.com/risc0/risc0/issues/2853.
2025-02-20Rollup merge of #137270 - QianNangong:master, r=ChrisDentonJubilee-8/+8
Fix `*-win7-windows-msvc` target since 26eeac1a1e9fe46ffd80dd0d3dafdd2c2a644306 That commit make it failed to build `std` with `*-win7-windows-msvc` so fix it.
2025-02-19Add fast path for displaying pre-validated Wtf8BufThalia Archibald-2/+2
2025-02-19Rollup merge of #137155 - thaliaarchi:wtf8-organize, r=ChrisDentonMatthias Krüger-74/+119
Organize `OsString`/`OsStr` shims Synchronize the `bytes.rs` and `wtf8.rs` shims for `OsString`/`OsStr` so they're easier to diff between each other. This is mostly ordering items the same between the two. I tried to minimize moves and went for the average locations between the files. With them in the same order, it is clear that `FromInner<_>` is not implemented for `bytes::Buf` and `Clone::clone_from` is not implemented for `wtf8::Buf`, but they are for the other. Fix that. I added #[inline] to all inherent methods of the `OsString`/`OsStr` shims, because it seemed that was already the rough pattern. `bytes.rs` has more inlining than `wtf8.rs`, so I added the corresponding ones to `wtf8.rs`. Then, the common missing ones have no discernible pattern to me. They're not divided by non-allocating/allocating. Perhaps the pattern is that UTF-8 validation isn't inlined? Since these types are merely the inner values in `OsStr`/`OsString`, I put inline on all methods and let those public types dictate inlining. I have not inspected codegen or run benchmarks. Also, touch up some (private) documentation comments. r? ``````@ChrisDenton``````
2025-02-19Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=m-ou-seMatthias Krüger-1/+2
Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants This pull request adds the `MAX_LEN_UTF8` and `MAX_LEN_UTF16` constants as per #45795, gated behind the `char_max_len` feature. The constants are currently applied in the `alloc`, `core` and `std` libraries.
2025-02-19fix by commentsxizheyin-21/+17
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-19Fix `*-win7-windows-msvc` target since 26eeac1a1e9fe46ffd80dd0d3dafdd2c2a644306Li Keqing-8/+8
2025-02-19remove assume_init in stack_overflowxizheyin-7/+9
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-17Remove obsolete MinGW ThinLTO+TLS workaroundKornel-3/+1
#109797 is fixed
2025-02-17Rollup merge of #137165 - thaliaarchi:file-tell, r=ChrisDentonMatthias Krüger-1/+28
Use `tell` for `<File as Seek>::stream_position` Some platforms have a more efficient way to get the current offset of the file than by seeking. For example, Wasi has `fd_tell` and SOLID has `SOLID_FS_Ftell`. Implement `<File as Seek>::stream_position()` in terms of those. I do not use any APIs that were not already used in `std`. Although, the `libc` crate has [`ftell`](https://docs.rs/libc/latest/libc/fn.ftell.html), [`ftello`](https://docs.rs/libc/latest/libc/fn.ftello.html), and [`ftello64`](https://docs.rs/libc/latest/libc/fn.ftello64.html), I do not know platform coverage. It appears that Windows has no `tell`-like API. I have checked that it builds on each relevant platform.
2025-02-17Use tell for <File as Seek>::stream_positionThalia Archibald-1/+28
2025-02-17Rollup merge of #136844 - thaliaarchi:const-io-error, r=ChrisDentonMatthias Krüger-99/+82
Use `const_error!` when possible Replace usages of `io::Error::new(io::ErrorKind::Variant, "constant string")` with `io::const_error!(io::ErrorKind::Variant, "constant string")` to avoid allocations when possible. Additionally, fix `&&str` error messages in SGX and missing/misplaced trailing commas in `const_error!`.
2025-02-16Synchronize platform adaptors for OsString/OsStrThalia Archibald-74/+119
* Order items as the average of the two adaptors. Enables easier diffs. * Consistently apply #[inline]. * Implement FromInner<Vec<u8>> for bytes::Buf. * Implement Clone::clone_from for wtf8::Buf.
2025-02-16Rollup merge of #136986 - ehuss:library-unsafe-fun, r=NoratriebMatthias Krüger-3/+3
Apply unsafe_op_in_unsafe_fn to the standard library This applies unsafe_op_in_unsafe_fn to the standard library in preparation for updating to Rust 2024. Closes https://github.com/rust-lang/rust/issues/127747 (I think?) cc ``@workingjubilee`` I have been testing a variety of targets, and I feel like they are all pretty much covered. I'll continue doing some testing async, but I don't expect to catch any more.
2025-02-16add MAX_LEN_UTF8 and MAX_LEN_UTF16 constantsHTGAzureX1212-1/+2
2025-02-15Auto merge of #137065 - jhpratt:rollup-ree9mej, r=jhprattbors-2739/+2772
Rollup of 9 pull requests Successful merges: - #135687 (re-export `FromCoroutine` from `core::iter`) - #135813 (CI: split i686-mingw job to three free runners) - #136749 (Implement Extend<AsciiChar> for String) - #136879 (Add safe new() to NotAllOnes) - #136978 (Windows: Update generated bindings) - #137028 (mir_build: Clarify some code for lowering `hir::PatExpr` to THIR) - #137029 (Remove unnecessary check code in unused_delims) - #137056 (made check_argument_compat public for use in miri) - #137062 (Forward all default methods for I/O impls) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-15Rollup merge of #136978 - ChrisDenton:windows-bindgen, r=AmanieuJacob Pratt-2734/+2770
Windows: Update generated bindings Update to windows-bindgen 0.59. This update is aimed at reducing churn in the future, but means a bit more churn now: - `bindings.txt` no longer needs us to write the namespace for each item. This is good because it means in the future we won't need to change them if the namespace changes. However, there are a few where we still need to disambiguate due to duplicate items (this is a bug in the upstream metadata). - The output in `windows-sys.rs` is now sorted. It was mostly sorted before but not intentionally. This should mean future changes are less noisy. The actual code changes are minimal here. A few types are now `bool` instead of `BOOLEAN`, which is more convenient.
2025-02-15Rollup merge of #136879 - kornelski:non1, r=NoratriebJacob Pratt-5/+2
Add safe new() to NotAllOnes Replaces duplicated `unsafe` code with a single, easier to verify implementation.
2025-02-15Auto merge of #136324 - GrigorenkoPV:erf, r=tgross35bors-0/+6
Implement `f{16,32,64,128}::{erf,erfc}` (`#![feature(float_erf)]`) Tracking issue: #136321 try-job: x86_64-gnu-aux