about summary refs log tree commit diff
path: root/library/std/src/sys/unix
AgeCommit message (Collapse)AuthorLines
2022-06-04Auto merge of #97191 - wesleywiser:main_thread_name, r=ChrisDentonbors-0/+10
Call the OS function to set the main thread's name on program init Normally, `Thread::spawn` takes care of setting the thread's name, if one was provided, but since the main thread wasn't created by calling `Thread::spawn`, we need to call that function in `std::rt::init`. This is mainly useful for system tools like debuggers and profilers which might show the thread name to a user. Prior to these changes, gdb and WinDbg would show all thread names except the main thread's name to a user. I've validated that this patch resolves the issue for both debuggers.
2022-06-04keep using poll as fast path and only use fcntl as fallbackThe 8472-19/+64
this minimizes the amount of syscalls performed during startup
2022-06-04Rollup merge of #97647 - m-ou-se:lazy-box-locks, r=AmanieuDylan DPC-28/+62
Lazily allocate and initialize pthread locks. Lazily allocate and initialize pthread locks. This allows {Mutex, Condvar, RwLock}::new() to be const, while still using the platform's native locks for features like priority inheritance and debug tooling. E.g. on macOS, we cannot directly use the (private) APIs that pthread's locks are implemented with, making it impossible for us to use anything other than pthread while still preserving priority inheritance, etc. This PR doesn't yet make the public APIs const. That's for a separate PR with an FCP. Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-06-03Auto merge of #95833 - notriddle:notriddle/human-readable-signals, r=yaahcbors-6/+82
std: `<ExitStatus as Display>::fmt` name the signal it died from Related to #95601
2022-06-03Lazily allocate+initialize locks.Mara Bos-14/+36
2022-06-03Use Drop instead of destroy() for locks.Mara Bos-14/+26
2022-06-02Fix MIPS-specific signal bugMichael Howell-1/+10
2022-06-01std: show signal number along with nameMichael Howell-46/+50
2022-05-30Remove "sys isn't exported yet" phraseest31-1/+0
The oldest occurence is from 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7, which is from the pre-1.0 days. In the years since then, std::sys still hasn't been exported, and the last attempt was met with strong criticism: https://github.com/rust-lang/rust/pull/97151 Thus, removing the "yet" part makes a lot of sense.
2022-05-27Call the OS function to set the main thread's name on program initWesley Wiser-0/+10
Normally, `Thread::spawn` takes care of setting the thread's name, if one was provided, but since the main thread wasn't created by calling `Thread::spawn`, we need to call that function in `std::rt::init`. This is mainly useful for system tools like debuggers and profilers which might show the thread name to a user. Prior to these changes, gdb and WinDbg would show all thread names except the main thread's name to a user. I've validated that this patch resolves the issue for both debuggers.
2022-05-25Disable unix::net::ancillary on BSD.Mara Bos-18/+2
2022-05-21Fix typo in futex RwLock::write_contended.Mara Bos-3/+2
I wrote `state` where I should've used `s`. This removes the unnecessary `s` variable to prevent that mistake. Fortunately, this typo didn't affect the correctness of the lock, as the second half of the condition (!has_writers_waiting) is enough for correctness, which explains why this mistake didn't show up during testing.
2022-05-21Use GRND_INSECURE instead of /dev/urandom when possibleJason A. Donenfeld-0/+15
From reading the source code, it appears like the desired semantic of std::unix::rand is to always provide some bytes and never block. For that reason GRND_NONBLOCK is checked before calling getrandom(0), so that getrandom(0) won't block. If it would block, then the function falls back to using /dev/urandom, which for the time being doesn't block. There are some drawbacks to using /dev/urandom, however, and so getrandom(GRND_INSECURE) was created as a replacement for this exact circumstance. getrandom(GRND_INSECURE) is the same as /dev/urandom, except: - It won't leave a warning in dmesg if used at early boot time, which is a common occurance (and the reason why I found this issue); - It won't introduce a tiny delay at early boot on newer kernels when /dev/urandom tries to opportunistically create jitter entropy; - It only requires 1 syscall, rather than 3. Other than that, it returns the same "quality" of randomness as /dev/urandom, and never blocks. It's only available on kernels ≥5.6, so we try to use it, cache the result of that attempt, and fall back to to the previous code if it didn't work.
2022-05-11Use `fcntl(fd, F_GETFD)` to detect if standard streams are openTomasz Miąsko-31/+6
In the previous implementation, if the standard streams were open, but the RLIMIT_NOFILE value was below three, the poll would fail with EINVAL: > ERRORS: EINVAL The nfds value exceeds the RLIMIT_NOFILE value. Switch to the existing fcntl based implementation to avoid the issue.
2022-05-11to_timespec could be unused by some targetsSébastien Marie-0/+1
2022-05-11avoid using both Some() and ? on linux/android/freebsd codeSébastien Marie-1/+1
2022-05-11openbsd: convert futex timeout managment to Timespec usageSébastien Marie-9/+7
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-13/+0
2022-05-06Share more unix SystemTime codeJosh Stone-101/+57
2022-05-06Use statx's 64-bit times on 32-bit linux-gnuJosh Stone-38/+79
2022-05-06Use __clock_gettime64 on 32-bit linux-gnuJosh Stone-0/+27
2022-05-06unix: always use 64-bit TimespecJosh Stone-67/+65
2022-05-03Round timeouts up to infinite in futex_wait on DragonFlyBSD.Mara Bos-9/+8
2022-05-03Add #[cfg] in cfg_if for linux in unix/futex.Mara Bos-3/+5
2022-05-03Don't use futexes on netbsd.Mara Bos-43/+5
The latest NetBSD release doesn't include the futex syscall yet.
2022-04-29Disable pthread thread parker on futex platforms.Mara Bos-1/+5
2022-04-29Always return false in futex_wake on {Free,DragonFly}BSD.Mara Bos-16/+13
2022-04-29Use futex-based locks and thread parker on FreeBSD.Mara Bos-4/+59
2022-04-29Use futex-based locks and thread parker on DragonFlyBSD.Mara Bos-1/+43
2022-04-29Use futex-based locks and thread parker on NetBSD.Mara Bos-24/+52
2022-04-29Use futex-based locks and thread parker on OpenBSD.Mara Bos-1/+52
2022-04-28Auto merge of #96393 - joboet:pthread_parker, r=thomccbors-2/+268
std: directly use pthread in UNIX parker implementation `Mutex` and `Condvar` are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore we should use the `pthread` synchronization primitives directly. Also, we can avoid allocating the mutex and condition variable because the `Parker` struct is being placed in an `Arc` anyways. This basically is just a copy of the current `Mutex` and `Condvar` code, which will however be removed (again, see #93740). An alternative implementation could be to use dedicated private `OsMutex` and `OsCondvar` types, but all the other platforms supported by std actually have their own thread parking primitives. I used `Pin` to guarantee a stable address for the `Parker` struct, while the current implementation does not, rather using extra unsafe declaration. Since the thread struct is shared anyways, I assumed this would not add too much clutter while being clearer.
2022-04-28std: simplify UNIX parker timeoutsjoboet-59/+21
2022-04-25Remove references to git.ioEric Huss-1/+2
2022-04-25std: directly use pthread in UNIX parker implementationjoboet-0/+304
Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore use the pthread synchronization primitives directly. Also, avoid allocating because the Parker struct is being placed in an Arc anyways.
2022-04-24Auto merge of #94609 - esp-rs:esp-idf-stat-type-fixes, r=Mark-Simulacrumbors-3/+18
espidf: fix stat Marking as draft as currently dependant on [a libc fix](https://github.com/rust-lang/libc/pull/2708) and release.
2022-04-23std: `<ExitStatus as Display>::fmt` name the signal it died fromMichael Howell-3/+66
2022-04-21Rollup merge of #96193 - djkoloski:fuchsia_current_exe, r=tmandryDylan DPC-1/+21
[fuchsia] Add implementation for `current_exe` This implementation returns a best attempt at the current exe path. On fuchsia, fdio will always use `argv[0]` as the process name and if it is not set then an error will be returned. Because this is not guaranteed to be the case, this implementation returns an error if `argv` does not contain any elements.
2022-04-20Rollup merge of #96234 - goffrie:eloop, r=thomccDylan DPC-1/+2
remove_dir_all_recursive: treat ELOOP the same as ENOTDIR On older Linux kernels (I tested on 4.4, corresponding to Ubuntu 16.04), opening a symlink using `O_DIRECTORY | O_NOFOLLOW` returns `ELOOP` instead of `ENOTDIR`. We should handle it the same, since a symlink is still not a directory and needs to be `unlink`ed.
2022-04-20Rollup merge of #96167 - CAD97:weak-dlsym-less-ptr-crime, r=thomccDylan DPC-17/+15
Replace sys/unix/weak AtomicUsize with AtomicPtr Should fix #96163. Can't easily test on Windows though...
2022-04-20remove_dir_all_recursive: treat ELOOP the same as ENOTDIRGeoffry Song-1/+2
2022-04-19[fuchsia] Add implementation for `current_exe`David Koloski-1/+21
This implementation returns a best attempt at the current exe path. On fuchsia, fdio will always use `argv[0]` as the process name and if it is not set then an error will be returned. Because this is not guaranteed to be the case, this implementation returns an error if `argv` does not contain any elements.
2022-04-19espidf: fix statScott Mabin-3/+18
* corect type usage with new type definitions in libc
2022-04-19Use futex locks on emscripten.Mara Bos-0/+1
2022-04-19Make std::sys::unix::futex consistent on emscripten.Mara Bos-22/+25
2022-04-18Auto merge of #96042 - m-ou-se:one-reentrant-mutex, r=Amanieubors-146/+2
Use a single ReentrantMutex implementation on all platforms. This replaces all platform specific ReentrantMutex implementations by the one I added in #95727 for Linux, since that one does not depend on any platform specific details. r? `@Amanieu`
2022-04-17Replace sys/unix/weak AtomicUsize with AtomicPtrCAD97-17/+15
2022-04-17Auto merge of #93530 - anonion0:pthread_sigmask_fix, r=JohnTitorbors-4/+5
fix error handling for pthread_sigmask(3) Errors from `pthread_sigmask(3)` were handled using `cvt()`, which expects a return value of `-1` on error and uses `errno`. However, `pthread_sigmask(3)` returns `0` on success and an error number otherwise. Fix it by replacing `cvt()` with `cvt_nz()`.
2022-04-17move import to fix warning with emscripten targetRalf Sager-1/+2
2022-04-16Use a single ReentrantMutex implementation on all platforms.Mara Bos-146/+2