Skip to content

Commit 57f1f91

Browse files
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`
2 parents f1edecf + a6d8724 commit 57f1f91

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: library/std/src/sys/unix/thread.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
324324
if libc::sched_getaffinity(0, mem::size_of::<libc::cpu_set_t>(), &mut set) == 0 {
325325
let count = libc::CPU_COUNT(&set) as usize;
326326
let count = count.min(quota);
327-
// SAFETY: affinity mask can't be empty and the quota gets clamped to a minimum of 1
328-
return Ok(NonZeroUsize::new_unchecked(count));
327+
// reported to occur on MIPS kernels older than our minimum supported kernel version for those targets
328+
let count = NonZeroUsize::new(count)
329+
.expect("CPU count must be > 0. This may be a bug in sched_getaffinity(); try upgrading the kernel.");
330+
return Ok(count);
329331
}
330332
}
331333
}

0 commit comments

Comments
 (0)