Skip to content

Commit 9eb94e8

Browse files
committed
moving out sched_getaffinity interception from linux'shim, FreeBSD supporting it too.
1 parent 71f8f49 commit 9eb94e8

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

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)