Browse Source

Enable old panic behavior for Citra

pull/10/head
Fenrir 8 years ago
parent
commit
cbe41e5304
  1. 3
      ctr-std/Cargo.toml
  2. 37
      ctr-std/src/panicking.rs

3
ctr-std/Cargo.toml

@ -15,3 +15,6 @@ default-features = false @@ -15,3 +15,6 @@ default-features = false
[dependencies.ctru-sys]
path = "../ctru-sys"
[features]
citra = []

37
ctr-std/src/panicking.rs

@ -57,8 +57,37 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments, file_line_col: &(&'static str, u32, @@ -57,8 +57,37 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments, file_line_col: &(&'static str, u32,
begin_panic(s, file_line_col);
}
/// We don't have stack unwinding, so all we do is print the panic message
/// and then crash or hang the application
// Citra doesn't support the Error applet yet
#[cfg(feature = "citra")]
#[unstable(feature = "libstd_sys_internals",
reason = "used by the panic! macro",
issue = "0")]
#[inline(never)] #[cold]
pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
let msg = Box::new(msg);
let (file, line, col) = *file_line_col;
// 3DS-specific code begins here
use libctru::{consoleInit, gfxScreen_t};
unsafe {
// set up a new console, overwriting whatever was on the top screen
// before we started panicking
let _console = consoleInit(gfxScreen_t::GFX_TOP, ptr::null_mut());
println!("thread '{}' panicked at '{}', {}:{}:{}",
"<unnamed>", msg, file, line, col);
// Citra seems to ignore calls to svcExitProcess, and libc::abort()
// causes it to lock up and fill the console with endless debug statements.
// So instead of terminating the program, we just let it spin in the following
// loop. This means that any background threads might continue to run after
// this thread panics, but there's not a lot we can do about that currently.
loop { }
}
}
#[cfg(not(feature = "citra"))]
#[unstable(feature = "libstd_sys_internals",
reason = "used by the panic! macro",
issue = "0")]
@ -75,14 +104,14 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line_col: &(&'static st @@ -75,14 +104,14 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line_col: &(&'static st
unsafe {
// Setup error payload
let error_text = format!("thread '{}' panicked at '{}', {}:{}:{}",
"<unnamed>", msg, file, line, col);
"<unnamed>", msg, file, line, col);
let mut error_conf: errorConf = mem::uninitialized();
errorInit(&mut error_conf,
errorType::ERROR_TEXT_WORD_WRAP,
CFG_Language::CFG_LANGUAGE_EN);
errorText(&mut error_conf, error_text.as_ptr() as *const libc::c_char);
// Display error via Error applet
// Display error
errorDisp(&mut error_conf);
// Now that we're all done printing, it's time to exit the program.

Loading…
Cancel
Save