-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic support for android targets
- Loading branch information
Lander Brandt
committed
Mar 9, 2022
1 parent
5aeff5d
commit 7828dcc
Showing
10 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,49 @@ | ||
use helpers::check_arg_count; | ||
use log::trace; | ||
use rustc_middle::mir; | ||
|
||
use crate::*; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum Dlsym { | ||
signal, | ||
} | ||
|
||
impl Dlsym { | ||
// Returns an error for unsupported symbols, and None if this symbol | ||
// should become a NULL pointer (pretend it does not exist). | ||
pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> { | ||
Ok(match &*name { | ||
"__pthread_get_minstack" => None, | ||
"getrandom" => None, // std falls back to syscall(SYS_getrandom, ...) when this is NULL. | ||
"statx" => None, // std falls back to syscall(SYS_statx, ...) when this is NULL. | ||
"signal" | "bsd_signal" => Some(Dlsym::signal), // these have the same signature/implementation | ||
_ => throw_unsup_format!("unsupported Android dlsym: {}", name), | ||
}) | ||
} | ||
} | ||
|
||
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} | ||
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { | ||
fn call_dlsym( | ||
&mut self, | ||
dlsym: Dlsym, | ||
args: &[OpTy<'tcx, Tag>], | ||
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, | ||
) -> InterpResult<'tcx> { | ||
let this = self.eval_context_mut(); | ||
let (dest, ret) = ret.expect("we don't support any diverging dlsym"); | ||
assert!(this.tcx.sess.target.os == "android"); | ||
|
||
match dlsym { | ||
Dlsym::signal => { | ||
let &[ref _sig, ref _func] = check_arg_count(args)?; | ||
this.write_null(dest)?; | ||
} | ||
} | ||
|
||
trace!("{:?}", this.dump_place(**dest)); | ||
this.go_to_block(ret); | ||
Ok(()) | ||
} | ||
} |
This file contains 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,28 @@ | ||
use rustc_middle::mir; | ||
use rustc_span::Symbol; | ||
use rustc_target::spec::abi::Abi; | ||
|
||
use crate::*; | ||
use shims::foreign_items::EmulateByNameResult; | ||
|
||
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} | ||
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { | ||
fn emulate_foreign_item_by_name( | ||
&mut self, | ||
link_name: Symbol, | ||
abi: Abi, | ||
args: &[OpTy<'tcx, Tag>], | ||
dest: &PlaceTy<'tcx, Tag>, | ||
ret: mir::BasicBlock, | ||
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> { | ||
let this = self.eval_context_mut(); | ||
|
||
match &*link_name.as_str() { | ||
_ => { | ||
// By default we piggyback off the items emulated for Linux. For now this functions | ||
// serves to make adding android-specific syscalls easy | ||
return shims::posix::linux::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest, ret); | ||
} | ||
} | ||
} | ||
} |
This file contains 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,2 @@ | ||
pub mod dlsym; | ||
pub mod foreign_items; |
This file contains 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 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ mod fs; | |
mod sync; | ||
mod thread; | ||
|
||
mod android; | ||
mod linux; | ||
mod macos; | ||
|
||
|