Browse Source

Terminate all threads when panicking

pull/10/head
Fenrir 8 years ago
parent
commit
fbd756339c
  1. 14
      ctr-std/src/panicking.rs

14
ctr-std/src/panicking.rs

@ -56,7 +56,7 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments, file_line: &(&'static str, u32)) ->
} }
/// We don't have stack unwinding, so all we do is print the panic message /// We don't have stack unwinding, so all we do is print the panic message
/// and then loop forever /// and then crash or hang the application
#[inline(never)] #[inline(never)]
#[cold] #[cold]
pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u32)) -> ! { pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u32)) -> ! {
@ -73,6 +73,18 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u
println!("PANIC in {} at line {}:", file, line); println!("PANIC in {} at line {}:", file, line);
println!(" {}", msg); println!(" {}", msg);
// Terminate the process to ensure that all threads cease when panicking.
unsafe { ::libctru::svc::svcExitProcess() }
// On 3DS hardware, code execution will have terminated at the above function.
//
// Citra, however, will simply ignore the function and control flow becomes trapped
// in the following loop instead. However, this means that other threads may continue
// to run after a panic!
//
// This is actually a better outcome than calling libc::abort(), which seemingly
// causes the emulator to step into unreachable code, prompting it to freak out
// and spew endless nonsense into the console log.
loop {} loop {}
} }

Loading…
Cancel
Save