-
Notifications
You must be signed in to change notification settings - Fork 390
Android: Added syscall support #3992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod eventfd; | |
pub mod foreign_items; | ||
pub mod mem; | ||
pub mod sync; | ||
pub mod syscall; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.