about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2022-08-16Refactor copying data to userspaceRaoul Strackx-19/+32
2022-08-15Auto merge of #100007 - ChrisDenton:dtor-inline-never, r=michaelwoeristerbors-0/+4
Never inline Windows dtor access Inlining can cause problem If used in a Rust dylib. See #44391. r? `@Mark-Simulacrum`
2022-08-14Rollup merge of #100249 - Meziu:master, r=joshtriplettMatthias Krüger-5/+5
Fix HorizonOS regression in FileTimes The changes in #98246 caused a regression for multiple Newlib-based systems. This is just a fix including HorizonOS to the list of targets which require a workaround. ``@AzureMarker`` ``@ian-h-chamberlain`` r? ``@nagisa``
2022-08-13created tcpstream quickack traitBerend-Jan Lange-0/+11
for linux and android
2022-08-12Rollup merge of #100030 - WaffleLapkin:nice_pointer_sis, r=scottmcmDylan DPC-4/+5
cleanup code w/ pointers in std a little Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
2022-08-12Auto merge of #99624 - vincenzopalazzo:macros/unix_error, r=Amanieubors-2/+6
promote debug_assert to assert when possible and useful This PR fixed a very old issue https://github.com/rust-lang/rust/issues/94705 to clarify and improve the POSIX error checking, and some of the checks are skipped because can have no benefit, but I'm sure that this can open some interesting discussion. Fixes https://github.com/rust-lang/rust/issues/94705 cc: `@tavianator` cc: `@cuviper`
2022-08-11Rollup merge of #100203 - compiler-errors:command-args-size-hint, r=m-ou-seMatthias Krüger-0/+3
provide correct size hint for unsupported platform `CommandArgs` Split from https://github.com/rust-lang/rust/pull/99880#discussion_r932994172
2022-08-11Rollup merge of #99421 - Bryanskiy:android-crt-static, r=petrochenkovMatthias Krüger-2/+4
add crt-static for android
2022-08-11Rollup merge of #100287 - cuviper:no-linux-prctl, r=Mark-SimulacrumDylan DPC-3/+9
linux: Use `pthread_setname_np` instead of `prctl` This function is available on Linux since glibc 2.12, musl 1.1.16, and uClibc 1.0.20. The main advantage over `prctl` is that it properly represents the pointer argument, rather than a multi-purpose `long`, so we're better representing strict provenance (#95496).
2022-08-11promote debug_assert to assertVincenzo Palazzo-2/+6
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-08-10add crt-static for androidBryanskiy-2/+4
2022-08-08Replace pointer casting in hashmap_random_keys with safe codeBlackHoleFox-9/+9
The old code was unnecessarily unsafe and relied on the layout of tuples always being the same as an array of the same size.
2022-08-08linux: Use `pthread_setname_np` instead of `prctl`Josh Stone-3/+9
This function is available on Linux since glibc 2.12, musl 1.1.16, and uClibc 1.0.20. The main advantage over `prctl` is that it properly represents the pointer argument, rather than a multi-purpose `long`, so we're better representing strict provenance (#95496).
2022-08-07Fix HorizonOS regression in FileTimesAndrea Ciliberti-5/+5
2022-08-07Rollup merge of #100127 - ChrisDenton:remove-init, r=thomccMatthias Krüger-160/+94
Remove Windows function preloading After `@Mark-Simulacrum` asked me to provide guidance for when optionally imported functions should be preloaded, I realised my justifications were now quite weak. I think the strongest argument that can be made is that it avoids some degree of nondeterminism when calling these functions (in as far as system API calls can be said to be deterministic). However, I don't think that's particularly convincing unless there's a real world use case where it matters. Further discussion with `@thomcc` has strengthened my feeling that preloading isn't really needed. Note that `WaitOnAddress` needed some adjustment to work without preloading. I opted not to use a macro for this special case as it seemed silly to do so for just one thing (and I don't like macros tbh).
2022-08-06provide correct size hint for unsupported platform CommandArgsMichael Goulet-0/+3
2022-08-05non-linux platformsNick Cameron-29/+25
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-05cleanup code w/ pointers in std a littleMaybe Waffle-4/+5
2022-08-04std::io: migrate ReadBuf to BorrowBuf/BorrowCursorNick Cameron-9/+8
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-04Update after code reviewChris Denton-6/+12
2022-08-04kmc-solid: Add a stub implementation of `File::set_times`Tomoaki Kawada-0/+12
2022-08-04Remove Windows function preloadingChris Denton-158/+86
2022-08-04Add visibility modifier to compat macroChris Denton-2/+2
2022-08-03FilesTimes support does not build for ESP-IDFIvan Markov-3/+7
2022-08-03Rollup merge of #99800 - sandydoo:bugfix/wasm-futex, r=m-ou-seDylan DPC-2/+4
Fix futex module imports on wasm+atomics The futex modules were rearranged a bit in #98707, which meant that wasm+atomics would no longer compile on nightly. I don’t believe any other targets were impacted by this.
2022-08-03Rollup merge of #99371 - ChrisDenton:simplify-gen-random-keys, r=thomccDylan DPC-60/+8
Remove synchronization from Windows `hashmap_random_keys` Unfortunately using synchronization when generating hashmap keys can prevent it being used in `DllMain`. ~~Fixes #99341~~
2022-08-02Rollup merge of #100017 - solid-rs:patch/kmc-solid/adapt-to-78802, r=thomccMatthias Krüger-2/+2
kmc-solid: Update `Socket::connect_timeout` to be in line with #78802 Fixes the build failure of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets after #78802. ``` error[E0308]: mismatched types --> library\std\src\sys\solid\net.rs:234:45 | 234 | cvt(netc::connect(self.0.raw(), addrp, len)) | ------------- ^^^^^ expected *-ptr, found union `SocketAddrCRepr` | | | arguments to this function are incorrect | = note: expected raw pointer `*const sockets::sockaddr` found union `SocketAddrCRepr` note: function defined here --> library\std\src\sys\solid\abi\sockets.rs:173:12 | 173 | pub fn connect(s: c_int, name: *const sockaddr, namelen: socklen_t) -> c_int; | ^^^^^^^ ```
2022-08-01kmc-solid: Adapt to a recent change in the `IntoInner` impl of `SocketAddr`Tomoaki Kawada-2/+2
`(x: SocketAddr).into_inner()` evaluates to `(SocketAddrCRepr, socklen_t)` instead of `(*const sockaddr, socklen_t)` as of commit 55e23db13.
2022-08-01Auto merge of #98246 - joshtriplett:times, r=m-ou-sebors-2/+174
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-08-01Never inline Windows dtor accessChris Denton-0/+4
2022-07-31Rollup merge of #99984 - ChrisDenton:fix-miri, r=Mark-SimulacrumMatthias Krüger-5/+5
Fix compat.rs for `cfg(miri)` Fixes #99982
2022-07-31Make sure `symbol_name` is const evaluatedChris Denton-4/+4
2022-07-31Auto merge of #78802 - faern:simplify-socketaddr, r=joshtriplettbors-10/+4
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-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-27Fix futex module imports on wasm+atomicssandydoo-2/+4
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-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-23Auto merge of #97925 - the8472:cgroupv1, r=joshtriplettbors-46/+189
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-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 #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-20owner is not micro (correct typo)joboet-1/+1
2022-07-20Rollup merge of #98101 - vladimir-ea:stdlib_watch_os, r=thomccDylan DPC-20/+61
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`