mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Auto merge of #28159 - MichaelMcDonnell:extract_crash_handler, r=jdm
Extract crash handler Moved the crash handler code into its own file since it is a distinct concept. It simplifies the main method a little. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because it only moves code around. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
4c82d3cb86
2 changed files with 39 additions and 34 deletions
37
ports/winit/crash_handler.rs
Normal file
37
ports/winit/crash_handler.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
|
||||||
|
pub fn install() {}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||||
|
pub fn install() {
|
||||||
|
use crate::backtrace;
|
||||||
|
use libc::_exit;
|
||||||
|
use sig::ffi::Sig;
|
||||||
|
use std::{io::Write, sync::atomic, thread};
|
||||||
|
|
||||||
|
extern "C" fn handler(sig: i32) {
|
||||||
|
static BEEN_HERE_BEFORE: atomic::AtomicBool = atomic::AtomicBool::new(false);
|
||||||
|
if !BEEN_HERE_BEFORE.swap(true, atomic::Ordering::SeqCst) {
|
||||||
|
let stdout = std::io::stdout();
|
||||||
|
let mut stdout = stdout.lock();
|
||||||
|
let _ = write!(&mut stdout, "Stack trace");
|
||||||
|
if let Some(name) = thread::current().name() {
|
||||||
|
let _ = write!(&mut stdout, " for thread \"{}\"", name);
|
||||||
|
}
|
||||||
|
let _ = write!(&mut stdout, "\n");
|
||||||
|
let _ = backtrace::print(&mut stdout);
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
_exit(sig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signal!(Sig::SEGV, handler); // handle segfaults
|
||||||
|
signal!(Sig::ILL, handler); // handle stack overflow and unsupported CPUs
|
||||||
|
signal!(Sig::IOT, handler); // handle double panics
|
||||||
|
signal!(Sig::BUS, handler); // handle invalid memory access
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ extern crate sig;
|
||||||
mod app;
|
mod app;
|
||||||
mod backtrace;
|
mod backtrace;
|
||||||
mod browser;
|
mod browser;
|
||||||
|
mod crash_handler;
|
||||||
mod embedder;
|
mod embedder;
|
||||||
mod events_loop;
|
mod events_loop;
|
||||||
mod headed_window;
|
mod headed_window;
|
||||||
|
@ -44,41 +45,8 @@ pub mod platform {
|
||||||
pub fn deinit(_clean_shutdown: bool) {}
|
pub fn deinit(_clean_shutdown: bool) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
|
|
||||||
fn install_crash_handler() {}
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
|
||||||
fn install_crash_handler() {
|
|
||||||
use libc::_exit;
|
|
||||||
use sig::ffi::Sig;
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
extern "C" fn handler(sig: i32) {
|
|
||||||
use std::sync::atomic;
|
|
||||||
static BEEN_HERE_BEFORE: atomic::AtomicBool = atomic::AtomicBool::new(false);
|
|
||||||
if !BEEN_HERE_BEFORE.swap(true, atomic::Ordering::SeqCst) {
|
|
||||||
let stdout = std::io::stdout();
|
|
||||||
let mut stdout = stdout.lock();
|
|
||||||
let _ = write!(&mut stdout, "Stack trace");
|
|
||||||
if let Some(name) = thread::current().name() {
|
|
||||||
let _ = write!(&mut stdout, " for thread \"{}\"", name);
|
|
||||||
}
|
|
||||||
let _ = write!(&mut stdout, "\n");
|
|
||||||
let _ = backtrace::print(&mut stdout);
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
_exit(sig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signal!(Sig::SEGV, handler); // handle segfaults
|
|
||||||
signal!(Sig::ILL, handler); // handle stack overflow and unsupported CPUs
|
|
||||||
signal!(Sig::IOT, handler); // handle double panics
|
|
||||||
signal!(Sig::BUS, handler); // handle invalid memory access
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
install_crash_handler();
|
crash_handler::install();
|
||||||
|
|
||||||
resources::init();
|
resources::init();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue