about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2022-07-31Auto merge of #78802 - faern:simplify-socketaddr, r=joshtriplettbors-247/+172
Implement network primitives with ideal Rust layout, not C system layout This PR is the result of this internals forum thread: https://internals.rust-lang.org/t/why-are-socketaddrv4-socketaddrv6-based-on-low-level-sockaddr-in-6/13321. Instead of basing `std:::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}` on system (C) structs, they are encoded in a more optimal and idiomatic Rust way. This changes the public API of std by introducing structural equality impls for all four types here, which means that `match ipv4addr { SOME_CONSTANT => ... }` will now compile, whereas previously this was an error. No other intentional changes are introduced to public API. It's possible to observe the current layout of these types (e.g., by pointer casting); most but not all libraries which were found by Crater to do this have had updates issued and affected versions yanked. See report below. ### Benefits of this change - It will become possible to move these fundamental network types from `std` into `core` ([RFC](https://github.com/rust-lang/rfcs/pull/2832)). - Some methods that can't be made `const fn`s today can be made `const fn`s with this change. - `SocketAddrV4` only occupies 6 bytes instead of 16 bytes. - These simple primitives become easier to read and uses less `unsafe`. - Makes these types support structural equality, which means you can now (for instance) match an `Ipv4Addr` against a constant ### ~Remaining~ Previous problems This change obviously changes the memory layout of the types. And it turns out some libraries invalidly assumes the memory layout and does very dangerous pointer casts to convert them. These libraries will have undefined behaviour and perform invalid memory access until patched. - [x] - `mio` - Issue: https://github.com/tokio-rs/mio/issues/1386. - [x] `0.7` branch https://github.com/tokio-rs/mio/pull/1388 - [x] `0.7.6` published https://github.com/tokio-rs/mio/pull/1398 - [x] Yank all `0.7` versions older than `0.7.6` - [x] Report `<0.7.6` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0081.html - [x] - `socket2` - Issue: https://github.com/rust-lang/socket2-rs/issues/119. - [x] `0.3.x` branch https://github.com/rust-lang/socket2-rs/pull/120 - [x] `0.3.16` published - [x] `master` branch https://github.com/rust-lang/socket2-rs/pull/122 - [x] Yank all `0.3` versions older than `0.3.16` - [x] Report `<0.3.16` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0079.html - [x] - `net2` - Issue: https://github.com/deprecrated/net2-rs/issues/105 - [x] https://github.com/deprecrated/net2-rs/pull/106 - [x] `0.2.36` published - [x] Yank all `0.2` versions older than `0.2.36` - [x] Report `<0.2.36` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0078.html - [x] - `miow` - Issue: https://github.com/yoshuawuyts/miow/issues/38 - [x] `0.3.x` - https://github.com/yoshuawuyts/miow/pull/39 - [x] `0.3.6` published - [x] `0.2.x` - https://github.com/yoshuawuyts/miow/pull/40 - [x] `0.2.2` published - [x] Yanked all `0.2` versions older than `0.2.2` - [x] Yanked all `0.3` versions older than `0.3.6` - [x] Report `<0.2.2` and `<0.3.6` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0080.html - [x] - `quinn master` (aka what became 0.7) - https://github.com/quinn-rs/quinn/issues/968 https://github.com/quinn-rs/quinn/pull/987 - [x] - `quinn 0.6` - https://github.com/quinn-rs/quinn/pull/1045 - [x] - `quinn 0.5` - https://github.com/quinn-rs/quinn/pull/1046 - [x] - Release `0.7.0`, `0.6.2` and `0.5.4` - [x] - `nb-connect` - https://github.com/smol-rs/nb-connect/issues/1 - [x] - Release `1.0.3` - [x] - Yank all versions older than `1.0.3` - [x] - `shadowsocks-rust` - https://github.com/shadowsocks/shadowsocks-rust/issues/462 - [ ] - `rio` - https://github.com/spacejam/rio/issues/44 - [ ] - `seaslug` - https://github.com/spacejam/seaslug/issues/1 #### Fixed crate versions All crates I have found that assumed the memory layout have been fixed and published. The crates and versions that will continue working even as/if this PR is merged is (please upgrade these to help unblock this PR): * `net2 0.2.36` * `socket2 0.3.16` * `miow 0.2.2` * `miow 0.3.6` * `mio 0.7.6` * `mio 0.6.23` - Never had the invalid assumption itself, but has now been bumped to only allow fixed dependencies (`net2` + `miow`) * `nb-connect 1.0.3` * `quinn 0.5.4` * `quinn 0.6.2` ### Release notes draft This release changes the memory layout of `Ipv4Addr`, `Ipv6Addr`, `SocketAddrV4` and `SocketAddrV6`. The standard library no longer implements these as the corresponding `libc` structs (`sockaddr_in`, `sockaddr_in6` etc.). This internal representation was never exposed, but some crates relied on it anyway by unsafely transmuting. This change will cause those crates to make invalid memory accesses. Notably `net2 <0.2.36`, `socket2 <0.3.16`, `mio <0.7.6`, `miow <0.3.6` and a few other crates are affected. All known affected crates have been patched and have had fixed versions published over a year ago. If any affected crate is still in your dependency tree, you need to upgrade them before using this version of Rust.
2022-07-31Fix compat.rs for `cfg(miri)`Chris Denton-1/+1
2022-07-31Auto merge of #99553 - ChrisDenton:lazy-compat-fn, r=Mark-Simulacrumbors-64/+205
Rewrite Windows `compat_fn` macro 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. This is optimized for the common case where a function is used after already being loaded (or failed to load). The only change in codegen at the call site is to use an atomic load instead of a plain load, which should have negligible or no impact. I've split the old `compat_fn` macro in two so as not to mix two different use cases. If/when Windows 7 support is dropped `compat_fn_optional` can be removed entirely. r? rust-lang/libs
2022-07-30Fix warnings in stubbed out set_timesJosh Triplett-4/+5
2022-07-30Original branch seems to have missed excluding the benchmark range from the ↵Christopher Hotchkiss-8/+3
globally reachable change
2022-07-30Reincorporated changes from #87689Christopher Hotchkiss-7/+2
2022-07-30Change `Ipv4Addr::is_global` to be in line with `Ipv6Addr::is_global`Christiaan Dirkx-59/+60
Rebasing off master
2022-07-30Fix `Ipv6Addr::is_global` to check for global reachability rather than ↵Christiaan Dirkx-27/+168
global scope
2022-07-30Reset directory iteration in remove_dir_allChris Denton-1/+3
2022-07-30Remove socklen_t from platforms where it's no longer usedLinus Färnstrand-6/+0
2022-07-27Allow using stable os::fd::raw items through unstable os::wasi modulebstrie-0/+19
This fixes a regression from stable to nightly. Closes #99502.
2022-07-27Auto merge of #98748 - saethlin:optimize-bufreader, r=Mark-Simulacrumbors-53/+134
Remove some redundant checks from BufReader The implementation of BufReader contains a lot of redundant checks. While any one of these checks is not particularly expensive to execute, especially when taken together they dramatically inhibit LLVM's ability to make subsequent optimizations by confusing data flow increasing the code size of anything that uses BufReader. In particular, these changes have a ~2x increase on the benchmark that this adds a `black_box` to. I'm adding that `black_box` here just in case LLVM gets clever enough to remove the reads entirely. Right now it can't, but these optimizations are really setting it up to do so. We get this optimization by factoring all the actual buffer management and bounds-checking logic into a new module inside `bufreader` with a new `Buffer` type. This makes it much easier to ensure that we have correctly encapsulated the management of the region of the buffer that we have read bytes into, and it lets us provide a new faster way to do small reads. `Buffer::consume_with` lets a caller do a read from the buffer with a single bounds check, instead of the double-check that's required to use `buffer` + `consume`. Unfortunately I'm not aware of a lot of open-source usage of `BufReader` in perf-critical environments. Some time ago I tweaked this code because I saw `BufReader` in a profile at work, and I contributed some benchmarks to the `bincode` crate which exercise `BufReader::buffer`. These changes appear to help those benchmarks at little, but all these sorts of benchmarks are kind of fragile so I'm wary of quoting anything specific.
2022-07-27Fix futex module imports on wasm+atomicssandydoo-2/+4
2022-07-27Rollup merge of #98583 - joshtriplett:stabilize-windows-symlink-types, r=thomccYuki Okushi-5/+9
Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file` These calls allow detecting whether a symlink is a file or a directory, a distinction Windows maintains, and one important to software that wants to do further operations on the symlink (e.g. removing it).
2022-07-26Add Buffer::consume_with to enable direct buffer access with one checkBen Kimock-3/+18
2022-07-26Rollup merge of #99716 - sourcelliu:iomut, r=Mark-SimulacrumMatthias Krüger-4/+4
remove useless mut from examples remove useless mut from examples
2022-07-26Rewrite Windows `compat_fn` macroChris Denton-64/+205
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-26Rollup merge of #98211 - devnexen:get_path_freebsd, r=Mark-SimulacrumYuki Okushi-0/+14
Implement `fs::get_path` for FreeBSD. Using `F_KINFO` fcntl flag, the kf_structsize field needs to be set beforehand for that effect.
2022-07-25Add comments about stdout lockingsigaloid-0/+22
2022-07-25Implement `fs::get_path` for FreeBSD.David CARLIER-0/+14
Using `F_KINFO` fcntl flag, the kf_structsize field needs to be set beforehand for that effect.
2022-07-25Rollup merge of #95916 - solid-rs:feat-kmc-solid-abort, r=Mark-SimulacrumYuki Okushi-45/+5
kmc-solid: Use `libc::abort` to abort a program This PR updates the target-specific abort subroutine for the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. The current implementation uses a `hlt` instruction, which is the most direct way to notify a connected debugger but is not the most flexible way. This PR changes it to call the `abort` libc function, making it possible for a system designer to override its behavior as they see fit.
2022-07-25Rollup merge of #95040 - frank-king:fix/94981, r=Mark-SimulacrumYuki Okushi-0/+20
protect `std::io::Take::limit` from overflow in `read` Resolves #94981
2022-07-25remove useless mut from examplessourcelliu-4/+4
2022-07-24Rename and document the new BufReader internalsBen Kimock-29/+33
2022-07-24Allow Buffer methods to inlineBen Kimock-0/+9
2022-07-24Remove some redundant checks from BufReaderBen Kimock-53/+106
The implementation of BufReader contains a lot of redundant checks. While any one of these checks is not particularly expensive to execute, especially when taken together they dramatically inhibit LLVM's ability to make subsequent optimizations.
2022-07-23Remove `mut`Phosra-1/+1
2022-07-23Auto merge of #97925 - the8472:cgroupv1, r=joshtriplettbors-47/+196
Add cgroupv1 support to available_parallelism Fixes #97549 My dev machine uses cgroup v2 so I was only able to test that code path. So the v1 code path is written only based on documentation. I could use some help testing that it works on a machine with cgroups v1: ``` $ x.py build --stage 1 # quota.rs fn main() { println!("{:?}", std::thread::available_parallelism()); } # assuming stage1 is linked in rustup $ rust +stage1 quota.rs # spawn a new cgroup scope for the current user $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS # should print Ok(3) $ ./quota ``` If it doesn't work as expected an strace, the contents of `/proc/self/cgroups` and the structure of `/sys/fs/cgroups` would help.
2022-07-22[review] mention that runtime may scale with # of mountpointsthe8472-0/+5
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-07-22Recover error strings on Unix from_lossy_utf8Jubilee Young-1/+3
Some language settings can result in unreliable UTF-8 being produced. This can result in failing to emit the error string, panicking instead. from_lossy_utf8 allows us to assume these strings usually will be fine.
2022-07-22Stub out `set_times` to return unsupported on RedoxJosh Triplett-2/+13
Redox doesn't appear to support `UTIME_OMIT`, so we can't set file times individually.
2022-07-21Rollup merge of #99523 - cuviper:asfd_ptrs-1.64, r=jyn514Matthias Krüger-2/+2
Fix the stable version of `AsFd for Arc<T>` and `Box<T>` These merged in #97437 for 1.64.0, apart from the main `io_safety` feature that stabilized in 1.63.0.
2022-07-21Rollup merge of #98707 - joboet:fuchsia_locks, r=m-ou-seMatthias Krüger-64/+256
std: use futex-based locks on Fuchsia This switches `Condvar` and `RwLock` to the futex-based implementation currently used on Linux and some BSDs. Additionally, `Mutex` now has its own, priority-inheriting implementation based on the mutex in Fuchsia's `libsync`. It differs from the original in that it panics instead of aborting when reentrant locking is detected. ````@rustbot```` ping fuchsia r? ````@m-ou-se````
2022-07-21remove unused importjoboet-1/+1
2022-07-20Fix the stable version of `AsFd for Arc<T>` and `Box<T>`Josh Stone-2/+2
These merged in #97437 for 1.64.0, apart from the main `io_safety` feature that stabilized in 1.63.0.
2022-07-20owner is not micro (correct typo)joboet-1/+1
2022-07-20Rollup merge of #98101 - vladimir-ea:stdlib_watch_os, r=thomccDylan DPC-25/+71
stdlib support for Apple WatchOS This is a follow-up to https://github.com/rust-lang/rust/pull/95243 (Add Apple WatchOS compiler targets) that adds stdlib support for Apple WatchOS. `@deg4uss3r` `@nagisa`
2022-07-20Library changes for Apple WatchOSVladimir Michael Eatwell-25/+71
2022-07-20Rollup merge of #98916 - ChrisDenton:hiberfil.sys, r=thomccDylan DPC-26/+99
Windows: Use `FindFirstFileW` for getting the metadata of locked system files Fixes #96980 Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory. Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI. r? rust-lang/libs
2022-07-19Improve the function pointer docsMichael Howell-10/+50
* Reduce duplicate impls; show only the `fn (T)` and include a sentence saying that there exists up to twelve of them. * Show `Copy` and `Clone`. * Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.
2022-07-18Ignore `hiberfil_sys` test in CIChris Denton-1/+4
The file it's testing does not exist in the CI environment.
2022-07-18std: panic instead of deadlocking in mutex implementation on Fuchsiajoboet-16/+15
2022-07-17rustdoc: extend `#[doc(tuple_variadic)]` to fn pointersMichael Howell-2/+2
The attribute is also renamed `fake_variadic`.
2022-07-17Simplify Windows `hashmap_random_keys`Chris Denton-60/+8
2022-07-17Move SocketAddrCRepr to sys_commonLinus Färnstrand-31/+35
2022-07-17Rollup merge of #99302 - yaahc:gma-tracking-issue, r=joshtriplettYuki Okushi-8/+8
add tracking issue to generic member access APIs Missed as part of https://github.com/rust-lang/rust/pull/98072
2022-07-17Rollup merge of #99088 - niklasf:stabilize-process_set_process_group, ↵Yuki Okushi-3/+30
r=joshtriplett Document and stabilize process_set_process_group Tracking issue: https://github.com/rust-lang/rust/issues/93857 FCP finished here: https://github.com/rust-lang/rust/issues/93857#issuecomment-1179551697
2022-07-17Rollup merge of #97915 - tbu-:pr_os_string_fmt_write, r=joshtriplettYuki Okushi-0/+8
Implement `fmt::Write` for `OsString` This allows to format into an `OsString` without unnecessary allocations. E.g. ``` let mut temp_filename = path.into_os_string(); write!(&mut temp_filename, ".tmp.{}", process::id()); ```
2022-07-16Stabilize `let_chains`Caio-1/+1
2022-07-16Expand documentation for `process_group` Josh Triplett-1/+3
Explain PGID 0, and provide the acronym PGID.