Skip to content

Commit 5e9bf46

Browse files
committed
Auto merge of #1683 - frewsxcv:frewsxcv-nprocessors, r=RalfJung
Add shim for libc::sysconf(libc::_SC_NPROCESSORS_CONF) `libc::sysconf(libc::_SC_NPROCESSORS_CONF)` is used by AArch64 devices to get the number of CPUs in the `num_cpus` crate: https://github.com/seanmonstar/num_cpus/blob/b423db0a698b035914ae1fd6b7ce5d2a4e727b46/src/lib.rs#L337-L342
2 parents e3ca994 + 7d8f8c4 commit 5e9bf46

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ run_tests
4747
case $HOST_TARGET in
4848
x86_64-unknown-linux-gnu)
4949
MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
50-
MIRI_TEST_TARGET=x86_64-apple-darwin run_tests
50+
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
5151
MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
5252
;;
5353
x86_64-apple-darwin)

src/shims/foreign_items.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
484484
let &[] = check_arg_count(args)?;
485485
this.yield_active_thread();
486486
}
487+
"llvm.aarch64.hint" if this.tcx.sess.target.arch == "aarch64" => {
488+
let &[hint] = check_arg_count(args)?;
489+
let hint = this.read_scalar(hint)?.to_i32()?;
490+
match hint {
491+
1 => { // HINT_YIELD
492+
this.yield_active_thread();
493+
}
494+
_ => {
495+
throw_unsup_format!("unsupported llvm.aarch64.hint argument {}", hint);
496+
}
497+
}
498+
}
487499

488500
// Platform-specific shims
489501
_ => match this.tcx.sess.target.os.as_str() {

src/shims/posix/foreign_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
180180

181181
let sysconfs = &[
182182
("_SC_PAGESIZE", Scalar::from_int(PAGE_SIZE, this.pointer_size())),
183+
("_SC_NPROCESSORS_CONF", Scalar::from_int(NUM_CPUS, this.pointer_size())),
183184
("_SC_NPROCESSORS_ONLN", Scalar::from_int(NUM_CPUS, this.pointer_size())),
184185
];
185186
let mut result = None;

src/shims/posix/macos/foreign_items.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2525
}
2626

2727
// File related shims
28-
"close$NOCANCEL" => {
28+
"close" | "close$NOCANCEL" => {
2929
let &[result] = check_arg_count(args)?;
3030
let result = this.close(result)?;
3131
this.write_scalar(Scalar::from_i32(result), dest)?;
3232
}
33-
"stat$INODE64" => {
33+
"stat" | "stat$INODE64" => {
3434
let &[path, buf] = check_arg_count(args)?;
3535
let result = this.macos_stat(path, buf)?;
3636
this.write_scalar(Scalar::from_i32(result), dest)?;
3737
}
38-
"lstat$INODE64" => {
38+
"lstat" | "lstat$INODE64" => {
3939
let &[path, buf] = check_arg_count(args)?;
4040
let result = this.macos_lstat(path, buf)?;
4141
this.write_scalar(Scalar::from_i32(result), dest)?;
4242
}
43-
"fstat$INODE64" => {
43+
"fstat" | "fstat$INODE64" => {
4444
let &[fd, buf] = check_arg_count(args)?;
4545
let result = this.macos_fstat(fd, buf)?;
4646
this.write_scalar(Scalar::from_i32(result), dest)?;
4747
}
48-
"opendir$INODE64" => {
48+
"opendir" | "opendir$INODE64" => {
4949
let &[name] = check_arg_count(args)?;
5050
let result = this.opendir(name)?;
5151
this.write_scalar(result, dest)?;
5252
}
53-
"readdir_r$INODE64" => {
53+
"readdir_r" | "readdir_r$INODE64" => {
5454
let &[dirp, entry, result] = check_arg_count(args)?;
5555
let result = this.macos_readdir_r(dirp, entry, result)?;
5656
this.write_scalar(Scalar::from_i32(result), dest)?;

0 commit comments

Comments
 (0)