about summary refs log tree commit diff
path: root/library/std/src/sys/pal/unix
AgeCommit message (Collapse)AuthorLines
2024-04-15Auto merge of #123928 - tbu-:pr_statx_enosys, r=workingjubileebors-8/+5
`statx` probe: `ENOSYS` might come from a faulty FUSE driver Do the availability check regardless of the error returned from `statx`. CC https://github.com/rust-lang/rust/pull/122079#discussion_r1564761281
2024-04-14`statx` probe: `ENOSYS` might come from a faulty FUSE driverTobias Bucher-8/+5
Do the availability check regardless of the error returned from `statx`. CC https://github.com/rust-lang/rust/pull/122079#discussion_r1564761281
2024-04-14Rollup merge of #123879 - beetrees:missing-unsafe, r=Mark-SimulacrumMatthias Krüger-3/+3
Add missing `unsafe` to some internal `std` functions Adds `unsafe` to a few internal functions that have safety requirements but were previously not marked as `unsafe`. Specifically: - `std::sys::pal::unix::thread::min_stack_size` needs to be `unsafe` as `__pthread_get_minstack` might dereference the passed pointer. All callers currently pass a valid initialised `libc::pthread_attr_t`. - `std::thread::Thread::new` (and `new_inner`) need to be `unsafe` as it requires the passed thread name to be valid UTF-8, otherwise `Thread::name` will trigger undefined behaviour. I've taken the opportunity to split out the unnamed thread case into a separate `new_unnamed` function to make the safety requirement clearer. All callers meet the safety requirement now that #123505 has been merged.
2024-04-13Add missing `unsafe` to internal function ↵beetrees-3/+3
`std::sys::pal::unix::thread::min_stack_size`
2024-04-11Factor some common `io::Error` constantsBenoît du Garreau-14/+8
2024-04-10visionOS: Fix unused import warningMads Marquart-12/+1
The import is used once in this file, inside `posix_spawn`, so let's move the import into that function instead, to reduce the number of `cfg`s that need to be kept in sync.
2024-04-10Auto merge of #122812 - dtolnay:mode, r=workingjubileebors-5/+186
Show mode_t as octal in std::fs Debug impls Example: ```rust fn main() { println!("{:?}", std::fs::metadata("Cargo.toml").unwrap().permissions()); } ``` - Before: `Permissions(FilePermissions { mode: 33204 })` - ~~After: `Permissions(FilePermissions { mode: 0o100664 })`~~ - After: `Permissions(FilePermissions { mode: 0o100664 (-rw-rw-r--) })` ~~I thought about using the format from `ls -l` (`-rw-rw-r--`, `drwxrwxr-x`) but I am not sure how transferable the meaning of the higher bits between different unix systems, and anyway starting the value with a leading negative-sign seems objectionable.~~
2024-04-09Show mode_t as octal in std::fs Debug implsDavid Tolnay-5/+186
2024-04-09Auto merge of #123485 - madsmtm:use-libc-copyfile, r=joboetbors-39/+10
macOS: Use `libc` definitions for copyfile `COPYFILE_ALL` is not yet exposed in `libc`, but the rest of what we need is, so use those definitions instead of manually defining them. The definitions were added in https://github.com/rust-lang/libc/pull/2667 and https://github.com/rust-lang/libc/pull/3346.
2024-04-05Rollup merge of #123505 - ChrisDenton:revert-121666, r=workingjubileeGuillaume Gomez-73/+1
Revert "Use OS thread name by default" This reverts #121666 (Use the OS thread name by default if `THREAD_INFO` has not been initialized) due to #123495 (Thread names are not always valid UTF-8). It's not a direct revert because there have been other changes since that PR.
2024-04-05Rollup merge of #121419 - agg23:xrOS-pr, r=davidtwcoGuillaume Gomez-12/+98
Add aarch64-apple-visionos and aarch64-apple-visionos-sim tier 3 targets Introduces `aarch64-apple-visionos` and `aarch64-apple-visionos-sim` as tier 3 targets. This allows native development for the Apple Vision Pro's visionOS platform. This work has been tracked in https://github.com/rust-lang/compiler-team/issues/642. There is a corresponding `libc` change https://github.com/rust-lang/libc/pull/3568 that is not required for merge. Ideally we would be able to incorporate [this change](https://github.com/gimli-rs/object/pull/626) to the `object` crate, but the author has stated that a release will not be cut for quite a while. Therefore, the two locations that would reference the xrOS constant from `object` are hardcoded to their MachO values of 11 and 12, accompanied by TODOs to mark the code as needing change. I am open to suggestions on what to do here to get this checked in. # Tier 3 Target Policy At this tier, the Rust project provides no official support for a target, so we place minimal requirements on the introduction of targets. > A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.) See [src/doc/rustc/src/platform-support/apple-visionos.md](https://github.com/rust-lang/rust/blob/e88379034a0fe7d90a8f305bbaf4ad66dd2ce8dc/src/doc/rustc/src/platform-support/apple-visionos.md) > Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target. > * Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it. > * If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo. This naming scheme matches `$ARCH-$VENDOR-$OS-$ABI` which is matches the iOS Apple Silicon simulator (`aarch64-apple-ios-sim`) and other Apple targets. > Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users. > - The target must not introduce license incompatibilities. > - Anything added to the Rust repository must be under the standard Rust license (`MIT OR Apache-2.0`). > - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the `tidy` tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to besubject to any new license requirements. > - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, `rustc` built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3. > - "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are *not* limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users. This contribution is fully available under the standard Rust license with no additional legal restrictions whatsoever. This PR does not introduce any new dependency less permissive than the Rust license policy. The new targets do not depend on proprietary libraries. > Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions. This new target mirrors the standard library for watchOS and iOS, with minor divergences. > The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary. Documentation is provided in [src/doc/rustc/src/platform-support/apple-visionos.md](https://github.com/rust-lang/rust/blob/e88379034a0fe7d90a8f305bbaf4ad66dd2ce8dc/src/doc/rustc/src/platform-support/apple-visionos.md) > Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions. > * This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements. > Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages. > * Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications. > Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target. > * In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target. I acknowledge these requirements and intend to ensure that they are met. This target does not touch any existing tier 2 or tier 1 targets and should not break any other targets.
2024-04-05Revert #121666Chris Denton-73/+1
This reverts #121666 due to #123495
2024-04-05macOS: Use `libc` definitions for copyfileMads Marquart-39/+10
`COPYFILE_ALL` is not yet exposed in `libc`, but the rest of what we need is, so use those definitions instead of manually defining them.
2024-04-03Rollup merge of #122356 - devnexen:dfbsd_build_fix, r=jhprattJacob Pratt-7/+13
std::rand: fix dragonflybsd after #121942.
2024-04-02style: fmtSteve Lau-1/+2
2024-04-02fix: build on haiku by adding missing importSteve Lau-1/+1
2024-04-01Rollup merge of #123323 - devnexen:thread_set_name_solaris_fix, r=workingjubileeJubilee-1/+6
std::thread: set_name change for solaris/illumos. truncate down to 32 (31 + 1) for solaris/illumos.
2024-04-01std::thread: set_name change for solaris/illumos.David Carlier-1/+6
truncate down to 32 (31 + 1) for solaris/illumos.
2024-04-01Auto merge of #123315 - devnexen:thread_get_name_solaris, r=ChrisDentonbors-3/+11
std::thread: adding get_name implementation for solaris/illumos. THREAD_NAME_MAX is 32 (31 max + 1 for the null terminator).
2024-04-01Auto merge of #123265 - joboet:guardians_of_the_unix, r=ChrisDentonbors-321/+287
Refactor stack overflow handling Currently, every platform must implement a `Guard` that protects a thread from stack overflow. However, UNIX is the only platform that actually does so. Windows has a different mechanism for detecting stack overflow, while the other platforms don't detect it at all. Also, the UNIX stack overflow handling is split between `sys::pal::unix::stack_overflow`, which implements the signal handler, and `sys::pal::unix::thread`, which detects/installs guard pages. This PR cleans this by getting rid of `Guard` and unifying UNIX stack overflow handling inside `stack_overflow` (commit 1). Therefore we can get rid of `sys_common::thread_info`, which stores `Guard` and the current `Thread` handle and move the `thread::current` TLS variable into `thread` (commit 2). The second commit is not strictly speaking necessary. To keep the implementation clean, I've included it here, but if it causes too much noise, I can split it out without any trouble.
2024-04-01std::thread: adding get_name implementation for solaris/illumos.David Carlier-3/+11
THREAD_NAME_MAX is 32 (31 max + 1 for the null terminator).
2024-03-31std::thread: adding get_name haiku implementation.David Carlier-1/+19
follow-up #123233
2024-03-31std: move `thread::current` TLS variable out of `thread_info`joboet-11/+0
2024-03-31std: move UNIX stack overflow guard page handling into `stack_overflow.rs`joboet-310/+287
2024-03-30std::thread: adding freebsd/netbsd to the linux's get_name implementation.David Carlier-1/+8
2024-03-27Rollup merge of #123038 - he32:netbsd-ilp32-fix, r=workingjubileeMatthias Krüger-1/+1
std library thread.rs: fix NetBSD code for ILP32 CPUs.
2024-03-27Rollup merge of #122880 - a1phyr:preadv_more_platform, r=workingjubileeMatthias Krüger-6/+22
Unix: Support more platforms with `preadv` and `pwritev` - `aix`, `dragonfly` and `openbsd` with direct call - `watchos` with weak linkage cc #89517
2024-03-26unix fs: Make hurd and horizon using explicit new rather than FromSamuel Thibault-2/+2
408c0ea2162b ("unix time module now return result") dropped the From impl for SystemTime, breaking the hurd and horizon builds. Fixes #123032
2024-03-26Unix: Support more platforms with `preadv` and `pwritev`Benoît du Garreau-6/+22
2024-03-26std library unix/thread.rs: fix NetBSD code for ILP32 CPUs.Havard Eidnes-1/+1
2024-03-24Rollup merge of #122992 - devnexen:available_parallelism_sol_upd, r=AmanieuMatthias Krüger-2/+6
std::thread: refine available_parallelism for solaris/illumos. Rather than the system-wide available cpus fallback solution, we fetch the cpus bound to the current process.
2024-03-24fix build.David Carlier-5/+3
2024-03-24std::thread: refine available_parallelism for solaris/illumos.David Carlier-0/+6
Rather than the system-wide available cpus fallback solution, we fetch the cpus bound to the current process.
2024-03-24Fix build failure on ARM/AArch64/PowerPC/RISC-V FreeBSD/NetBSDTaiki Endo-1/+1
2024-03-23Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlinbors-1/+1
Replace visibility test with reachability test in dead code detection Fixes https://github.com/rust-lang/rust/issues/119545 Also included is a fix for an error now flagged by the lint
2024-03-22Rollup merge of #121881 - devnexen:bsd_acceptfilter, r=AmanieuMatthias Krüger-0/+31
std::net: adding acceptfilter feature for netbsd/freebsd. similar to linux's ext deferaccept, to filter incoming connections before accept.
2024-03-20std::net: adding acceptfilter feature for netbsd/freebsd.David Carlier-0/+31
similar to linux's ext deferaccept, to filter incoming connections before accept.
2024-03-19Use less restricted memory ordering in thread_parking::pthread.Mara Bos-10/+12
SeqCst is unnecessary here.
2024-03-18Support for visionOSAdam Gastineau-12/+98
2024-03-14Rollup merge of #121650 - GrigorenkoPV:cap_setgid, r=AmanieuMatthias Krüger-3/+11
change std::process to drop supplementary groups based on CAP_SETGID A trivial rebase of #95982 Should fix #39186 (from what I can tell) Original description: > Fixes #88716 > > * Before this change, when a process was given a uid via `std::os::unix::process::CommandExt.uid`, there would be a `setgroups` call (when the process runs) to clear supplementary groups for the child **if the parent was root** (to remove potentially unwanted permissions). > * After this change, supplementary groups are cleared if we have permission to do so, that is, if we have the CAP_SETGID capability. > > This new behavior was agreed upon in #88716 but there was a bit of uncertainty from `@Amanieu` here: [#88716 (comment)](https://github.com/rust-lang/rust/issues/88716#issuecomment-973366600) > > > I agree with this change, but is it really necessary to ignore an EPERM from setgroups? If you have permissions to change UID then you should also have permissions to change groups. I would feel more comfortable if we documented set_uid as requiring both UID and GID changing permissions. > > The way I've currently written it, we ignore an EPERM as that's what #88716 originally suggested. I'm not at all an expert in any of this so I'd appreciate feedback on whether that was the right way to go.
2024-03-14Auto merge of #114038 - Stargateur:108277, r=ChrisDentonbors-51/+35
unix time module now return result First try to fix #108277 without break anything. if anyone who read this know tips to be able to check compilation for different target I could use some help. So far I installed many target with rustup but `./x check --all-targets` doesn't seem to use them. TODO: - [x] better error - [ ] test, how ? `@rustbot` label -S-waiting-on-author +S-waiting-on-review
2024-03-12Allow dead code in thread local dtorArthur Carcano-1/+1
The dead_code lint was previously eroneously missing this dead code. Since this lint bug has been fixed, the unused field need to be removed or marked as `#[allow(dead_code)]`. Given the nature of this code, I don't feel confident removing the field so it is only marked as allow(dead_code).
2024-03-12std::rand: fix dragonflybsd after #121942.David Carlier-7/+13
2024-03-11Auto merge of #122331 - jhpratt:rollup-cbl8xsy, r=jhprattbors-2/+3
Rollup of 9 pull requests Successful merges: - #121148 (Add slice::try_range) - #121633 (Win10: Use `GetSystemTimePreciseAsFileTime` directly) - #121840 (Expose the Freeze trait again (unstably) and forbid implementing it manually) - #121907 (skip sanity check for non-host targets in `check` builds) - #122002 (std::threads: revisit stack address calculation on netbsd.) - #122108 (Add `target.*.runner` configuration for targets) - #122298 (RawVec::into_box: avoid unnecessary intermediate reference) - #122315 (Allow multiple `impl Into<{D,Subd}iagMessage>` parameters in a function.) - #122326 (Optimize `process_heap_alloc`) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-11Rollup merge of #122002 - devnexen:thread_stack_netbsd_fix, ↵Jacob Pratt-2/+3
r=workingjubilee,riastradh std::threads: revisit stack address calculation on netbsd. like older linux glibc versions, we need to get the guard size and increasing the stack's bottom address accordingly.
2024-03-11Auto merge of #117156 - jmillikin:os-unix-socket-ext, r=Amanieu,dtolnaybors-10/+16
Convert `Unix{Datagram,Stream}::{set_}passcred()` to per-OS traits These methods are the pre-stabilized API for obtaining peer credentials from an `AF_UNIX` socket, part of the `unix_socket_ancillary_data` feature. Their current behavior is to get/set one of the `SO_PASSCRED` (Linux), `LOCAL_CREDS_PERSISTENT` (FreeBSD), or `LOCAL_CREDS` (NetBSD) socket options. On other targets the `{set_}passcred()` methods do not exist. There are two problems with this approach: 1. Having public methods only exist for certain targets isn't permitted in a stable `std` API. 2. These options have generally similar purposes, but they are non-POSIX and their details can differ in subtle and surprising ways (such as whether they continue to be set after the next call to `recvmsg()`). Splitting into OS-specific extension traits is the preferred solution to both problems.
2024-03-10Rollup merge of #121942 - devnexen:getrandom_for_dfbsd, r=joboetMatthias Krüger-1/+9
std::rand: enable getrandom for dragonflybsd too.
2024-03-08further changes from feedbackDavid Carlier-19/+1
2024-03-06Dynamically size sigaltstk in stdJubilee Young-11/+39
On modern Linux with Intel AMX and 1KiB matrices, Arm SVE with potentially 2KiB vectors, and RISCV Vectors with up to 16KiB vectors, we must handle dynamic signal stack sizes. We can do so unconditionally by using getauxval, but assuming it may return 0 as an answer, thus falling back to the old constant if needed.
2024-03-06Be stricter with `copy_file_range` probe resultsTobias Bucher-33/+35