Skip to content

Commit fae29fd

Browse files
committed
Auto merge of rust-lang#3283 - devnexen:fbsd_affinity, r=oli-obk
moving out sched_getaffinity interception from linux'shim, FreeBSD su… …pporting it too.
2 parents 562d529 + e47bb90 commit fae29fd

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/tools/miri/ci/ci.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ case $HOST_TARGET in
121121
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
122122
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
123123
# Some targets are only partially supported.
124-
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align
125-
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align
124+
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
125+
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
126+
126127
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
127128
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings wasm
128129
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings wasm

src/tools/miri/src/shims/unix/foreign_items.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
711711
}
712712
}
713713

714+
"sched_getaffinity" => {
715+
// FreeBSD supports it as well since 13.1 (as a wrapper of cpuset_getaffinity)
716+
if !matches!(&*this.tcx.sess.target.os, "linux" | "freebsd") {
717+
throw_unsup_format!(
718+
"`sched_getaffinity` is not supported on {}",
719+
this.tcx.sess.target.os
720+
);
721+
}
722+
let [pid, cpusetsize, mask] =
723+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
724+
this.read_scalar(pid)?.to_i32()?;
725+
this.read_target_usize(cpusetsize)?;
726+
this.deref_pointer_as(mask, this.libc_ty_layout("cpu_set_t"))?;
727+
// FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
728+
let einval = this.eval_libc("EINVAL");
729+
this.set_last_error(einval)?;
730+
this.write_scalar(Scalar::from_i32(-1), dest)?;
731+
}
732+
714733
// Platform-specific shims
715734
_ => {
716735
let target_os = &*this.tcx.sess.target.os;

src/tools/miri/src/shims/unix/linux/foreign_items.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
197197
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
198198
getrandom(this, ptr, len, flags, dest)?;
199199
}
200-
"sched_getaffinity" => {
201-
let [pid, cpusetsize, mask] =
202-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
203-
this.read_scalar(pid)?.to_i32()?;
204-
this.read_target_usize(cpusetsize)?;
205-
this.deref_pointer_as(mask, this.libc_ty_layout("cpu_set_t"))?;
206-
// FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
207-
let einval = this.eval_libc("EINVAL");
208-
this.set_last_error(einval)?;
209-
this.write_scalar(Scalar::from_i32(-1), dest)?;
210-
}
211200

212201
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
213202
// These shims are enabled only when the caller is in the standard library.

0 commit comments

Comments
 (0)