Browse Source

Use Error applet to display panics

pull/10/head
Fenrir 8 years ago
parent
commit
d36057aee0
  1. 48
      ctr-std/src/panicking.rs
  2. 2
      ctru-sys/src/bindings.rs

48
ctr-std/src/panicking.rs

@ -15,11 +15,10 @@ use io::prelude::*;
use any::Any; use any::Any;
use cell::RefCell; use cell::RefCell;
use fmt; use fmt::{self, Display};
use mem; use mem;
use ptr; use ptr;
use raw; use raw;
use __core::fmt::Display;
thread_local! { thread_local! {
pub static LOCAL_STDERR: RefCell<Option<Box<Write + Send>>> = { pub static LOCAL_STDERR: RefCell<Option<Box<Write + Send>>> = {
@ -68,29 +67,28 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line_col: &(&'static st
let msg = Box::new(msg); let msg = Box::new(msg);
let (file, line, col) = *file_line_col; let (file, line, col) = *file_line_col;
use libctru::consoleInit; // 3DS-specific code begins here
use libctru::gfxScreen_t; use libctru::{errorInit, errorText, errorDisp, svcExitProcess,
errorConf, errorType, CFG_Language};
// set up a new console, overwriting whatever was on the top screen use libc;
// before we started panicking
let _console = unsafe { consoleInit(gfxScreen_t::GFX_TOP, ptr::null_mut()) }; unsafe {
// Setup error payload
println!("PANIC in {} at line {}:", file, line); let error_text = format!("thread '{}' panicked at '{}', {}:{}:{}",
println!(" {}", msg); "<unnamed>", msg, file, line, col);
let mut error_conf: errorConf = mem::uninitialized();
// Terminate the process to ensure that all threads cease when panicking. errorInit(&mut error_conf,
unsafe { ::libctru::svcExitProcess() } errorType::ERROR_TEXT_WORD_WRAP,
CFG_Language::CFG_LANGUAGE_EN);
// On 3DS hardware, code execution will have terminated at the above function. errorText(&mut error_conf, error_text.as_ptr() as *const libc::c_char);
//
// Citra, however, will simply ignore the function and control flow becomes trapped // Display error via Error applet
// in the following loop instead. However, this means that other threads may continue errorDisp(&mut error_conf);
// to run after a panic!
// // Now that we're all done printing, it's time to exit the program.
// This is actually a better outcome than calling libc::abort(), which seemingly // We don't have stack unwinding yet, so we just forcibly end the process
// causes the emulator to step into unreachable code, prompting it to freak out svcExitProcess()
// and spew endless nonsense into the console log. }
loop {}
} }
/// Invoke a closure, capturing the cause of an unwinding panic if one occurs. /// Invoke a closure, capturing the cause of an unwinding panic if one occurs.

2
ctru-sys/src/bindings.rs

@ -1844,7 +1844,7 @@ extern "C" {
pub fn svcOpenProcess(process: *mut Handle, processId: u32) -> Result; pub fn svcOpenProcess(process: *mut Handle, processId: u32) -> Result;
} }
extern "C" { extern "C" {
pub fn svcExitProcess(); pub fn svcExitProcess() -> !;
} }
extern "C" { extern "C" {
pub fn svcTerminateProcess(process: Handle) -> Result; pub fn svcTerminateProcess(process: Handle) -> Result;

Loading…
Cancel
Save