diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-09-19 11:35:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-19 11:35:52 +0200 |
| commit | 57f1f91a9c960d171a6de3ddaa3cd2b0f389597d (patch) | |
| tree | 3cbc05ff8f8f85bfe9034597e1fbff8ab160687a | |
| parent | f1edecfaab9e0490e21bae162faade9df686901d (diff) | |
| parent | a6d87246f6d1cee63d773311536ace19d1df78a3 (diff) | |
| download | rust-57f1f91a9c960d171a6de3ddaa3cd2b0f389597d.tar.gz rust-57f1f91a9c960d171a6de3ddaa3cd2b0f389597d.zip | |
Rollup merge of #115946 - the8472:panic-on-sched_getaffinity-bug, r=Mark-Simulacrum
panic when encountering an illegal cpumask in thread::available_parallelism Fixes #115868 by panicking instead of returning an invalid `NonZeroUsize`
| -rw-r--r-- | library/std/src/sys/unix/thread.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index 7c242d4d334..2afec897a88 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -324,8 +324,10 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { if libc::sched_getaffinity(0, mem::size_of::<libc::cpu_set_t>(), &mut set) == 0 { let count = libc::CPU_COUNT(&set) as usize; let count = count.min(quota); - // SAFETY: affinity mask can't be empty and the quota gets clamped to a minimum of 1 - return Ok(NonZeroUsize::new_unchecked(count)); + // reported to occur on MIPS kernels older than our minimum supported kernel version for those targets + let count = NonZeroUsize::new(count) + .expect("CPU count must be > 0. This may be a bug in sched_getaffinity(); try upgrading the kernel."); + return Ok(count); } } } |
