about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2022-06-15Test `copy_to_userspace` functionRaoul Strackx-1/+33
2022-06-15Ensure userspace allocation is 8-byte alignedRaoul Strackx-1/+4
2022-06-15Mitigate MMIO stale data vulnerabilitiesRaoul Strackx-2/+98
Intel Security Advisory: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00615.html
2022-06-15Unify copying data from enclave to userspaceRaoul Strackx-7/+3
2022-06-14Implement stabilization of `#[feature(io_safety)]`.Dan Gohman-6/+6
Implement stabilization of [I/O safety], aka `#[feature(io_safety)]`. Fixes #87074. [I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
2022-06-14Rollup merge of #98042 - DrMeepster:winfred_std_changes, r=ChrisDentonDylan DPC-8/+10
Fix compat_fn option method on miri This change is required to make `WaitOnAddress` work with rust-lang/miri#2231
2022-06-13Enable thread_local_dtor on horizon OSIan Chamberlain-1/+1
Always use fallback thread_local destructor, since __cxa_thread_atexit_impl is never defined on the target. See https://github.com/AzureMarker/rust-horizon/pull/2
2022-06-13Update libc::stat field namesIan Chamberlain-1/+6
See https://github.com/Meziu/rust-horizon/pull/14
2022-06-13Enable argv support for horizon OSIan Chamberlain-4/+7
See https://github.com/Meziu/rust-horizon/pull/9
2022-06-13Use the right wait_timeout implementationAzureMarker-7/+7
Our condvar doesn't support setting attributes, like pthread_condattr_setclock, which the current wait_timeout expects to have configured. Switch to a different implementation, following espidf.
2022-06-13Horizon OS STD supportMeziu-54/+87
Co-authored-by: Ian Chamberlain <ian.h.chamberlain@gmail.com> Co-authored-by: Mark Drobnak <mark.drobnak@gmail.com>
2022-06-13add inline(always) to optionDrMeepster-0/+1
2022-06-11fix compat_fn option method on miriDrMeepster-8/+9
2022-06-10Auto merge of #96837 - tmiasko:stdio-fcntl, r=joshtriplettbors-35/+56
Use `fcntl(fd, F_GETFD)` to detect if standard streams are open 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. Fixes #96621.
2022-06-10use fcntl fallback for additional poll-specific errorsThe 8472-7/+8
2022-06-09add cgroupv1 support to available_parallelismThe 8472-47/+126
2022-06-09Implement ExitCodeExt for WindowsAron Parker-0/+6
2022-06-08remove unneeded codeStefan Lankes-5/+0
2022-06-07Windows: No panic if function not (yet) availableChris Denton-4/+5
In some situations it is possible for required functions to be called before they've had a chance to be loaded. Therefore, we make it possible to recover from this situation simply by looking at error codes.
2022-06-06Make all {Mutex, Condvar, RwLock}::new #[inline].Mara Bos-0/+8
2022-06-05Remove SIGIO reference on HaikuRyan Zoeller-0/+1
Haiku doesn't define SIGIO. The nix crate already employs this workaround: https://github.com/nix-rust/nix/blob/5dedbc7850448ae3922ab0a833f3eb971bf7e25f/src/sys/signal.rs#L92-L94
2022-06-04Auto merge of #97191 - wesleywiser:main_thread_name, r=ChrisDentonbors-1/+15
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-90/+101
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-28/+62
2022-06-03Use Drop instead of destroy() for locks.Mara Bos-62/+39
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-1/+15
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-19std: fix deadlock in `Parker`joboet-4/+9
2022-05-19Rollup merge of #97127 - Mark-Simulacrum:revert-96441, r=m-ou-seYuki Okushi-119/+31
Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se" This reverts commit ddb7fbe8434be481607ae199fe2aee976ee2fc2e. Partially addresses https://github.com/rust-lang/rust/issues/97124, but not marking as fixed as we're still pending on a beta backport (for 1.62, which is happening in https://github.com/rust-lang/rust/pull/97088). r? ``@m-ou-se`` ``@ChrisDenton``
2022-05-18std: use an event flag based thread parker on SOLIDjoboet-3/+114
2022-05-18Rollup merge of #96917 - marti4d:master, r=ChrisDentonDylan DPC-4/+74
Make HashMap fall back to RtlGenRandom if BCryptGenRandom fails With PR #84096, Rust `std::collections::hash_map::RandomState` changed from using `RtlGenRandom()` ([msdn](https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom)) to `BCryptGenRandom()` ([msdn](https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom)) as its source of secure randomness after much discussion ([here](https://github.com/rust-random/getrandom/issues/65#issuecomment-753634074), among other places). Unfortunately, after that PR landed, Mozilla Firefox started experiencing fairly-rare crashes during startup while attempting to initialize the `env_logger` crate. ([docs for env_logger](https://docs.rs/env_logger/latest/env_logger/)) The root issue is that on some machines, `BCryptGenRandom()` will fail with an `Access is denied. (os error 5)` error message. ([Bugzilla issue 1754490](https://bugzilla.mozilla.org/show_bug.cgi?id=1754490)) (Discussion in issue #94098) Note that this is happening upon startup of Firefox's unsandboxed Main Process, so this behavior is different and separate from previous issues ([like this](https://bugzilla.mozilla.org/show_bug.cgi?id=1746254)) where BCrypt DLLs were blocked by process sandboxing. In the case of sandboxing, we knew we were doing something abnormal and expected that we'd have to resort to abnormal measures to make it work. However, in this case we are in a regular unsandboxed process just trying to initialize `env_logger` and getting a panic. We suspect that this may be caused by a virus scanner or some other security software blocking the loading of the BCrypt DLLs, but we're not completely sure as we haven't been able to replicate locally. It is also possible that Firefox is not the only software affected by this; we just may be one of the pieces of Rust software that has the telemetry and crash reporting necessary to catch it. I have read some of the historical discussion around using `BCryptGenRandom()` in Rust code, and I respect the decision that was made and agree that it was a good course of action, so I'm not trying to open a discussion about a return to `RtlGenRandom()`. Instead, I'd like to suggest that perhaps we use `RtlGenRandom()` as a "fallback RNG" in the case that BCrypt doesn't work. This pull request implements this fallback behavior. I believe this would improve the robustness of this essential data structure within the standard library, and I see only 2 potential drawbacks: 1. Slight added overhead: It should be quite minimal though. The first call to `sys::rand::hashmap_random_keys()` will incur a bit of initialization overhead, and every call after will incur roughly 2 non-atomic global reads and 2 easily predictable branches. Both should be negligible compared to the actual cost of generating secure random numbers 2. `RtlGenRandom()` is deprecated by Microsoft: Technically true, but as mentioned in [this comment on GoLang](https://github.com/golang/go/issues/33542#issuecomment-626124873), this API is ubiquitous in Windows software and actually removing it would break lots of things. Also, Firefox uses it already in [our C++ code](https://searchfox.org/mozilla-central/rev/5f88c1d6977e03e22d3420d0cdf8ad0113c2eb31/mfbt/RandomNum.cpp#25), and [Chromium uses it in their code as well](https://source.chromium.org/chromium/chromium/src/+/main:base/rand_util_win.cc) (which transitively means that Microsoft uses it in their own web browser, Edge). If there did come a time when Microsoft truly removes this API, it should be easy enough for Rust to simply remove the fallback in the code I've added here
2022-05-17Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se"Mark Rousskov-119/+31
This reverts commit ddb7fbe8434be481607ae199fe2aee976ee2fc2e, reversing changes made to baaa3b682986879c7784b5733ecea942e9ae7de3.
2022-05-16Improve error message for fallback RNG failureChris Martin-1/+1
2022-05-15fix use of SetHandleInformation on UWPbdbai-1/+13
2022-05-13Address review feedbackChris Martin-31/+22
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-10Make HashMap fall back to RtlGenRandom if BCryptGenRandom failsChris Martin-4/+83
Issue #84096 changed the hashmap RNG to use BCryptGenRandom instead of RtlGenRandom on Windows. Mozilla Firefox started experiencing random failures in env_logger::Builder::new() (Issue #94098) during initialization of their unsandboxed main process with an "Access Denied" error message from BCryptGenRandom(), which is used by the HashMap contained in env_logger::Builder The root cause appears to be a virus scanner or other software interfering with BCrypt DLLs loading. This change adds a fallback option if BCryptGenRandom is unusable for whatever reason. It will fallback to RtlGenRandom in this case. Fixes #94098
2022-05-11Rollup merge of #96861 - m-ou-se:std-use-prelude-2021, r=joshtriplettYuki Okushi-29/+2
Use Rust 2021 prelude in std itself.
2022-05-10Expose process main_thread_handle on Windowsunknown-7/+38
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-29/+2