Skip to content

Commit 2feb8bb

Browse files
committed
better error when native code tries to execute Rust function
1 parent fe91820 commit 2feb8bb

File tree

1 file changed

+12
-1
lines changed
  • src/tools/miri/src/shims/native_lib/trace

1 file changed

+12
-1
lines changed

src/tools/miri/src/shims/native_lib/trace/parent.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,18 @@ fn handle_segfault(
530530
// Don't use wait_for_signal here since 1 instruction doesn't give room
531531
// for any uncertainty + we don't want it `cont()`ing randomly by accident
532532
// Also, don't let it continue with unprotected memory if something errors!
533-
let _ = wait::waitid(wait::Id::Pid(pid), WAIT_FLAGS).map_err(|_| ExecEnd(None))?;
533+
let stat = wait::waitid(wait::Id::Pid(pid), WAIT_FLAGS).map_err(|_| ExecEnd(None))?;
534+
match stat {
535+
wait::WaitStatus::Signaled(_, s, _)
536+
| wait::WaitStatus::Stopped(_, s)
537+
| wait::WaitStatus::PtraceEvent(_, s, _) =>
538+
assert!(
539+
!matches!(s, signal::SIGSEGV),
540+
"native code segfaulted when re-trying memory access\n\
541+
is the native code trying to call a Rust function?"
542+
),
543+
_ => (),
544+
}
534545

535546
// Zero out again to be safe
536547
for a in (ch_stack..ch_stack.strict_add(CALLBACK_STACK_SIZE)).step_by(ARCH_WORD_SIZE) {

0 commit comments

Comments
 (0)