From fbd756339c103972f283982f4f1a32105bbd0390 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Mon, 6 Mar 2017 09:50:52 -0700 Subject: [PATCH] Terminate all threads when panicking --- ctr-std/src/panicking.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ctr-std/src/panicking.rs b/ctr-std/src/panicking.rs index 3eb5bee..efb828a 100644 --- a/ctr-std/src/panicking.rs +++ b/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 -/// and then loop forever +/// and then crash or hang the application #[inline(never)] #[cold] pub fn begin_panic(msg: M, file_line: &(&'static str, u32)) -> ! { @@ -73,6 +73,18 @@ pub fn begin_panic(msg: M, file_line: &(&'static str, u println!("PANIC in {} at line {}:", file, line); 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 {} }