about summary refs log tree commit diff
path: root/library/std/src/sys/unix
AgeCommit message (Collapse)AuthorLines
2024-01-11std: begin moving platform support modules into `pal`joboet-15123/+0
2024-01-09Rollup merge of #118748 - devnexen:fbsd_getrandom_simpl, r=Nilstrieb,dtolnayGuillaume Gomez-11/+1
std: getrandom simplification for freebsd. it is in the libcs' crate too now.
2023-12-30openbsd: available_parallelism: use the right APISebastien Marie-26/+6
use the standard sysconf(_SC_NPROCESSORS_ONLN) way to get the number of available processors (capable of running processes), and fallback to sysctl([CTL_HW, HW_NCPU]) (number of CPUs configured) only on error. it permits to differenciate CPUs online vs CPUs configured (and not necessary capable of running processes). while here, use the common code path for BSDs for doing that, and avoid code duplication. Problem initially reported to me by Jiri Navratil.
2023-12-23Adjust the std library for sanitizer_cfi cfgs changesUrgau-1/+1
2023-12-14Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkinbors-19/+18
use c literals in compiler and library Relands refreshed https://github.com/rust-lang/rust/pull/111647
2023-12-09Auto merge of #117873 - quininer:android-emutls, r=Amanieubors-1/+7
Add emulated TLS support This is a reopen of https://github.com/rust-lang/rust/pull/96317 . many android devices still only use 128 pthread keys, so using emutls can be helpful. Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls. r? `@Amanieu`
2023-12-08std: getrandom simplification for freebsd.David Carlier-11/+1
it is in the libcs' crate too now.
2023-12-07Auto merge of #116565 - Sword-Destiny:master, r=Amanieubors-6/+6
add teeos std impl add teeos std library implement. this MR is draft untill the libc update to 0.2.150 this MR is the final step for suppot rust in teeos. first step(add target): https://github.com/rust-lang/rust/pull/113480 second step(add teeos libc): https://github.com/rust-lang/libc/pull/3333
2023-12-07add teeos std impl袁浩-6/+6
Signed-off-by: 袁浩 <yuanhao34@huawei.com>
2023-12-07Add emulated TLS supportquininer-1/+7
Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.
2023-12-05Rollup merge of #117793 - wdunicornpro:patch-1, r=workingjubileeMichael Goulet-1/+1
Update variable name to fix `unused_variables` warning This PR fixes an `unused_variables` warning within `os.rs` when targeting `espidf`.
2023-12-03library: use c string literalsklensy-19/+18
2023-11-21Rollup merge of #117790 - rcvalle:rust-cfi-fix-000000, r=workingjubileeNilstrieb-0/+2
CFI: Add missing use core::ffi::c_int Adds missing use core::ffi::c_int for when sanitizer_cfi_normalize_integers is defined.
2023-11-19Rollup merge of #117957 - the8472:pidfd-wait, r=Mark-SimulacrumMichael Goulet-11/+84
if available use a Child's pidfd for kill/wait This should get us closer to stabilization of pidfds since they now do something useful. And they're `CLOEXEC` now. ``` $ strace -ffe clone,sendmsg,recvmsg,execve,kill,pidfd_open,pidfd_send_signal,waitpid,waitid ./x test std --no-doc -- pidfd [...] running 1 tests strace: Process 816007 attached [pid 816007] pidfd_open(816006, 0) = 3 [pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0c6b787990) = 816008 strace: Process 816008 attached [pid 816007] recvmsg(3, <unfinished ...> [pid 816008] pidfd_open(816008, 0) = 3 [pid 816008] sendmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0 [pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0 [pid 816008] execve("/usr/bin/false", ["false"], 0x7ffcf2100048 /* 105 vars */) = 0 [pid 816007] waitid(P_PIDFD, 4, <unfinished ...> [pid 816008] +++ exited with 1 +++ [pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0}, WEXITED, NULL) = 0 [pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0} --- [pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 816009 attached , child_tidptr=0x7f0c6b787990) = 816009 [pid 816007] recvmsg(3, <unfinished ...> [pid 816009] pidfd_open(816009, 0) = 3 [pid 816009] sendmsg(5, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0 [pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[5]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0 [pid 816009] execve("/usr/bin/sleep", ["sleep", "1000"], 0x7ffcf2100048 /* 105 vars */) = 0 [pid 816007] waitid(P_PIDFD, 5, {}, WNOHANG|WEXITED, NULL) = 0 [pid 816007] pidfd_send_signal(5, SIGKILL, NULL, 0) = 0 [pid 816007] waitid(P_PIDFD, 5, <unfinished ...> [pid 816009] +++ killed by SIGKILL +++ [pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0}, WEXITED, NULL) = 0 [pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0} --- [pid 816007] +++ exited with 0 +++ ```
2023-11-19Don't set cmsg fields in msghdr if we have no cmsg to sendThe 8472-3/+4
2023-11-17Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naberMatthias Krüger-11/+0
Remove asmjs Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668). `asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-15Re-format code with new rustfmtMark Rousskov-10/+18
2023-11-16if available use a Child's pidfd for kill/waitThe 8472-4/+72
2023-11-16update comment, we're currently using a different syscallThe 8472-1/+1
2023-11-16set CLOEXEC on pidfd received from child processThe 8472-3/+7
2023-11-10Update variable name to fix `unused_variables` warningDuo Wang-1/+1
2023-11-10CFI: Add missing use core::ffi::c_intRamon de C Valle-0/+2
Adds missing use core::ffi::c_int for when sanitizer_cfi_normalize_integers is defined.
2023-11-01Auto merge of #115356 - devnexen:haiku_set_name_use_return, r=thomccbors-1/+3
`std::thread::set_name` exploit the return on haiku
2023-10-31Add support for pre-unix-epoch file dates on Apple platforms (#108277)Sebastian Thiel-0/+24
Time in UNIX system calls counts from the epoch, 1970-01-01. The timespec struct used in various system calls represents this as a number of seconds and a number of nanoseconds. Nanoseconds are required to be between 0 and 999_999_999, because the portion outside that range should be represented in the seconds field; if nanoseconds were larger than 999_999_999, the seconds field should go up instead. Suppose you ask for the time 1969-12-31, what time is that? On UNIX systems that support times before the epoch, that's seconds=-86400, one day before the epoch. But now, suppose you ask for the time 1969-12-31 23:59:00.1. In other words, a tenth of a second after one minute before the epoch. On most UNIX systems, that's represented as seconds=-60, nanoseconds=100_000_000. The macOS bug is that it returns seconds=-59, nanoseconds=-900_000_000. While that's in some sense an accurate description of the time (59.9 seconds before the epoch), that violates the invariant of the timespec data structure: nanoseconds must be between 0 and 999999999. This causes this assertion in the Rust standard library. So, on macOS, if we get a Timespec value with seconds less than or equal to zero, and nanoseconds between -999_999_999 and -1 (inclusive), we can add 1_000_000_000 to the nanoseconds and subtract 1 from the seconds, and then convert. The resulting timespec value is still accepted by macOS, and when fed back into the OS, produces the same results. (If you set a file's mtime with that timestamp, then read it back, you get back the one with negative nanoseconds again.) Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2023-10-28Remove asmjs from libraryJubilee Young-11/+0
2023-10-29Don't use LFS64 symbols on muslgit-bruh-13/+34
Simplify #[cfg] blocks fmt don't try to use the more appropriate direntry on musl
2023-10-25Auto merge of #117102 - devnexen:dfbsd_stack_overflow_upd, r=thomccbors-2/+12
stack_overflow: get_stackp using MAP_STACK flag on dragonflybsd too.
2023-10-24Auto merge of #116319 - BlackHoleFox:apple-rand-take-2, r=thomccbors-58/+52
Remove Apple RNG fallbacks and simplify implementation Now that we have [higher Apple platform requirements](https://github.com/rust-lang/rust/pull/104385), the RNG code can be simplified a lot. Since `getentropy` still doesn't look to be usable outside macOS this implementation: - Removes any macOS fallback paths and unconditionally links to `getentropy` - Minimizes the implementation for everything else (iOS, watchOS, etc). `CCRandomGenerateBytes` was added in iOS 8 which means that we can use it now. It and `SecRandomCopyBytes` have the exact same functionality, but the former has a simpler API and no longer requires libstd to link to `Security.framework` for one function. Its also available in all the other target's SDKs. Why care about `getentropy` then though on macOS? Well, its still much more performant. Benchmarking shows it runs at ~2x the speed of `CCRandomGenerateBytes`, which makes sense since it directly pulls from the kernel vs going through its own generator etc. Semi-related to a previous, but reverted, attempt at improving this logic in https://github.com/rust-lang/rust/pull/101011
2023-10-24Auto merge of #116238 - tamird:gettimeofday, r=thomccbors-196/+78
time: use clock_gettime on macos Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on: ``` all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios", target_os = "watchos", target_os = "tvos" ))] ``` `gettimeofday` was first used in https://github.com/time-rs/time/commit/cc367edd953e72756ed6f0980918795c11e469b1 which predated the introduction of `clock_gettime` support in macOS 10.12 Sierra which became the minimum supported version in 58bbca958d917a89124da248735926f86c59a149. Replace `mach_{absolute_time,timebase_info}` with `clock_gettime(CLOCK_REALTIME)` on: ``` all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios", target_os = "watchos", target_os = "tvos" ))] ``` `mach_{absolute_time,timebase_info}` were first used in https://github.com/time-rs/time/commit/cc367edd953e72756ed6f0980918795c11e469b1 which predated the introduction of `clock_gettime` support in macOS 10.12 Sierra which became the minimum supported version in 58bbca958d917a89124da248735926f86c59a149. Note that this change was made for aarch64 in 5008a317ce8e508c390ed12bff281f307313376e which predated 10.12 becoming the minimum supported version. The discussion took place in https://github.com/rust-lang/rust/issues/91417 and in particular https://github.com/rust-lang/rust/issues/91417#issuecomment-992151582 and https://github.com/rust-lang/rust/issues/91417#issuecomment-1033048064 are relevant.
2023-10-23Remove Apple RNG fallbacks and simplify implementationBlackHoleFox-58/+52
2023-10-23Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgrbors-9/+7
Rollup of 6 pull requests Successful merges: - #107159 (rand use getrandom for freebsd (available since 12.x)) - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`) - #117046 (return unfixed len if pat has reported error) - #117070 (rustdoc: wrap Type with Box instead of Generics) - #117074 (Remove smir from triage and add me to stablemir) - #117086 (Update .mailmap to promote my livename) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-23stack_overflow: get_stackp using MAP_STACK flag on dragonflybsd too.David Carlier-2/+12
2023-10-23Rollup merge of #107159 - devnexen:random_fbsd_update, r=workingjubileeMatthias Krüger-9/+7
rand use getrandom for freebsd (available since 12.x)
2023-10-22use visibility to check unused imports and delete some stmtsbohan-1/+2
2023-10-19Auto merge of #116132 - darthunix:connect_poll, r=cuviperbors-0/+17
Make TCP connect handle EINTR correctly According to the [POSIX](https://pubs.opengroup.org/onlinepubs/009695399/functions/connect.html) standard, if connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() shall fail and set errno to EINTR, but the connection request shall not be aborted, and the connection shall be established asynchronously. When the connection has been established asynchronously, select() and poll() shall indicate that the file descriptor for the socket is ready for writing. The previous implementation differs from the recomendation: in a case of the EINTR we tried to reconnect in a loop and sometimes get EISCONN error (this problem was originally detected on MacOS). 1. More details about the problem in an [article](http://www.madore.org/~david/computers/connect-intr.html). 2. The original [issue](https://git.picodata.io/picodata/picodata/tarantool-module/-/issues/157).
2023-10-19Auto merge of #116402 - joboet:global_alloc_tls_unsoundness, ↵bors-7/+8
r=thomcc,workingjubilee Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in #116390 and reduces the amount of `unsafe` code in the codebase.
2023-10-17Updated libc and doc for Vita targetNikolay Arhipov-2/+2
2023-10-14Fix broken build on ESP-IDF caused by #115108ivmarkov-4/+24
2023-10-13Auto merge of #115108 - ijackson:broken-wait-status, r=dtolnaybors-50/+144
Fix exit status / wait status on non-Unix cfg(unix) platforms Fixes #114593 Needs FCP due to behavioural changes (NB only on non-Unix `#[cfg(unix)]` platforms). Also, I think this is likely to break in CI. I have not been yet able to compile the new bits of `process_unsupported.rs`, although I have compiled the new module. I'd like some help from people familiar with eg emscripten and fuchsia (which are going to be affected, I think).
2023-10-13Make TCP connect() handle EINTR correctlyDenis Smirnov-0/+17
According to the POSIX standard, if connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() shall fail and set errno to EINTR, but the connection request shall not be aborted, and the connection shall be established asynchronously. If asynchronous connection was successfully established after EINTR and before the next connection attempt, OS returns EISCONN that was handled as an error before. This behavior is fixed now and we handle it as success. The problem affects MacOS users: Linux doesn't return EISCONN in this case, Windows connect() can not be interrupted without an old-fashoin WSACancelBlockingCall function that is not used in the library. So current solution gives connect() as OS specific implementation.
2023-10-09Support AIX in Rust standard libraryQiu Chaofan-3/+90
2023-10-06Add tvOS to target_os for register_dtorSebastian Imlay-1/+1
2023-10-04Disable CFI for core and std CFI violationsRamon de C Valle-12/+31
Works around #115199 by temporarily disabling CFI for core and std CFI violations to allow the user rebuild and use both core and std with CFI enabled using the Cargo build-std feature.
2023-10-04std: abort instead of panicking if the global allocator uses TLSjoboet-1/+4
2023-10-03std: panic when the global allocator tries to register a TLS destructorjoboet-7/+5
2023-09-30Add missing #[inline] on AsFd impl for sys::unix::fs::Filelinkmauve-0/+1
This operation should be extremely cheap, at most the mov of the underlying file descriptor, but due to this missing #[inline] it is currently a function call.
2023-09-28time: use clock_gettime on macosTamir Duberstein-148/+44
Replace `mach_{absolute_time,timebase_info}` with `clock_gettime(CLOCK_REALTIME)` on: ``` all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios", target_os = "watchos", target_os = "tvos" ))] ``` `mach_{absolute_time,timebase_info}` were first used in https://github.com/time-rs/time/commit/cc367edd953e72756ed6f0980918795c11e469b1 which predated the introduction of `clock_gettime` support in macOS 10.12 Sierra which became the minimum supported version in 58bbca958d917a89124da248735926f86c59a149. Note that this change was made for aarch64 in 5008a317ce8e508c390ed12bff281f307313376e which predated 10.12 becoming the minimum supported version. The discussion took place in https://github.com/rust-lang/rust/issues/91417 and in particular https://github.com/rust-lang/rust/issues/91417#issuecomment-992151582 and https://github.com/rust-lang/rust/issues/91417#issuecomment-1033048064 are relevant.
2023-09-28time: use clock_gettime on macosTamir Duberstein-49/+35
Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on: ``` all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios", target_os = "watchos", target_os = "tvos" ))] ``` `gettimeofday` was first used in https://github.com/time-rs/time/commit/cc367edd953e72756ed6f0980918795c11e469b1 which predated the introduction of `clock_gettime` support in macOS 10.12 Sierra which became the minimum supported version in 58bbca958d917a89124da248735926f86c59a149.
2023-09-28time: cfg(any(x)) is the same as cfg(x)Tamir Duberstein-2/+2
This was left over in c043a0e7d6f347f9b2c7f08c5b3a179470e0f0c5.
2023-09-28Auto merge of #98704 - vthib:impl-from-raw-for-childstd-structs, r=dtolnaybors-1/+7
Implement From<OwnedFd/Handle> for ChildStdin/out/err object ## Summary Comments in `library/std/src/process.rs` ( https://github.com/rust-lang/rust/commit/ab08639e5950f5c8a42a2870c9636181308c3686 ) indicates that `ChildStdin`, `ChildStdout`, `ChildStderr` implements some traits that are not actually implemented: `FromRawFd`, `FromRawHandle`, and the `From<OwnedFd>/From<OwnedHandle>` from the io_safety feature. In this PR I implement `FromRawHandle` and `FromRawFd` for those 3 objects. ## Usecase I have a usecase where those implementations are basically needed. I want to customize in the `Command::spawn` API how the pipes for the parent/child communications are created (mainly to strengthen the security attributes on them). I can properly setup the pipes, and the "child" handles can be provided to `Child::spawn` easily using `Stdio::from_raw_handle`. However, there is no way to generate the `ChildStd*` objects from the raw handle of the created name pipe, which would be very useful to still expose the same API than in other OS (basically a `spawn(...) -> (Child, ChildStdin, ChildStdout, ChildSterr)`, where on windows this is customized), and to for example use `tokio::ChildStdin::from_std` afterwards. ## Questions * Are those impls OK to add? I have searched to see if those impls were missing on purpose, or if it was just never implemented because never needed. I haven't found any indication on why they couldn't be added, although the user clearly has to be very careful that the handle provided makes sense (i think, mainly that it is in overlapped mode for windows). * If this change is ok, adding the impls for the io_safety feature would probably be best, or should it be done in another PR? * I just copy-pasted the `#[stable(...)]` attributes, but the `since` value has to be updated, I'm not sure to which value.