diff --git a/src/symbolize/libbacktrace.rs b/src/symbolize/libbacktrace.rs index 23706da02..5fd6476e8 100644 --- a/src/symbolize/libbacktrace.rs +++ b/src/symbolize/libbacktrace.rs @@ -124,7 +124,7 @@ unsafe fn call(data: *mut c_void, sym: &Symbol) { // that is calculated the first time this is requested. Remember that // backtracing all happens serially (one global lock). // -// An additionally oddity in this function is that we initialize the +// An additional oddity in this function is that we initialize the // filename via self_exe_name() to pass to libbacktrace. It turns out // that on Linux libbacktrace seamlessly gets the filename of the // current executable, but this fails on freebsd. by always providing @@ -159,6 +159,8 @@ unsafe fn init_state() -> *mut bt::backtrace_state { } None => ptr::null(), }; + // Our libbacktrace may not have multithreading support, so + // set `threaded = 0` and synchronize ourselves. STATE = bt::backtrace_create_state(filename, 0, error_cb, ptr::null_mut()); }); @@ -184,6 +186,7 @@ pub fn resolve(symaddr: *mut c_void, mut cb: &mut FnMut(&Symbol)) { if state.is_null() { return } + let _guard = ::lock::lock(); let ret = bt::backtrace_pcinfo(state, symaddr as uintptr_t, pcinfo_cb, error_cb,