Skip to content

Commit

Permalink
remove handle_unsupported_foreign_item helper
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 10, 2024
1 parent 66fda4a commit 7e21dce
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
16 changes: 0 additions & 16 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols::ExportedSymbol;
use rustc_middle::mir;
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
use rustc_session::config::CrateType;
Expand Down Expand Up @@ -949,21 +948,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
crate_name == "std" || crate_name == "std_miri_test"
}

/// Handler that should be called when an unsupported foreign item is encountered.
/// This function will either panic within the context of the emulated application
/// or return an error in the Miri process context
fn handle_unsupported_foreign_item(&mut self, error_msg: String) -> InterpResult<'tcx, ()> {
let this = self.eval_context_mut();
if this.machine.panic_on_unsupported {
// message is slightly different here to make automated analysis easier
let error_msg = format!("unsupported Miri functionality: {error_msg}");
this.start_panic(error_msg.as_ref(), mir::UnwindAction::Continue)?;
interp_ok(())
} else {
throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(error_msg));
}
}

fn check_abi_and_shim_symbol_clash(
&mut self,
abi: Abi,
Expand Down
12 changes: 9 additions & 3 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
return interp_ok(Some(body));
}

this.handle_unsupported_foreign_item(format!(
let error_msg = format!(
"can't call foreign function `{link_name}` on OS `{os}`",
os = this.tcx.sess.target.os,
))?;
return interp_ok(None);
);
if this.machine.panic_on_unsupported {
// message is slightly different here to make automated analysis easier
let error_msg = format!("unsupported Miri functionality: {error_msg}");
this.start_panic(error_msg.as_ref(), mir::UnwindAction::Continue)?;
} else {
throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(error_msg));
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/tools/miri/src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_int(result.to_i32()?, dest)?;
}
id => {
this.handle_unsupported_foreign_item(format!(
"can't execute syscall with ID {id}"
))?;
return interp_ok(EmulateItemResult::AlreadyJumped);
throw_unsup_format!("can't execute syscall with ID {id}");
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/tools/miri/tests/panic/unsupported_syscall.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/tools/miri/tests/panic/unsupported_syscall.stderr

This file was deleted.

0 comments on commit 7e21dce

Please sign in to comment.