about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2024-05-26std::pal::unix::thread fetching min stack size on netbsd.David Carlier-1/+10
PTHREAD_STACK_MIN is not defined however sysconf/_SC_THREAD_STACK_MIN returns it as it can vary from arch to another.
2024-05-25Rollup merge of #125271 - RalfJung:posix_memalign, r=workingjubileeMatthias Krüger-9/+7
use posix_memalign on almost all Unix targets Seems nice to be able to use a single common codepath for all of them. :) The `libc` crate says this symbol exists for all Unix targets. I did locally do check-builds to ensure this still builds, but I can't really test more than that. - For redox, I found indications posix_memalign really exists [here](https://gitlab.redox-os.org/redox-os/relibc/-/merge_requests/271) - For esp-idf, I found indications [here](https://github.com/playable-tech/esp-idf/commit/c5b297a86f3d65081bc690e81ab53db47b18d31c) - ~~For horizon and vita (these seem to be gaming console OSes? "Horizon OS" also has some hits for a Facebook product but that seems unrelated), they seem to be based on "newlib", where posix_memalign [seems to exist](https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=3ba2c39fb2a12cd7332ef16b1b3e3df994f7c6f5).~~ Turns out no, this 20-year-old standard POSIX function is unfortunately [not supported](https://github.com/rust-lang/rust/pull/125271#issuecomment-2119221419) here.
2024-05-25std: make TLS accessors closures that return pointersjoboet-172/+103
2024-05-24std: clean up the TLS implementationjoboet-5/+4
2024-05-24std: simplify key-based thread localsjoboet-185/+60
2024-05-24Auto merge of #123724 - joboet:static_tls, r=m-ou-sebors-70/+76
Rewrite TLS on platforms without threads The saga of #110897 continues! r? `@m-ou-se` if you have time
2024-05-23std: rewrite native thread-local storagejoboet-248/+330
2024-05-21Rollup merge of #125225 - madsmtm:ios-crt_externs.h, r=workingjubileeMatthias Krüger-150/+127
Use functions from `crt_externs.h` on iOS/tvOS/watchOS/visionOS Use `_NSGetEnviron`, `_NSGetArgc` and `_NSGetArgv` on iOS/tvOS/watchOS/visionOS, see each commit and the code comments for details. This allows us to unify more code with the macOS implementation, as well as avoiding linking to the `Foundation` framework (which is good for startup performance). The biggest problem with doing this would be if it lead to App Store rejections. After doing a bunch of research on this, while [it did happen once in 2009](https://blog.unity.com/engine-platform/unity-app-store-submissions-problem-solved), I find it fairly unlikely to happen nowadays, especially considering that Apple has later _added_ `crt_externs.h` to the iOS/tvOS/watchOS/visionOS SDKs, strongly signifying the functions therein is indeed supported on those platforms (even though they lack an availability attribute). That we've been overly cautious here has also been noted by `@thomcc` in https://github.com/rust-lang/rust/pull/117910#issuecomment-1903372350. r? `@workingjubilee` `@rustbot` label O-apple
2024-05-20switch also the default implementation for read_vectoredStefan Lankes-13/+2
2024-05-20switch to the default implementation of `write_vectored`Stefan Lankes-8/+2
2024-05-20Make NULL check in argument parsing the same on all unix platformsMads Marquart-76/+64
2024-05-19fix typoRalf Jung-2/+2
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-05-19Rollup merge of #124304 - hermit-os:fuse, r=joboetMichael Goulet-89/+86
revise the interpretation of ReadDir for HermitOS HermitOS supports getdents64. As under Linux, the dirent64 entry `d_off` is not longer used, because its definition is not clear. Instead of `d_off` the entry `d_reclen` is used to determine the end of the dirent64 entry. In addition, take up `@workingjubilee` suggestion from the discussions in rust-lang/rust#115984 to increase the readability. Hermit is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-05-19use posix_memalign on most Unix targetsRalf Jung-9/+7
2024-05-19Add NULL check in argument parsing on Apple platformsMads Marquart-14/+44
2024-05-18android: use posix_memalign for aligned allocationsRalf Jung-18/+1
2024-05-17Use `_NSGetArgc`/`_NSGetArgv` on iOS/tvOS/watchOS/visionOSMads Marquart-84/+19
If we're comfortable using `_NSGetEnviron` from `crt_externs.h`, there shouldn't be an issue with using these either, and then we can merge with the macOS implementation. This also fixes two test cases on Mac Catalyst: - `tests/ui/command/command-argv0.rs`, maybe because `[[NSProcessInfo processInfo] arguments]` somehow converts the name of the first argument? - `tests/ui/env-funky-keys.rs` since we no longer link to Foundation.
2024-05-17Use `_NSGetEnviron` instead of `environ` on iOS/tvOS/watchOS/visionOSMads Marquart-2/+26
This should be slightly more correct, and matches the implementation in other programming languages: - [Python's `os.environ`](https://github.com/python/cpython/blob/v3.12.3/Modules/posixmodule.c#L1562-L1566). - [Swift's `Darwin.environ`](https://github.com/apple/swift-corelibs-foundation/blob/swift-5.10-RELEASE/CoreFoundation/Base.subproj/CFPlatform.c#L1811-L1812), though that library is bundled on the system, so they can change it if they want. - [Dart/Flutter](https://github.com/dart-lang/sdk/blob/3.4.0/runtime/bin/platform_macos.cc#L205-L234), doesn't support environment variables on iOS. - Node seems to not be entirely consistent with it: - [`process.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/process.c#L38). - [`unix/core.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/core.c#L59). - [.NET/Xamarin](https://github.com/dotnet/runtime/blob/v8.0.5/src/native/libs/configure.cmake#L1099-L1106). - [OpenJDK](https://github.com/openjdk/jdk/blob/jdk-23%2B22/src/java.base/unix/native/libjava/ProcessEnvironment_md.c#L31-L33).
2024-05-15Rollup merge of #125003 - RalfJung:aligned_alloc, r=cuviperLeón Orell Valerian Liehr-11/+8
avoid using aligned_alloc; posix_memalign is better-behaved Also there's no reason why wasi should be different than all the other Unixes here.
2024-05-14avoid using aligned_alloc; posix_memalign is better-behavedRalf Jung-11/+8
2024-05-12Auto merge of #124798 - devnexen:illumos_memalign_fix, r=RalfJungbors-2/+0
std::alloc: use posix_memalign instead of memalign on solarish `memalign` on Solarish requires the alignment to be at least the size of a pointer, which we did not honor. `posix_memalign` also requires that, but that code path already takes care of this requirement. close GH-124787
2024-05-11std::alloc: using posix_memalign instead of memalign on solarish.David Carlier-2/+0
simpler code path since small alignments are already taking care of. close GH-124787
2024-05-11Rollup merge of #124766 - devnexen:getrandom_solarish, r=Mark-SimulacrumMatthias Krüger-1/+12
std::rand: adding solaris/illumos for getrandom support. To help solarish support for miri https://https://github.com/rust-lang/miri/issues/3567
2024-05-08Rollup merge of #124788 - madsmtm:reduce-target_os-macos, r=workingjubileeJubilee-17/+24
Convert instances of `target_os = "macos"` to `target_vendor = "apple"` https://github.com/rust-lang/rust/pull/124491 migrated towards using `target_vendor = "apple"` more, as there's very little difference between iOS, tvOS, watchOS and visionOS. In that PR, I only did the changes where the standard library already had fixes for iOS, that I could confidently apply to the other targets. However, there's actually also not that big of a gap between macOS and the aforementioned platforms - so in this PR, I've gone through a few of the instances of `target_os = "macos"` and replaced it with `target_vendor = "apple"` to improve support on those platforms, see the commits for details. r? workingjubilee CC `@thomcc` `@simlay` (do tell me if I should stop pinging you on these Apple PRs) `@rustbot` label O-apple
2024-05-08Rollup merge of #124470 - devnexen:no_sigpipe_fbsd, r=workingjubileeJubilee-1/+8
std::net: Socket::new_raw now set to SO_NOSIGPIPE on freebsd.
2024-05-06std::rand: adding solaris/illumos for getrandom support.David Carlier-1/+12
To help solarish support for miri https://rust-lang/miri/issues/3567
2024-05-06iOS/tvOS/watchOS/visionOS: Improve File Debug implMads Marquart-9/+9
This uses `libc::fcntl`, which, while not explicitly marked as available in the headers, is already used by `File::sync_all` and `File::sync_data` on these platforms, so should be fine to use here as well.
2024-05-06iOS/tvOS/watchOS/visionOS: Fix reading large filesMads Marquart-5/+6
Tested in the iOS simulator with something like: ``` let mut buf = vec![0; c_int::MAX as usize - 1 + 2]; let read_bytes = f.read(&mut buf).unwrap(); ```
2024-05-06iOS/tvOS/watchOS: Fix alloc w. large alignment on older versionsMads Marquart-1/+7
Tested on an old MacBook and the iOS simulator.
2024-05-06iOS/tvOS/watchOS/visionOS: Set the main thread nameMads Marquart-2/+2
Tested in the iOS simulator that the thread name is not set by default, and that setting it improves the debugging experience in lldb / Xcode.
2024-05-05Fix unwinding on 32-bit watchOS ARMMads Marquart-3/+11
The code is written in a way to support 32-bit iOS and tvOS ARM devices, for future compatibility even though we currently only have a target for 32-bit iOS ARM.
2024-05-04library/std: Fix build for NetBSD targets with 32-bit `c_long`Ian Douglas Scott-2/+2
This fixes building `std` for targets like `mipsel-unknown-netbsd`. If `c_long` is an `i64`, this conversion works with `Into`. But if it's an `i32`, this failed to convert a `u32` to an `i32`.
2024-05-04Rollup merge of #124159 - joboet:move_pal_thread_parking, r=ChrisDentonMatthias Krüger-54/+247
Move thread parking to `sys::sync` Part of #117276. I'll leave the platform-specific API abstractions in `sys::pal`, as per the initial proposal. I'm not entirely sure whether we'll want to keep it that way, but that remains to be seen. r? ``@ChrisDenton`` (if you have time)
2024-05-03Rollup merge of #124480 - Enselic:on-broken-pipe, r=jieyouxuMichael Goulet-15/+15
Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...` In the stabilization [attempt](https://github.com/rust-lang/rust/pull/120832) of `#[unix_sigpipe = "sig_dfl"]`, a concern was [raised ](https://github.com/rust-lang/rust/pull/120832#issuecomment-2007394609) related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward. So as a first step towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature. Another point was [also raised](https://github.com/rust-lang/rust/pull/120832#issuecomment-1987023484), namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization. Tracking issue: https://github.com/rust-lang/rust/issues/97889
2024-05-03Horizon OS: dirfd unavailableAndrea Ciliberti-0/+1
2024-05-02Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...`Martin Nordholts-15/+15
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern was raised related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward. So as a first step towards towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature. Another point was also raised, namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.
2024-05-02std: move thread parking to `sys::sync`joboet-54/+247
2024-05-01Auto merge of #124491 - madsmtm:target_vendor-apple, r=workingjubileebors-262/+52
Use `target_vendor = "apple"` instead of `target_os = "..."` Use `target_vendor = "apple"` instead of `all(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos")`. The apple targets are quite close to being identical, with iOS, tvOS, watchOS and visionOS being even closer, so using `target_vendor` when possible makes it clearer when something is actually OS-specific, or just Apple-specific. Note that `target_vendor` will [be deprecated in the future](https://github.com/rust-lang/rust/issues/100343), but not before an alternative (like `target_family = "apple"`) is available. While doing this, I found various inconsistencies and small mistakes in the standard library, see the commits for details. Will follow-up with an extra PR for a similar issue that need a bit more discussion. EDIT: https://github.com/rust-lang/rust/pull/124494 Since you've talked about using `target_vendor = "apple"` in the past: r? workingjubilee CC `@simlay,` `@thomcc` `@rustbot` label O-macos O-ios O-tvos O-watchos O-visionos
2024-04-30std: rewrite TLS on platforms without threadsjoboet-70/+76
2024-04-29Fix Fuchsia build broken by #124210David Koloski-0/+1
Fuchsia doesn't support dirfd although we have a symbol stubbed for it.
2024-04-29Fix ESP IDF build broken by #124210ivmarkov-0/+1
2024-04-28Fix posix_spawn not being used on iOS and visionOSMads Marquart-8/+3
`man posix_spawn` documents it to be able to return `ENOENT`, and there should be nothing preventing this. Tested in the iOS simulator and on Mac Catalyst.
2024-04-28Fix SIGEMT and SIGINFO parsing on watchOS and visionOSMads Marquart-7/+3
2024-04-28Fix available_parallelism on watchOS and visionOSMads Marquart-3/+1
Both `sysconf` and `_SC_NPROCESSORS_ONLN` is available on all Apple platforms.
2024-04-28std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly.David Carlier-1/+8
2024-04-28Use `target_vendor = "apple"` instead of `target_os = "..."`Mads Marquart-244/+45
2024-04-28Auto merge of #124210 - the8472:consign-ebadf-to-the-fire, r=Mark-Simulacrumbors-0/+32
Abort a process when FD ownership is violated When an owned FD has already been closed before it's dropped that means something else touched an FD in ways it is not allowed to. At that point things can already be arbitrarily bad, e.g. clobbered mmaps. Recovery is not possible. All we can do is hasten the fire. Unlike the previous attempt in #124130 this shouldn't suffer from the possibility that FUSE filesystems can return arbitrary errors.
2024-04-28put FD validity behind late debug_asserts checkingThe 8472-18/+29
uses the same machinery as assert_unsafe_precondition
2024-04-28Rollup merge of #124447 - workingjubilee:set-argv-twice-on-gnu, r=ChrisDentonMatthias Krüger-6/+4
Unconditionally call `really_init` on GNU/Linux This makes miri not diverge in behavior, it fixes running Rust linux-gnu binaries on musl with gcompat, it fixes dlopen edge-cases that cranelift somehow hits, etc. Fixes #124126 thou hast gazed into this abyss with me: r? ``@ChrisDenton``
2024-04-27Unconditionally call really_initJubilee Young-6/+4
This makes miri not diverge in behavior, it fixes running Rust linux-gnu binaries on musl with gcompat, it fixes dlopen edge-cases that cranelift somehow hits, etc.