Commit Graph

7168 Commits

Author SHA1 Message Date
Matthias Krüger
867317835d
Rollup merge of #136288 - joshtriplett:would-you-could-you-with-some-locks--would-you-could-you-in-some-docs, r=m-ou-se
Improve documentation for file locking

Add notes to each method stating that locks get dropped on close.

Clarify the return values of the try methods: they're only defined if
the lock is held via a *different* file handle/descriptor. That goes
along with the documentation that calling them while holding a lock via
the *same* file handle/descriptor may deadlock.

Document the behavior of unlock if no lock is held.

r? `@m-ou-se`
(Documentation changes requested in https://github.com/rust-lang/rust/issues/130994 .)
2025-01-30 20:47:09 +01:00
Matthias Krüger
55c7a02a8b
Rollup merge of #135475 - Ayush1325:uefi-absolute-path, r=jhpratt
uefi: Implement path

This PR is split off from https://github.com/rust-lang/rust/pull/135368 to reduce noise.

UEFI paths can be of 4 types:
1. Absolute Shell Path: Uses shell mappings
2. Absolute Device Path: this is what we want
3. Relative root: path relative to the current root.
4. Relative

Absolute shell path can be identified with `:` and Absolute Device path can be identified with `/`. Relative root path will start with `\`.

The algorithm is mostly taken from edk2 UEFI shell implementation and is somewhat simple. Check for the path type in order.

For Absolute Shell path, use `EFI_SHELL->GetDevicePathFromMap` to get a BorrowedDevicePath for the volume.

For Relative paths, we use the current working directory to construct the new path.

BorrowedDevicePath abstraction is needed to interact with `EFI_SHELL->GetDevicePathFromMap` which returns a Device Path Protocol with the lifetime of UEFI shell.

Absolute Shell paths cannot exist if UEFI shell is missing.

cc `@nicholasbishop`
2025-01-30 20:47:04 +01:00
Josh Triplett
fb1ad2fe02 Improve documentation for file locking
Add notes to each method stating that locks get dropped on close.

Clarify the return values of the try methods: they're only defined if
the lock is held via a *different* file handle/descriptor. That goes
along with the documentation that calling them while holding a lock via
the *same* file handle/descriptor may deadlock.

Document the behavior of unlock if no lock is held.
2025-01-30 11:48:26 +01:00
bors
0cc4f4f7b8 Auto merge of #136248 - matthiaskrgr:rollup-leaxgfd, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #133382 (Suggest considering casting fn item as fn pointer in more cases)
 - #136092 (Test pipes also when not running on Windows and Linux simultaneously)
 - #136190 (Remove duplicated code in RISC-V asm bad-reg test)
 - #136192 (ci: remove unused windows runner)
 - #136205 (Properly check that array length is valid type during built-in unsizing in index)
 - #136211 (Update mdbook to 0.4.44)
 - #136212 (Tweak `&mut self` suggestion span)
 - #136214 (Make crate AST mutation accessible for driver callback)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-29 16:18:29 +00:00
Matthias Krüger
da7980b315
Rollup merge of #136092 - tbu-:pr_io_pipe_test, r=joboet
Test pipes also when not running on Windows and Linux simultaneously

Fixes https://github.com/rust-lang/rust/pull/135635#pullrequestreview-2574184488.

Based on top of #135635 to avoid merge conflicts.
2025-01-29 15:29:30 +01:00
León Orell Valerian Liehr
7e60f276ce
Rollup merge of #136186 - Ayush1325:uefi-process-args-fix, r=nicholasbishop,Noratrieb
uefi: process: Fix args

- While working on process env support, I found that args were currently broken. Not sure how I missed it in the PR, but well here is the fix.
- Additionally, no point in adding space at the end of args.
2025-01-29 06:03:25 +01:00
Ayush Singh
9c4fd25f27
uefi: process: Fix args
- While working on process env support, I found that args were currently
  broken. Not sure how I missed it in the PR, but well here is the fix.
- Additionally, no point in adding space at the end of args.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-01-28 19:10:28 +05:30
Matthias Krüger
9a192b254c
Rollup merge of #136012 - hkBst:patch-22, r=workingjubilee,tgross35
Document powf and powi values that are always 1.0

fixes bug #90429
2025-01-28 14:23:25 +01:00
Marijn Schouten
3d6c6fa04e Document powf and powi calls that always return 1.0 2025-01-28 08:24:39 +01:00
Guillaume Gomez
4d5c8bdc9d
Rollup merge of #135876 - usamoi:mpmc-doc, r=tgross35
fix doc for std::sync::mpmc

fix document of `std::sync::mpmc` (tracked in https://github.com/rust-lang/rust/issues/126840)
2025-01-27 15:38:25 +01:00
usamoi
05364239a8 fix doc for std::sync::mpmc 2025-01-27 11:42:16 +08:00
León Orell Valerian Liehr
2949f2a5ef
Rollup merge of #135635 - tbu-:pr_io_pipe, r=joboet
Move `std::io::pipe` code into its own file

Also update the docs for the new location, create a section "Platform-specific behavior", don't hide required imports for code examples.
2025-01-27 04:34:51 +01:00
bors
15c6f7e1a3 Auto merge of #136087 - jhpratt:rollup-tam1mzn, r=jhpratt
Rollup of 7 pull requests

Successful merges:

 - #133631 (Support QNX 7.1 with `io-sock`+libstd and QNX 8.0 (`no_std` only))
 - #134358 (compiler: Set `target_abi = "ilp32e"` on all riscv32e targets)
 - #135812 (Fix GDB `OsString` provider on Windows )
 - #135842 (TRPL: more backward-compatible Edition changes)
 - #135946 (Remove extra whitespace from rustdoc breadcrumbs for copypasting)
 - #135953 (ci.py: check the return code in `run-local`)
 - #136019 (Add an `unchecked_div` alias to the `Div<NonZero<_>>` impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-26 12:10:05 +00:00
Tobias Bucher
93d347d7d2 Test pipes also when not running on Windows and Linux simultaneously
Fixes https://github.com/rust-lang/rust/pull/135635#pullrequestreview-2574184488.
2025-01-26 12:48:33 +01:00
Tobias Bucher
ad28cbb423 Update std::io::{pipe, PipeReader, PipeWriter} docs the new location
Also create a section "Platform-specific behavior", don't hide required
imports for code examples.
2025-01-26 12:42:52 +01:00
Tobias Bucher
68e983fcf7 Move std::io::pipe code into its own file 2025-01-26 12:40:36 +01:00
Jacob Pratt
0d0e841594
Rollup merge of #133631 - flba-eb:add_nto_qnx71_iosock_support, r=workingjubilee
Support QNX 7.1 with `io-sock`+libstd and QNX 8.0 (`no_std` only)

Changes of this pull request:

1. Refactor code for qnx nto targets to share more code in file `nto_qnx.rs`
1. Add support for an additional network stack on nto qnx 7.1.

   QNX 7.1 supports two network stacks:

   1. `io-pkt`, which is default
   2. `io-sock`, which is optional on 7.1 but default in QNX 8.0

   As one can see in the [io-sock migration notes](https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.io_sock/topic/migrate_app.html), this changes the libc API in a way similar to e.g. linux-gnu vs. linux-musl.

   This change adds a new target which has a different value for `target_env`, so that e.g. libc can distinguish between both APIs.

2. Add initial support for QNX 8.0, thanks to AkhilTThomas. As it turned out, the problem with forking many processes still exists in QNX 8.0. Because if this, we are now using it for any QNX version (i.e. not check for `target_env` anymore).
2025-01-26 01:51:14 -05:00
Jacob Pratt
b58221ec9d
Rollup merge of #135948 - bjorn3:update_emscripten_std_tests, r=Mark-Simulacrum
Update emscripten std tests

This disables a bunch of emscripten tests that test things emscripten doesn't support and re-enables a whole bunch of tests which now work just fine on emscripten.

Tested with `EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" ./x.py test library/ --target wasm32-unknown-emscripten`.
2025-01-25 23:27:00 -05:00
Josh Triplett
687607c31e Improve and expand documentation of pipes
- Simplify some of the language
- Minor grammar fixes
- Don't imply that pipes *only* work across multiple processes; instead,
  *suggest* that they're typically used across two or more separate
  processes.
- Specify that portable applications cannot use multiple readers or
  multiple writers for messages larger than a byte, due to potential
  interleaving.
- Remove no-longer-referenced footnote URLs.
2025-01-25 22:15:54 +02:00
Matthias Krüger
7a79024ef4
Rollup merge of #135991 - no1wudi:master, r=thomcc
Fix set_name in thread mod for NuttX

Replace `pthread_set_name_np` with `pthread_setname_np` for NuttX in the `set_name` function, this change aligns the implementation with the correct API available on NuttX

This patch ensures thread naming works correctly on NuttX platforms.

See also:
0f9f8c91ad/src/unix/nuttx/mod.rs (L562)
8f3a2a6f76/include/pthread.h (L511-L514)
2025-01-25 08:03:35 +01:00
Matthias Krüger
0741cc0ea7
Rollup merge of #135415 - Harshit933:hard-link-error, r=ChrisDenton
Add `File already exists` error doc to `hard_link` function

## Description
If the link path already exists, the error `AlreadyExists` is returned. This commit adds this error to the docs.

I tested it with the current rust master version, this error was returned when there is already a link for the file is present.
This was the error returned:
```
[harshit:../Desktop/rust_compiler_testing/hard_link (master|…5)] cargo +stage1 run
   Compiling hard_link v0.1.0 (/home/harshit/Desktop/rust_compiler_testing/hard_link)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/hard_link`
Err(Os { code: 17, kind: AlreadyExists, message: "File exists" })
```
This is my first PR on rust, any suggestions on which issue I can take next are most welcome 😄

Fixes #130117
2025-01-24 23:25:41 +01:00
Harshit Verma
ab274630b9 Add File already exists error doc to hard_link function
If the link path already exists, the error `AlreadyExists`
is returned. This commit adds this error to the docs.
2025-01-24 22:43:33 +05:30
Huang Qi
e170c9dec0 Fix set_name in thread mod for NuttX
Replace `pthread_set_name_np` with `pthread_setname_np` for NuttX in the `set_name` function,
this change aligns the implementation with the correct API available on NuttX

This patch ensures thread naming works correctly on NuttX platforms.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-24 21:21:30 +08:00
AkhilTThomas
3f045c9d2e add nto80 x86-64 and aarch64 target
Signed-off-by: Florian Bartels <Florian.Bartels@elektrobit.com>
2025-01-24 12:41:49 +00:00
Florian Bartels
efe53ddd58 Add support for QNX 7.1 with io-sock on x64
Signed-off-by: Florian Bartels <Florian.Bartels@elektrobit.com>
2025-01-24 12:32:20 +00:00
Florian Bartels
84c80151cf Add new target for supporting Neutrino QNX 6.1 with io-socket network stack on aarch64
Signed-off-by: Florian Bartels <Florian.Bartels@elektrobit.com>
2025-01-24 12:32:07 +00:00
bjorn3
a20996c180 Update a bunch of comments from before wasi support was added 2025-01-24 09:25:34 +00:00
bjorn3
88ff147c56 Remove a bunch of emscripten test ignores
They are either outdated as emscripten now supports i128 or they are
subsumed by #[cfg_attr(not(panic = "unwind"), ignore]
2025-01-24 09:25:34 +00:00
bjorn3
d0a70d9328 Fix testing of the standard library with Emscripten
This does need EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" avoid several OOMs.
2025-01-24 09:25:34 +00:00
Matthias Krüger
08d5b2303a
Rollup merge of #135073 - joshtriplett:bstr, r=BurntSushi
Implement `ByteStr` and `ByteString` types

Approved ACP: https://github.com/rust-lang/libs-team/issues/502
Tracking issue: https://github.com/rust-lang/rust/issues/134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`,
when those would be the second implementation for a type (counting the
`T` impl), to avoid potential inference failures. We can attempt to add
more impls later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (`@BurntSushi).`

r? `@BurntSushi`
2025-01-23 19:54:23 +01:00
Matthias Krüger
3962bfaeed
Rollup merge of #135856 - fmease:library-mv-obj-save-dyn-compat-ii, r=tgross35
Library: Finalize dyn compatibility renaming

Update the Reference link to use the new URL fragment from https://github.com/rust-lang/reference/pull/1666 (this change has finally hit stable). Fixes a FIXME.

Follow-up to #130827.
Part of #130852.
2025-01-22 20:37:28 +01:00
Matthias Krüger
0bdc1015cc
Rollup merge of #135837 - ChrisDenton:trunc, r=Noratrieb
Remove test panic from File::open

Fixes #135831
2025-01-22 20:37:27 +01:00
León Orell Valerian Liehr
9e98d25729
Library: Finalize dyn compatibility renaming 2025-01-22 04:46:55 +01:00
Chris Denton
fed5f98c47
Remove test panic from File::open 2025-01-21 17:31:17 +00:00
Marijn Schouten
fdc80af5c5
fix OsString::from_encoded_bytes_unchecked description 2025-01-21 14:36:18 +01:00
bors
b605c65b6e Auto merge of #135224 - wyfo:tls-panic-outline, r=cuviper
Outline panicking code for `LocalKey::with`

See https://github.com/rust-lang/rust/pull/115491 for prior related modifications.

https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
2025-01-21 02:23:15 +00:00
许杰友 Jieyou Xu (Joe)
e7f53663de
Rollup merge of #135626 - clubby789:env-note, r=ibraheemdev
doc: Point to methods on `Command` as alternatives to `set/remove_var`

Make these methods more discoverable, as configuring a child process is a common reason for manipulating the environment.
2025-01-20 21:45:04 +08:00
许杰友 Jieyou Xu (Joe)
e1e26f339d
Rollup merge of #135491 - RalfJung:remove-dead-rustc_allowed_through_unstable_modules, r=Mark-Simulacrum
Remove dead rustc_allowed_through_unstable_modules for std::os::fd contents

As far as I was able to reconstruct, the history here is roughly as follows:
- https://github.com/rust-lang/rust/pull/99723 added some `rustc_allowed_through_unstable_modules` to the types in `std::os::fd::raw` since they were accessible on stable via the unstable `std::os::wasi::io::AsRawFd` path. (This was needed to fix https://github.com/rust-lang/rust/issues/99502.)
- Shortly thereafter, https://github.com/rust-lang/rust/pull/98368 re-organized things so that instead of re-exporting from an internal  `std::os::wasi::io::raw`,   `std::os::wasi::io::AsRawFd` is now directly re-exported from `std::os::fd`. This also made `library/std/src/os/wasi/io/raw.rs` entirely dead code as far as I can tell, it's not imported by anything any more.
- Shortly thereafter, https://github.com/rust-lang/rust/pull/103308 stabilizes `std::os::wasi::io`, so `rustc_allowed_through_unstable_modules` is not needed any more to access `std::os::wasi::io::AsRawFd`. There is even a comment in `library/std/src/os/wasi/io/raw.rs` saying the attribute can be removed now, but that file is dead code so it is not touched as part of the stabilization.

I did a grep for `pub use crate::os::fd` and all the re-exports I could find are in stable modules. So given all that, we can remove the  `rustc_allowed_through_unstable_modules` (hoping they are not also re-exported somewhere else, it's really hard to be sure about this).

I have checked that std still builds after this PR on the wasm32-wasip2 target.
2025-01-20 12:38:32 +08:00
许杰友 Jieyou Xu (Joe)
e5b85035fe
Rollup merge of #135446 - klensy:panic_immediate_abort_ext, r=Mark-Simulacrum
further improve panic_immediate_abort by removing rtprintpanic! messages

Reduces binary size using `panic_immediate_abort` by removing strings used by `rtprintpanic!`.

for `main.rs`
```rust
fn main() {
    println!("Hello, world!");
}
```
with `Cargo.toml`
```toml
[package]
name = "tst"
version = "0.1.0"
edition = "2024"

[dependencies]

[profile.release]
lto = true
codegen-units = 1
panic = "abort"

```

and build with `RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" cargo +stage-1 b -r -Z build-std=std,panic_abort -Z build-std-features=optimize_for_size,panic_immediate_abort` for `x86_64-unknown-linux-gnu`

This reduces size:
| before |  after | type |
| - | - | - |
| 25256 | 21880 | unstripped |
| 18072 | 15288 | stripped |
2025-01-20 12:38:32 +08:00
Matthias Krüger
23fb4f22b3
Rollup merge of #135661 - tgross35:stabilize-float_next_up_down, r=scottmcm
Stabilize `float_next_up_down`

FCP completed at [1].

For `f16` and `f128`, this just removes the gates in comments and doctests.

Closes https://github.com/rust-lang/rust/issues/91399

[1]: https://github.com/rust-lang/rust/issues/91399#issuecomment-2598734570
2025-01-18 13:58:06 +01:00
Matthias Krüger
508c72b81e
Rollup merge of #135583 - NobodyXu:move-pipe-to-io, r=joshtriplett
Move `std::pipe::*` into `std::io`

Resolve concern from final comment period https://github.com/rust-lang/rust/issues/127154#issuecomment-2590419895
2025-01-18 13:58:03 +01:00
Trevor Gross
366cecacdd Stabilize float_next_up_down
FCP completed at [1].

Closes https://github.com/rust-lang/rust/issues/91399

[1]: https://github.com/rust-lang/rust/issues/91399#issuecomment-2598734570
2025-01-17 23:01:10 +00:00
Jiahao XU
81d70f92ab
Fix import of pipe in kernel_copy.rs
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-18 00:44:44 +11:00
clubby789
f7c2d1194d doc: Point to methods on Command as alternatives to set/remove_var 2025-01-17 12:53:58 +00:00
Matthias Krüger
dbbbed0579
Rollup merge of #135556 - AeonSolstice:patch-1, r=tgross35
Clarify note in `std::sync::LazyLock` example

I doubt most people know what it means, as I did not until a week ago. In the current form, it seems like a `TODO:`.
2025-01-16 17:00:47 +01:00
Jiahao XU
efe888871c
Move std::pipe::* into std::io
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-17 01:30:05 +11:00
Ayush Singh
c1790b14bc
uefi: Implement path
UEFI paths can be of 4 types:
1. Absolute Shell Path: Uses shell mappings
2. Absolute Device Path: this is what we want
3: Relative root: path relative to the current root.
4: Relative

Absolute shell path can be identified with `:` and Absolute Device path
can be identified with `/`. Relative root path will start with `\`.

The algorithm is mostly taken from edk2 UEFI shell implementation and is
somewhat simple. Check for the path type in order.

For Absolute Shell path, use `EFI_SHELL->GetDevicePathFromMap` to
get a BorrowedDevicePath for the volume.

For Relative paths, we use the current working directory to construct
the new path.

BorrowedDevicePath abstraction is needed to interact with
`EFI_SHELL->GetDevicePathFromMap` which returns a Device Path Protocol
with the lifetime of UEFI shell.

Absolute Shell paths cannot exist if UEFI shell is missing.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-01-16 10:19:22 +05:30
Aeon
c4a5e12567
Clarify note in std::sync::LazyLock example 2025-01-15 16:08:22 -05:00
Guillaume Gomez
4c26dc5d3d
Rollup merge of #132654 - joboet:lazy_main, r=ChrisDenton
std: lazily allocate the main thread handle

https://github.com/rust-lang/rust/pull/123550 eliminated the allocation of the main thread handle, but at the cost of greatly increased complexity. This PR proposes another approach: Instead of creating the main thread handle itself, the runtime simply remembers the thread ID of the main thread. The main thread handle is then only allocated when it is used, using the same lazy-initialization mechanism as for non-runtime use of `thread::current`, and the `name` method uses the thread ID to identify the main thread handle and return the correct name ("main") for it.

Thereby, we also allow accessing `thread::current` before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from `name` will only be "main" after the runtime initialization code has run, but I think that is acceptable.

This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).

Reverts #123550, CC ``@GnomedDev``
2025-01-15 16:30:08 +01:00
Jacob Pratt
56eb7bd9a9
Rollup merge of #134678 - zachs18:offset-ptr-update, r=tgross35
Update `ReadDir::next` in `std::sys::pal::unix::fs` to use `&raw const (*p).field` instead of `p.byte_offset().cast()`

Since https://github.com/rust-lang/reference/pull/1387 and https://github.com/rust-lang/rust/pull/117572, `&raw mut (*p).field`/`addr_of!((*p).field)` is defined to have the same inbounds preconditions as `ptr::offset`/`ptr::byte_offset`. I.e. `&raw const (*p).field` does not require that `p: *const T` point to a full `size_of::<T>()` bytes of memory, only that `p.byte_add(offset_of!(T, field))` is defined.

The old comment "[...] we don't even get to use `&raw const (*entry_ptr).d_name` because that operation requires the full extent of *entry_ptr to be in bounds of the same allocation, which is not necessarily the case here [...]" is now outdated, and the code can be simplified to use `&raw const (*entry_ptr).field`.

-------

There should be no behavior differences from this PR.

The `: *const dirent64` on line 716 and the `const _: usize = mem::offset_of!(dirent64, $field);` and comment on lines 749-751 are just sanity checks and should not affect semantics.

Since the `offset_ptr!` macro is only called three times, and all with the same local variable entry_ptr, I just used the local variable directly in the macro instead of taking it as an input, and renamed the macro to `entry_field_ptr!`.

The whole macro could also be removed and replaced with just using `&raw const (*entry_ptr).field`  in the three places, but the comments on the macro seemed worthwhile to keep.
2025-01-15 04:08:12 -05:00