Skip to content

Commit 7eda989

Browse files
committed
Auto merge of rust-lang#3557 - RalfJung:getaffinity, r=RalfJung
Move sched_getaffinity back to Linux This reverts commit c1a3f8576ea12b0bed68ad3dedf4069ca3d9816f. The shim isn't actually useful for anything, and it is untested on FreeBSD. On Linux it exists solely because std and num_cpus are trying this before falling back to `sysconf`, but on FreeBSD that's not how they work, so there's no reason I can see to have this stub shim on FreeBSD.
2 parents c3f2701 + e1c3d67 commit 7eda989

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

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

-19
Original file line numberDiff line numberDiff line change
@@ -724,25 +724,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
724724
}
725725
}
726726

727-
"sched_getaffinity" => {
728-
// FreeBSD supports it as well since 13.1 (as a wrapper of cpuset_getaffinity)
729-
if !matches!(&*this.tcx.sess.target.os, "linux" | "freebsd") {
730-
throw_unsup_format!(
731-
"`sched_getaffinity` is not supported on {}",
732-
this.tcx.sess.target.os
733-
);
734-
}
735-
let [pid, cpusetsize, mask] =
736-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
737-
this.read_scalar(pid)?.to_i32()?;
738-
this.read_target_usize(cpusetsize)?;
739-
this.deref_pointer_as(mask, this.libc_ty_layout("cpu_set_t"))?;
740-
// FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
741-
let einval = this.eval_libc("EINVAL");
742-
this.set_last_error(einval)?;
743-
this.write_scalar(Scalar::from_i32(-1), dest)?;
744-
}
745-
746727
// Platform-specific shims
747728
_ => {
748729
let target_os = &*this.tcx.sess.target.os;

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

+13
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
184184

185185
this.write_scalar(Scalar::from_i32(SIGRTMAX), dest)?;
186186
}
187+
"sched_getaffinity" => {
188+
// This shim isn't useful, aside from the fact that it makes `num_cpus`
189+
// fall back to `sysconf` where it will successfully determine the number of CPUs.
190+
let [pid, cpusetsize, mask] =
191+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
192+
this.read_scalar(pid)?.to_i32()?;
193+
this.read_target_usize(cpusetsize)?;
194+
this.deref_pointer_as(mask, this.libc_ty_layout("cpu_set_t"))?;
195+
// FIXME: we just return an error.
196+
let einval = this.eval_libc("EINVAL");
197+
this.set_last_error(einval)?;
198+
this.write_scalar(Scalar::from_i32(-1), dest)?;
199+
}
187200

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

0 commit comments

Comments
 (0)