Skip to content

Commit 2a2a93d

Browse files
committed
Require #[repr(C)] on MiriFrame
1 parent 5857365 commit 2a2a93d

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ extern "Rust" {
277277
/// and `MiriFrame` should be declared as follows:
278278
///
279279
/// ```rust
280+
/// #[repr(C)]
280281
/// struct MiriFrame {
281282
/// // The name of the function being executed, encoded in UTF-8
282283
/// name: Box<[u8]>,

src/shims/backtrace.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::*;
22
use helpers::check_arg_count;
3-
use rustc_middle::ty::TypeAndMut;
3+
use rustc_middle::ty::{self, TypeAndMut};
44
use rustc_ast::ast::Mutability;
55
use rustc_span::BytePos;
66
use rustc_target::abi::Size;
@@ -105,7 +105,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
105105
let lineno_alloc = Scalar::from_u32(lineno);
106106
let colno_alloc = Scalar::from_u32(colno);
107107

108-
let dest = this.force_allocation_maybe_sized(dest, MemPlaceMeta::None)?.0;
108+
let dest = this.force_allocation(dest)?;
109+
if let ty::Adt(adt, _) = dest.layout.ty.kind() {
110+
if !adt.repr.c() {
111+
throw_ub_format!("miri_resolve_frame must be declared with a `#[repr(C)]` return type");
112+
}
113+
}
109114

110115
this.write_immediate(name_alloc.to_ref(), this.mplace_field(dest, 0)?.into())?;
111116
this.write_immediate(filename_alloc.to_ref(), this.mplace_field(dest, 1)?.into())?;

tests/run-pass/backtrace-api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "Rust" {
77
}
88

99
#[derive(Debug)]
10+
#[repr(C)]
1011
struct MiriFrame {
1112
name: Box<[u8]>,
1213
filename: Box<[u8]>,

tests/run-pass/backtrace-api.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
$DIR/backtrace-api.rs:19:59 (func_c)
2-
$DIR/backtrace-api.rs:18:53 (func_b::<u8>)
3-
$DIR/backtrace-api.rs:17:50 (func_a)
4-
$DIR/backtrace-api.rs:23:18 (main)
1+
$DIR/backtrace-api.rs:20:59 (func_c)
2+
$DIR/backtrace-api.rs:19:53 (func_b::<u8>)
3+
$DIR/backtrace-api.rs:18:50 (func_a)
4+
$DIR/backtrace-api.rs:24:18 (main)
55
RUSTLIB/src/rust/library/core/src/ops/function.rs:LL:COL (<fn() as std::ops::FnOnce<()>>::call_once - shim(fn()))
66
RUSTLIB/src/rust/library/std/src/sys_common/backtrace.rs:LL:COL (std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>)
77
RUSTLIB/src/rust/library/std/src/rt.rs:LL:COL (std::rt::lang_start::<()>::{{closure}}#0)

tests/run-pass/backtrace-api.stdout

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$DIR/backtrace-api.rs:19:59 (func_c)
2-
$DIR/backtrace-api.rs:18:53 (func_b::<u8>)
3-
$DIR/backtrace-api.rs:17:50 (func_a)
4-
$DIR/backtrace-api.rs:23:18 (main)
1+
$DIR/backtrace-api.rs:20:59 (func_c)
2+
$DIR/backtrace-api.rs:19:53 (func_b::<u8>)
3+
$DIR/backtrace-api.rs:18:50 (func_a)
4+
$DIR/backtrace-api.rs:24:18 (main)

0 commit comments

Comments
 (0)