about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2024-03-19SeqCst->Relaxed in pal::windows::pipe.Mara Bos-4/+4
Relaxed is enough to ensure fetch_add(1) returns each integer exactly once.
2024-03-19SeqCst->{Release,Acquire} for wasm DropLock.Mara Bos-3/+6
SeqCst is unnecessary. Release+Acquire is the right ordering for a mutex.
2024-03-19Use less restricted memory ordering in thread_parking::pthread.Mara Bos-10/+12
SeqCst is unnecessary here.
2024-03-19SeqCst->{Release,Acquire} in xous mutex.Mara Bos-4/+7
No need for SeqCst. Release+Acquire is the right memory ordering for a mutex.
2024-03-18Support for visionOSAdam Gastineau-13/+102
2024-03-17Expand sys/os for UEFIAyush Singh-10/+81
- Implement current_exe() - Cache device_path_to_text protocol Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-03-16Rollup merge of #122583 - Zoxc:tls-non-mut, r=joboetChris Denton-8/+7
Use `UnsafeCell` for fast constant thread locals This uses `UnsafeCell` instead of `static mut` for fast constant thread locals. This changes the type of the TLS shims to return `&UnsafeCell<T>` instead of `*mut T` which means they are always non-null so LLVM can optimize away the check for `Some` in `LocalKey::with` if `T` has no destructor. LLVM is currently unable to do this optimization as we lose the fact that `__getit` always returns `Some` as it gets optimized to just returning the value of the TLS shim.
2024-03-16Rollup merge of #122390 - ChrisDenton:bindgen, r=Mark-SimulacrumChris Denton-213/+211
Bump windows-bindgen to 0.55.0 windows-bindgen is the crate used to generate std's Windows API bindings. Not many changes for us, it's mostly just simplifying the generate code (e.g. no more `-> ()`). The one substantial change is some structs now use `i8` byte arrays instead of `u8`. However, this only impacts one test.
2024-03-16Use `UnsafeCell` for fast constant thread localsJohn Kåre Alsaker-8/+7
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-13Provide `cabi_realloc` on `wasm32-wasip2` by defaultAlex Crichton-0/+67
This commit provides a component model intrinsic in the standard library by default on the `wasm32-wasip2` target. This intrinsic is not required by the component model itself but is quite common to use, for example it's needed if a wasm module receives a string or a list. The intention of this commit is to provide an overridable definition in the standard library through a weak definition of this function. That means that downstream crates can provide their own customized and more specific versions if they'd like, but the standard library's version should suffice for general-purpose use.
2024-03-13Get wasm32-wasip2 compiling with its custom pal implementationAlex Crichton-9/+3
The ordering of targets in `pal/mod.rs` did not end up using the wasip2 implementation, so after reordering that I've edited the implementation to compile correctly.
2024-03-12Bump windows-bindgen to 0.55.0Chris Denton-183/+181
2024-03-12Bump windows-bindgen to 0.54.0Chris Denton-31/+31
2024-03-12std: move `Once` implementations to `sys`joboet-25/+488
2024-03-12Allow dead code in sys/palArthur Carcano-0/+6
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)]`. These structures API is common to all platforms so the code cannot be removed and is hence marked allow(dead_code).
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-11Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviperJubilee-4/+4
std support for wasm32 panic=unwind Tracking issue: #118168 This adds std support for `-Cpanic=unwind` on wasm, and with it slightly more fleshed out rustc support. Now, the stable default is still panic=abort without exception-handling, but if you `-Zbuild-std` with `RUSTFLAGS=-Cpanic=unwind`, you get wasm exception-handling try/catch blocks in the binary: ```rust #[no_mangle] pub fn foo_bar(x: bool) -> *mut u8 { let s = Box::<str>::from("hello"); maybe_panic(x); Box::into_raw(s).cast() } #[inline(never)] #[no_mangle] fn maybe_panic(x: bool) { if x { panic!("AAAAA"); } } ``` ```wat ;; snip... (try $label$5 (do (call $maybe_panic (local.get $0) ) (br $label$1) ) (catch_all (global.set $__stack_pointer (local.get $1) ) (call $__rust_dealloc (local.get $2) (i32.const 5) (i32.const 1) ) (rethrow $label$5) ) ) ;; snip... ```
2024-03-11Auto merge of #122331 - jhpratt:rollup-cbl8xsy, r=jhprattbors-21/+45
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 #122326 - Zoxc:win-alloc-tweak, r=ChrisDentonJacob Pratt-19/+36
Optimize `process_heap_alloc` This optimizes `process_heap_alloc` introduced in https://github.com/rust-lang/rust/pull/120205. From: ``` .text:0000000180027ED0 ; std::sys::pal::windows::alloc::process_heap_alloc::h703a613b3e25ff93 .text:0000000180027ED0 public _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h703a613b3e25ff93E .text:0000000180027ED0 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h703a613b3e25ff93E proc near .text:0000000180027ED0 ; CODE XREF: std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+23↑p .text:0000000180027ED0 ; std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+55↑p ... .text:0000000180027ED0 push rsi .text:0000000180027ED1 push rdi .text:0000000180027ED2 sub rsp, 28h .text:0000000180027ED6 mov rsi, rdx .text:0000000180027ED9 mov edi, ecx .text:0000000180027EDB mov rcx, cs:_ZN3std3sys3pal7windows5alloc4HEAP17hb53ca4010cc29b62E ; std::sys::pal::windows::alloc::HEAP::hb53ca4010cc29b62 .text:0000000180027EE2 test rcx, rcx .text:0000000180027EE5 jnz short loc_180027EFC .text:0000000180027EE7 call cs:__imp_GetProcessHeap .text:0000000180027EED test rax, rax .text:0000000180027EF0 jz short loc_180027F0E .text:0000000180027EF2 mov rcx, rax .text:0000000180027EF5 mov cs:_ZN3std3sys3pal7windows5alloc4HEAP17hb53ca4010cc29b62E, rax ; std::sys::pal::windows::alloc::HEAP::hb53ca4010cc29b62 .text:0000000180027EFC .text:0000000180027EFC loc_180027EFC: ; CODE XREF: std::sys::pal::windows::alloc::process_heap_alloc::h703a613b3e25ff93+15↑j .text:0000000180027EFC mov edx, edi .text:0000000180027EFE mov r8, rsi .text:0000000180027F01 add rsp, 28h .text:0000000180027F05 pop rdi .text:0000000180027F06 pop rsi .text:0000000180027F07 jmp cs:__imp_HeapAlloc .text:0000000180027F0E ; --------------------------------------------------------------------------- .text:0000000180027F0E .text:0000000180027F0E loc_180027F0E: ; CODE XREF: std::sys::pal::windows::alloc::process_heap_alloc::h703a613b3e25ff93+20↑j .text:0000000180027F0E xor eax, eax .text:0000000180027F10 add rsp, 28h .text:0000000180027F14 pop rdi .text:0000000180027F15 pop rsi .text:0000000180027F16 retn .text:0000000180027F16 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h703a613b3e25ff93E endp ``` to ``` .text:0000000180027EE0 ; std::sys::pal::windows::alloc::process_heap_alloc::h70f9d61a631e5c16 .text:0000000180027EE0 public _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h70f9d61a631e5c16E .text:0000000180027EE0 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h70f9d61a631e5c16E proc near .text:0000000180027EE0 ; CODE XREF: std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+23↑p .text:0000000180027EE0 ; std::sys::pal::common::alloc::realloc_fallback::hc4c96b4c24d03e77+54↑p ... .text:0000000180027EE0 mov rcx, cs:_ZN3std3sys3pal7windows5alloc4HEAP17hb53ca4010cc29b62E ; std::sys::pal::windows::alloc::HEAP::hb53ca4010cc29b62 .text:0000000180027EE7 test rcx, rcx .text:0000000180027EEA jz short loc_180027EF3 .text:0000000180027EEC jmp cs:__imp_HeapAlloc .text:0000000180027EF3 ; --------------------------------------------------------------------------- .text:0000000180027EF3 .text:0000000180027EF3 loc_180027EF3: ; CODE XREF: std::sys::pal::windows::alloc::process_heap_alloc::h70f9d61a631e5c16+A↑j .text:0000000180027EF3 mov ecx, edx .text:0000000180027EF5 mov rdx, r8 .text:0000000180027EF8 jmp std__sys__pal__windows__alloc__process_heap_init_and_alloc .text:0000000180027EF8 _ZN3std3sys3pal7windows5alloc18process_heap_alloc17h70f9d61a631e5c16E endp ``` r? `@ChrisDenton`
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-11Rollup merge of #121633 - ChrisDenton:precise, r=NilstriebJacob Pratt-0/+6
Win10: Use `GetSystemTimePreciseAsFileTime` directly On Windows 10 we can use `GetSystemTimePreciseAsFileTime` directly instead of lazy loading it (with a fallback).
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-11Optimize `process_heap_alloc`John Kåre Alsaker-19/+36
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-10Rollup merge of #113525 - workingjubilee:handle-dynamic-minsigstksz, r=m-ou-seMatthias Krüger-11/+39
Dynamically size sigaltstk in std 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. Fixes https://github.com/rust-lang/rust/issues/107795
2024-03-09Rollup merge of #121711 - ChrisDenton:junction, r=Mark-SimulacrumGuillaume Boisseau-74/+69
Implement junction_point Implements https://github.com/rust-lang/rust/issues/121709 We already had a private implementation that we use for tests so we could just make that public. Except it was very hacky as it was only ever intended for use in testing. I've made an improved version that at least handles path conversion correctly and has less need for things like the `Align8` hack. There's still room for further improvement though.
2024-03-08further changes from feedbackDavid Carlier-19/+1
2024-03-07Rust is a proper name: rust → RustRalf Jung-1/+1
2024-03-06Document and test minimal stack size on WindowsChris Denton-0/+2
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-06Remove unnecessary fixmeChris Denton-5/+0
As the FIXME itself notes, there's nothing to fix here.
2024-03-06Be stricter with `copy_file_range` probe resultsTobias Bucher-33/+35
2024-03-06Less syscalls for the `copy_file_range` probeTobias Bucher-23/+48
If it's obvious from the actual syscall results themselves that the syscall is supported or unsupported, don't do an extra syscall with an invalid file descriptor. CC #122052
2024-03-06unix time module now return resultAntoine PLASKOWSKI-51/+35
2024-03-05Add `Waitable` traitChris Denton-10/+43
2024-03-05Windows: Implement mutex using futexChris Denton-30/+103
Well, the Windows equivalent: `WaitOnAddress`, `WakeByAddressSingle` and `WakeByAddressAll`.
2024-03-04std::threads: revisit stack address calculation on netbsd.David Carlier-2/+21
like older linux glibc versions, we need to get the guard size and increasing the stack's bottom address accordingly.
2024-03-03std::rand: enable getrandom for dragonflybsd too.David Carlier-1/+9
2024-03-03Add missing get_name for wasm::thread.Ian Neumann-0/+4
2024-03-03Auto merge of #121856 - ChrisDenton:abort, r=joboetbors-10/+13
Cleanup windows `abort_internal` As the comments on the functions say, we define abort in both in panic_abort and in libstd. This PR makes the two implementation (mostly) the same. Additionally it: * uses `options(noreturn)` on the asm instead of using `core::intrinsics::unreachable`. * removed unnecessary allow lints * added `FAST_FAIL_FATAL_APP_EXIT` to our generated Windows API bindings instead of defining it manually (std only)
2024-03-02Cleanup windows abort_internalChris Denton-10/+13
2024-03-02Rollup merge of #121758 - joboet:move_pal_thread_local, r=ChrisDentonMatthias Krüger-2/+3
Move thread local implementation to `sys` Part of #117276.
2024-03-02Rollup merge of #121666 - ChrisDenton:thread-name, r=cuviperMatthias Krüger-10/+115
Use the OS thread name by default if `THREAD_INFO` has not been initialized Currently if `THREAD_INFO` hasn't been initialized then the name will be set to `None`. This PR changes it to use the OS thread name by default. This mostly affects foreign threads at the moment but we could expand this to make more use of the OS thread name in the future. Note: I've only implemented `Thread::get_name` for windows, linux and macos (and macos adjacent) targets. The rest just return `None`.
2024-03-01Add `get_name` placeholder to other targetsChris Denton-8/+40
2024-03-01revise interface to read directory entriesStefan Lankes-97/+116
The new interface has some similarities to Linux system call getdents64. The system call reads several dirent64 structures. At the end of each dirent64 is stored the name of the file. The length of file name is implictly part of dirent64 because d_reclen contains size of dirent64 plus the length of the file name.
2024-03-01Extending filesystem support for hermit-ossimonschoening-96/+225
2024-03-01Auto merge of #114016 - krtab:delete_sys_memchr, r=workingjubileebors-91/+6
Delete architecture-specific memchr code in std::sys Currently all architecture-specific memchr code is only used in `std::io`. Most of the actual `memchr` capacity exposed to the user through the slice API is instead implemented in `core::slice::memchr`. Hence this commit deletes `memchr` from `std::sys[_common]` and replace calls to it by calls to `core::slice::memchr` functions. This deletes `(r)memchr` from the list of symbols linked to libc. The interest of putting architecture specific code back in core is linked to the discussion to be had in #113654