diff options
| author | Ralf Jung <post@ralfj.de> | 2025-02-02 19:14:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-02 19:14:20 +0000 |
| commit | 60e1c0cb033e2736b479f4782122f613740111e9 (patch) | |
| tree | 42b93f5b47c28a4b81efcaa98c0eca21e45a6cfa | |
| parent | 6b656cc0c73fcbafdce753c9610693c0a23445a3 (diff) | |
| parent | 726c9d84d1f42b9d6610bc0d3b171700c1f81e23 (diff) | |
| download | rust-60e1c0cb033e2736b479f4782122f613740111e9.tar.gz rust-60e1c0cb033e2736b479f4782122f613740111e9.zip | |
Merge pull request #4172 from RalfJung/miri_get_backtrace
miri_get_backtrace: stop supporting the v0 protocol
| -rw-r--r-- | src/tools/miri/src/helpers.rs | 16 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/backtrace.rs | 40 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/foreign_items.rs | 2 | ||||
| -rw-r--r-- | src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-decl.rs | 7 |
4 files changed, 14 insertions, 51 deletions
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 5204056a3d5..a26f12cdfb1 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -1211,22 +1211,6 @@ where throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N) } -/// Check that the number of args is at least the minimum what we expect. -/// FIXME: Remove this function, use varargs and `check_min_vararg_count` instead. -pub fn check_min_arg_count<'a, 'tcx, const N: usize>( - name: &'a str, - args: &'a [OpTy<'tcx>], -) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]> { - if let Some((ops, _)) = args.split_first_chunk() { - return interp_ok(ops); - } - throw_ub_format!( - "incorrect number of arguments for `{name}`: got {}, expected at least {}", - args.len(), - N - ) -} - /// Check that the number of varargs is at least the minimum what we expect. /// Fixed args should not be included. /// Use `check_vararg_fixed_arg_count` to extract the varargs slice from full function arguments. diff --git a/src/tools/miri/src/shims/backtrace.rs b/src/tools/miri/src/shims/backtrace.rs index 137666160d2..7e667e70a17 100644 --- a/src/tools/miri/src/shims/backtrace.rs +++ b/src/tools/miri/src/shims/backtrace.rs @@ -4,7 +4,6 @@ use rustc_middle::ty::{self, Instance, Ty}; use rustc_span::{BytePos, Loc, Symbol, hygiene}; use rustc_target::callconv::{Conv, FnAbi}; -use crate::helpers::check_min_arg_count; use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} @@ -34,13 +33,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { abi: &FnAbi<'tcx, Ty<'tcx>>, link_name: Symbol, args: &[OpTy<'tcx>], - dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); - let tcx = this.tcx; + let ptr_ty = this.machine.layouts.mut_raw_ptr.ty; + let ptr_layout = this.layout_of(ptr_ty)?; + + let [flags, buf] = this.check_shim(abi, Conv::Rust, link_name, args)?; - let [flags] = check_min_arg_count("miri_get_backtrace", args)?; let flags = this.read_scalar(flags)?.to_u64()?; + let buf_place = this.deref_pointer_as(buf, ptr_layout)?; let mut data = Vec::new(); for frame in this.active_thread_stack().iter().rev() { @@ -63,43 +64,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { }) .collect(); - let len: u64 = ptrs.len().try_into().unwrap(); - - let ptr_ty = this.machine.layouts.mut_raw_ptr.ty; - let array_layout = this.layout_of(Ty::new_array(tcx.tcx, ptr_ty, len)).unwrap(); - match flags { - // storage for pointers is allocated by miri - // deallocating the slice is undefined behavior with a custom global allocator 0 => { - let [_flags] = this.check_shim(abi, Conv::Rust, link_name, args)?; - - let alloc = this.allocate(array_layout, MiriMemoryKind::Rust.into())?; - - // Write pointers into array - for (i, ptr) in ptrs.into_iter().enumerate() { - let place = this.project_index(&alloc, i as u64)?; - - this.write_pointer(ptr, &place)?; - } - - this.write_immediate(Immediate::new_slice(alloc.ptr(), len, this), dest)?; + throw_unsup_format!("miri_get_backtrace: v0 is not supported any more"); } - // storage for pointers is allocated by the caller - 1 => { - let [_flags, buf] = this.check_shim(abi, Conv::Rust, link_name, args)?; - - let ptr_layout = this.layout_of(ptr_ty)?; - let buf_place = this.deref_pointer_as(buf, ptr_layout)?; - + 1 => for (i, ptr) in ptrs.into_iter().enumerate() { let offset = ptr_layout.size.checked_mul(i.try_into().unwrap(), this).unwrap(); let op_place = buf_place.offset(offset, ptr_layout, this)?; this.write_pointer(ptr, &op_place)?; - } - } + }, _ => throw_unsup_format!("unknown `miri_get_backtrace` flags {}", flags), }; diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index d84f414af14..97bfb04f1f4 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -357,7 +357,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { // Obtains a Miri backtrace. See the README for details. "miri_get_backtrace" => { // `check_shim` happens inside `handle_miri_get_backtrace`. - this.handle_miri_get_backtrace(abi, link_name, args, dest)?; + this.handle_miri_get_backtrace(abi, link_name, args)?; } // Resolves a Miri backtrace frame. See the README for details. "miri_resolve_frame" => { diff --git a/src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-decl.rs b/src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-decl.rs index a20539ee7c7..c557c35c9de 100644 --- a/src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-decl.rs +++ b/src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-decl.rs @@ -1,10 +1,13 @@ extern "Rust" { - fn miri_get_backtrace(flags: u64) -> Box<[*mut ()]>; + fn miri_backtrace_size(flags: u64) -> usize; + fn miri_get_backtrace(flags: u64, buf: *mut *mut ()); fn miri_resolve_frame(ptr: *mut (), flags: u64); } fn main() { - let frames = unsafe { miri_get_backtrace(0) }; + let size = unsafe { miri_backtrace_size(0) }; + let mut frames = vec![std::ptr::null_mut(); size]; + unsafe { miri_get_backtrace(1, frames.as_mut_ptr()) }; for frame in frames.iter() { unsafe { miri_resolve_frame(*frame, 0); //~ ERROR: Undefined Behavior: bad declaration of miri_resolve_frame - should return a struct with 5 fields |
