about summary refs log tree commit diff
path: root/library/std/src/sys/pal
AgeCommit message (Collapse)AuthorLines
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-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-853/+5
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-853/+5
2024-05-01Auto merge of #124491 - madsmtm:target_vendor-apple, r=workingjubileebors-244/+46
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-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-226/+39
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.
2024-04-27Lift the probe code of `copy_file_range` into a functionTobias Bucher-29/+31
2024-04-27Elaborate in comment about `statx` probeTobias Bucher-8/+4
As requested by @workingjubilee in https://github.com/rust-lang/rust/pull/123928#discussion_r1564916743.
2024-04-24Rollup merge of #124282 - RalfJung:fill_utf16_buf, r=ChrisDentonLeón Orell Valerian Liehr-5/+14
windows fill_utf16_buf: explain the expected return value The comment just says "return what the syscall returns", but that doesn't work for all syscalls as the Windows API is not consistent in how buffer size is negotiated. For instance, GetUserProfileDirectoryW works a bit differently, and so home_dir_crt has to translate this to the usual protocol itself. So it's worth describing that protocol. r? ``@ChrisDenton``
2024-04-24Rollup merge of #124281 - RalfJung:win-tls, r=joboetLeón Orell Valerian Liehr-4/+22
fix weak memory bug in TLS on Windows We need to store the `key` *after* we register the dtor. Now I hope there isn't also some other reason why we have to actually register the dtor last... `@joboet` is there a reason you picked this particular order in https://github.com/rust-lang/rust/pull/102655? Fixes https://github.com/rust-lang/rust/issues/123583
2024-04-23increase the readability by using the unique name for the hermit-abiStefan Lankes-79/+80
Take up suggestion from the discussions within rust-lang/rust#115984 to increase readability.
2024-04-23revise the interpretation of ReadDirStefan Lankes-12/+8
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.
2024-04-23fix weak memory bug in TLS on WindowsRalf Jung-4/+22
2024-04-23windows fill_utf16_buf: explain the expected return valueRalf Jung-5/+14
2024-04-21Rollup merge of #124089 - ↵Guillaume Gomez-38/+66
simlay:fix-preadv64-and-pwritev64-link-for-watchos-and-visionos, r=workingjubilee Fix watchOS and visionOS for pread64 and pwrite64 calls In #122880, links to `preadv64` and `pwritev64` were added for `watchOS` however the underlying [`weak!` macro did not include `target_os = "watchos"`](https://github.com/rust-lang/rust/blob/c45dee5efd0c042e9d1e24559ebd0d6424d8aa70/library/std/src/sys/pal/unix/weak.rs#L30-L74). This resulted in an `xcodebuild` error when targeting `watchOS`: ``` Undefined symbols for architecture arm64: "_preadv64", referenced from: __rust_extern_with_linkage_preadv64 in libliveview_native_core.a[274](std-324fdd8d31e8eaa2.std.e18cf7e8d0336778-cgu.08.rcgu.o) "_pwritev64", referenced from: __rust_extern_with_linkage_pwritev64 in libliveview_native_core.a[274](std-324fdd8d31e8eaa2.std.e18cf7e8d0336778-cgu.08.rcgu.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` So I added them. I also went ahead and added the same for visionOS because it's bound to create the same issue.
2024-04-21Fix watchOS and visionOS for pread64 and pwrite64 callsSebastian Imlay-38/+66
* Refactor apple OSs to use pwritev and preadv rather pwritev64 and preadv64 * Updated the comments for preadv and pwritev
2024-04-20Abort a process when FD ownership is violatedThe 8472-0/+21
When an EBADF happens then something else already 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.
2024-04-18Rollup merge of #124019 - ChrisDenton:futex-raw-dylib, r=joboetJubilee-1/+13
Use raw-dylib for Windows synchronization functions Fixes #123999 by using the raw-dylib feature to specify the DLL to load the Windows futex functions from (e.g. [`WaitOnAddress`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress)). This avoids reliance on the import library causing that issue. With apologies to ``@bjorn3,`` as it's currently necessary to revert this for cranelift.