Created
July 1, 2020 16:49
-
-
Save losfair/15aeb363095f1652c03b7edd76fb6378 to your computer and use it in GitHub Desktop.
Reproduction case for https://github.com/wasmerio/wasmer-reborn/pull/125 .
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
use backtrace::Backtrace; | |
use std::{mem, ptr}; | |
#[inline(never)] | |
fn f(x: i32) -> i32 { | |
if x == 0 || x == 1 { | |
1 | |
} else { | |
f(x - 1) + f(x - 2) | |
} | |
} | |
fn main() { | |
unsafe { | |
let mut handler: libc::sigaction = mem::zeroed(); | |
handler.sa_flags = libc::SA_ONSTACK; | |
handler.sa_sigaction = trap_handler as usize; | |
libc::sigemptyset(&mut handler.sa_mask); | |
assert_eq!(libc::sigaction(libc::SIGSEGV, &handler, ptr::null_mut()), 0); | |
// Backtracing from a normal SIGSEGV works | |
//println!("Before invalid write"); | |
//ptr::write_volatile(0 as *mut u32, 0); | |
//println!("After invalid write"); | |
// Backtracing from a stack overflow crashes | |
println!("Before stack overflow"); | |
println!("{}", f(0xfffffff)); | |
println!("After stack overflow"); | |
} | |
} | |
unsafe extern "C" fn trap_handler( | |
_: libc::c_int | |
) { | |
println!("Backtrace begin"); | |
let backtrace = Backtrace::new_unresolved(); | |
println!("Backtrace result: {:?}", backtrace); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment