Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9622a79
Implement LLVM x86 vpclmulqdq intrinsics
TDecking Oct 22, 2024
05530b6
Adjust the vpclmulqdq test case
TDecking Oct 26, 2024
fb7bcd1
Merge pull request #3987 from TDecking/vpclmul
RalfJung Oct 27, 2024
cdc40a4
Add option for generating coverage reports
Mandragorian Oct 9, 2024
9023e35
Merge pull request #3954 from Mandragorian/coverage-report
RalfJung Oct 28, 2024
c8ce9e6
Android: Added syscall support
YohDeadfall Oct 25, 2024
f736269
Merge pull request #3992 from YohDeadfall/android-syscall
RalfJung Oct 28, 2024
6365ea1
contributing guide: mention expectations around force pushes and squa…
RalfJung Oct 27, 2024
d581d80
Merge pull request #3998 from RalfJung/contrib
oli-obk Oct 28, 2024
ff6e703
Preparing for merge from rustc
Oct 30, 2024
7d12e50
Merge from rustc
Oct 30, 2024
8a5f34a
Merge pull request #4001 from rust-lang/rustup-2024-10-30
RalfJung Oct 30, 2024
042f762
Change futex_wait errno from Scalar to IoError
noahmbright Oct 29, 2024
4ca9c07
Merge pull request #4000 from noahmbright/futex
RalfJung Oct 30, 2024
c5e86c4
Fixed a typo in the GetThreadDescription shim
YohDeadfall Oct 30, 2024
445a340
Merge pull request #4003 from YohDeadfall/windows-shim-typo
saethlin Oct 31, 2024
1c88af6
Preparing for merge from rustc
Oct 31, 2024
4828592
Merge from rustc
Oct 31, 2024
ef6b9a9
fmt
Oct 31, 2024
b8bd7be
silence clippy
RalfJung Oct 31, 2024
6630802
Merge pull request #4005 from rust-lang/rustup-2024-10-31
RalfJung Oct 31, 2024
06d869b
Preparing for merge from rustc
RalfJung Nov 2, 2024
3253cc6
Merge from rustc
RalfJung Nov 2, 2024
c1b8d66
teach clippy about IeeeFloat, and make all 'allow' into 'expect'
RalfJung Nov 2, 2024
c67ea44
Merge pull request #4009 from RalfJung/rustup
RalfJung Nov 2, 2024
9c75eff
Preparing for merge from rustc
Nov 3, 2024
b58cbe2
Merge from rustc
Nov 3, 2024
b17cf41
Merge pull request #4010 from rust-lang/rustup-2024-11-03
RalfJung Nov 3, 2024
dc62c34
Renamed ecx variales to this
YohDeadfall Nov 7, 2024
1254d8e
Get/set thread name shims return errors for invalid handles
YohDeadfall Oct 30, 2024
c8e089e
Merge pull request #4018 from YohDeadfall/ecx-name-standardization
RalfJung Nov 8, 2024
d7aceee
Merge pull request #4004 from YohDeadfall/thread-name-ice-fix
RalfJung Nov 8, 2024
beb8d6f
Preparing for merge from rustc
Nov 9, 2024
15d883e
Merge from rustc
Nov 9, 2024
c272bb4
Merge pull request #4019 from rust-lang/rustup-2024-11-09
saethlin Nov 9, 2024
fe39888
pthread-sync: avoid confusing error when running with preemption
RalfJung Nov 9, 2024
5ff90d0
Merge pull request #4020 from RalfJung/thread-sope
RalfJung Nov 9, 2024
ce7a560
Preparing for merge from rustc
RalfJung Nov 10, 2024
a01f37c
Merge from rustc
RalfJung Nov 10, 2024
a839fbf
Merge pull request #4021 from RalfJung/rustup
RalfJung Nov 10, 2024
d1a4812
store futexes in per-allocation data rather than globally
RalfJung Oct 12, 2024
673d9c3
Merge pull request #3971 from RalfJung/futex-virtual
RalfJung Nov 10, 2024
e8a3ffe
fix linux-futex test being accidentally disabled
RalfJung Nov 10, 2024
881f2ec
Merge pull request #4022 from RalfJung/linux-futex
RalfJung Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Android: Added syscall support
  • Loading branch information
YohDeadfall committed Oct 28, 2024
commit c8ce9e68d4cdae32b8a0859e4e381356452d2dc2
2 changes: 1 addition & 1 deletion src/tools/miri/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ case $HOST_TARGET in
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random threadname pthread fs libc-pipe
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap threadname pthread
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random sync threadname pthread
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
Expand Down
4 changes: 4 additions & 0 deletions src/tools/miri/src/shims/unix/android/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;

use crate::shims::unix::android::thread::prctl;
use crate::shims::unix::linux::syscall::syscall;
use crate::*;

pub fn is_dyn_sym(_name: &str) -> bool {
Expand All @@ -26,6 +27,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
}

// Dynamically invoked syscalls
"syscall" => syscall(this, link_name, abi, args, dest)?,

// Threading
"prctl" => prctl(this, link_name, abi, args, dest)?,

Expand Down
51 changes: 2 additions & 49 deletions src/tools/miri/src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use rustc_target::spec::abi::Abi;
use self::shims::unix::linux::epoll::EvalContextExt as _;
use self::shims::unix::linux::eventfd::EvalContextExt as _;
use self::shims::unix::linux::mem::EvalContextExt as _;
use self::shims::unix::linux::sync::futex;
use crate::helpers::check_min_arg_count;
use self::shims::unix::linux::syscall::syscall;
use crate::machine::{SIGRTMAX, SIGRTMIN};
use crate::shims::unix::*;
use crate::*;
Expand Down Expand Up @@ -117,53 +116,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

// Dynamically invoked syscalls
"syscall" => {
// We do not use `check_shim` here because `syscall` is variadic. The argument
// count is checked bellow.
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?;
// The syscall variadic function is legal to call with more arguments than needed,
// extra arguments are simply ignored. The important check is that when we use an
// argument, we have to also check all arguments *before* it to ensure that they
// have the right type.

let sys_getrandom = this.eval_libc("SYS_getrandom").to_target_usize(this)?;
let sys_futex = this.eval_libc("SYS_futex").to_target_usize(this)?;
let sys_eventfd2 = this.eval_libc("SYS_eventfd2").to_target_usize(this)?;

let [op] = check_min_arg_count("syscall", args)?;
match this.read_target_usize(op)? {
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
num if num == sys_getrandom => {
// Used by getrandom 0.1
// The first argument is the syscall id, so skip over it.
let [_, ptr, len, flags] =
check_min_arg_count("syscall(SYS_getrandom, ...)", args)?;

let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?;
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
// neither of which have any effect on our current PRNG.
// See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
let _flags = this.read_scalar(flags)?.to_i32()?;

this.gen_random(ptr, len)?;
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
}
// `futex` is used by some synchronization primitives.
num if num == sys_futex => {
futex(this, args, dest)?;
}
num if num == sys_eventfd2 => {
let [_, initval, flags] =
check_min_arg_count("syscall(SYS_evetfd2, ...)", args)?;

let result = this.eventfd(initval, flags)?;
this.write_int(result.to_i32()?, dest)?;
}
num => {
throw_unsup_format!("syscall: unsupported syscall number {num}");
}
}
syscall(this, link_name, abi, args, dest)?;
}

// Miscellaneous
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/src/shims/unix/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod eventfd;
pub mod foreign_items;
pub mod mem;
pub mod sync;
pub mod syscall;
63 changes: 63 additions & 0 deletions src/tools/miri/src/shims/unix/linux/syscall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;

use self::shims::unix::linux::eventfd::EvalContextExt as _;
use crate::helpers::check_min_arg_count;
use crate::shims::unix::linux::sync::futex;
use crate::*;

pub fn syscall<'tcx>(
this: &mut MiriInterpCx<'tcx>,
link_name: Symbol,
abi: Abi,
args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx> {
// We do not use `check_shim` here because `syscall` is variadic. The argument
// count is checked bellow.
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?;
// The syscall variadic function is legal to call with more arguments than needed,
// extra arguments are simply ignored. The important check is that when we use an
// argument, we have to also check all arguments *before* it to ensure that they
// have the right type.

let sys_getrandom = this.eval_libc("SYS_getrandom").to_target_usize(this)?;
let sys_futex = this.eval_libc("SYS_futex").to_target_usize(this)?;
let sys_eventfd2 = this.eval_libc("SYS_eventfd2").to_target_usize(this)?;

let [op] = check_min_arg_count("syscall", args)?;
match this.read_target_usize(op)? {
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
num if num == sys_getrandom => {
// Used by getrandom 0.1
// The first argument is the syscall id, so skip over it.
let [_, ptr, len, flags] = check_min_arg_count("syscall(SYS_getrandom, ...)", args)?;

let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?;
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
// neither of which have any effect on our current PRNG.
// See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
let _flags = this.read_scalar(flags)?.to_i32()?;

this.gen_random(ptr, len)?;
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
}
// `futex` is used by some synchronization primitives.
num if num == sys_futex => {
futex(this, args, dest)?;
}
num if num == sys_eventfd2 => {
let [_, initval, flags] = check_min_arg_count("syscall(SYS_evetfd2, ...)", args)?;

let result = this.eventfd(initval, flags)?;
this.write_int(result.to_i32()?, dest)?;
}
num => {
throw_unsup_format!("syscall: unsupported syscall number {num}");
}
};

interp_ok(())
}
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@only-target: linux
//@only-target: android
//@compile-flags: -Zmiri-disable-isolation

// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
Expand Down
41 changes: 21 additions & 20 deletions src/tools/miri/tests/pass-dep/libc/libc-random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,27 @@ fn test_getrandom() {

let mut buf = [0u8; 5];
unsafe {
#[cfg(target_os = "linux")]
assert_eq!(
libc::syscall(
libc::SYS_getrandom,
ptr::null_mut::<libc::c_void>(),
0 as libc::size_t,
0 as libc::c_uint,
),
0,
);
#[cfg(target_os = "linux")]
assert_eq!(
libc::syscall(
libc::SYS_getrandom,
buf.as_mut_ptr() as *mut libc::c_void,
5 as libc::size_t,
0 as libc::c_uint,
),
5,
);
#[cfg(any(target_os = "linux", target_os = "android"))]
{
assert_eq!(
libc::syscall(
libc::SYS_getrandom,
ptr::null_mut::<libc::c_void>(),
0 as libc::size_t,
0 as libc::c_uint,
),
0,
);
assert_eq!(
libc::syscall(
libc::SYS_getrandom,
buf.as_mut_ptr() as *mut libc::c_void,
5 as libc::size_t,
0 as libc::c_uint,
),
5,
);
}

assert_eq!(
libc::getrandom(ptr::null_mut::<libc::c_void>(), 0 as libc::size_t, 0 as libc::c_uint),
Expand Down