1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 use std::panic;
6 use std::process::abort;
7
8 /// The intent of our panic hook is to get panic info and a stacktrace into the syslog, even for
9 /// jailed subprocesses. It will always abort on panic to ensure a minidump is generated.
10 ///
11 /// Note that jailed processes will usually have a stacktrace of \<unknown\> because the backtrace
12 /// routines attempt to open this binary and are unable to do so in a jail.
set_panic_hook()13 pub fn set_panic_hook() {
14 let default_panic = panic::take_hook();
15 panic::set_hook(Box::new(move |info| {
16 // Ensure all in-flight metrics are fully flushed
17 metrics::get_destructor().cleanup();
18 // TODO(b/144724919): should update log_panic_info for this "cleanly exit crosvm" bug
19 // log_panic_info(default_panic.as_ref(), info);
20 default_panic(info);
21 // Abort to trigger the crash reporter so that a minidump is generated.
22 abort();
23 }));
24 }
25