Skip to content
Snippets Groups Projects
Commit fb8c931e authored by John Hodge's avatar John Hodge
Browse files

All - Switch to panic_implementation

parent 9a895bc9
No related merge requests found
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#![feature(integer_atomics)] // AtomicU8 #![feature(integer_atomics)] // AtomicU8
#![feature(dropck_eyepatch)] #![feature(dropck_eyepatch)]
#![feature(const_atomic_bool_new,const_atomic_ptr_new,const_atomic_usize_new,const_unsafe_cell_new,const_unique_new)] // Various const fns #![feature(const_atomic_bool_new,const_atomic_ptr_new,const_atomic_usize_new,const_unsafe_cell_new,const_unique_new)] // Various const fns
#![feature(panic_implementation,panic_info_message)]
#![no_std] #![no_std]
......
...@@ -93,7 +93,7 @@ fn init() ...@@ -93,7 +93,7 @@ fn init()
// A picture of a sad ferris the crab // A picture of a sad ferris the crab
// NOTE: Commented out, as uncompressed 32bpp is too large to fit in the image // NOTE: Commented out, as uncompressed 32bpp is too large to fit in the image
include!{"../../../../Graphics/.output/shared/panic.rs"} include!{"../../../../Graphics/.output/shared/panic.rs"}
pub fn set_panic(file: &str, line: usize, message: ::core::fmt::Arguments) pub fn set_panic(file: &str, line: usize, message: &::core::fmt::Arguments)
{ {
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
static LOOP_PREVENT: AtomicBool = AtomicBool::new(false); static LOOP_PREVENT: AtomicBool = AtomicBool::new(false);
......
...@@ -52,9 +52,27 @@ static EXCEPTION_CLASS : u64 = 0x544B3120_52757374; // TK1 Rust (big endian) ...@@ -52,9 +52,27 @@ static EXCEPTION_CLASS : u64 = 0x544B3120_52757374; // TK1 Rust (big endian)
// */ // */
// Evil fail when doing unwind // Evil fail when doing unwind
#[no_mangle] #[panic_implementation]
#[lang = "panic_fmt"] pub extern fn rust_begin_unwind(info: &::core::panic::PanicInfo) -> ! {
pub extern "C" fn rust_begin_unwind(msg: ::core::fmt::Arguments, file: &'static str, line: usize) -> ! let file_line = match info.location()
{
Some(v) => (v.file(), v.line()),
None => ("", 0),
};
if let Some(m) = info.payload().downcast_ref::<::core::fmt::Arguments>() {
begin_panic_fmt(m, file_line)
}
else if let Some(m) = info.payload().downcast_ref::<&str>() {
begin_panic_fmt(&format_args!("{}", m), file_line)
}
else if let Some(m) = info.message() {
begin_panic_fmt(m, file_line)
}
else {
begin_panic_fmt(&format_args!("Unknown"), file_line)
}
}
fn begin_panic_fmt(msg: &::core::fmt::Arguments, (file, line): (&str, u32)) -> !
{ {
static NESTED: ::core::sync::atomic::AtomicBool = ::core::sync::atomic::ATOMIC_BOOL_INIT; static NESTED: ::core::sync::atomic::AtomicBool = ::core::sync::atomic::ATOMIC_BOOL_INIT;
::arch::puts("\nERROR: rust_begin_unwind: "); ::arch::puts("\nERROR: rust_begin_unwind: ");
...@@ -68,7 +86,7 @@ pub extern "C" fn rust_begin_unwind(msg: ::core::fmt::Arguments, file: &'static ...@@ -68,7 +86,7 @@ pub extern "C" fn rust_begin_unwind(msg: ::core::fmt::Arguments, file: &'static
} }
::arch::print_backtrace(); ::arch::print_backtrace();
log_panic!("{}:{}: Panicked \"{:?}\"", file, line, msg); log_panic!("{}:{}: Panicked \"{:?}\"", file, line, msg);
::metadevs::video::set_panic(file, line, msg); ::metadevs::video::set_panic(file, line as usize, msg);
loop{} loop{}
} }
#[lang="eh_personality"] #[lang="eh_personality"]
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// //
// Standard Library - Runtime support (aka unwind and panic) // Standard Library - Runtime support (aka unwind and panic)
#![feature(lang_items)] // Allow definition of lang_items #![feature(lang_items)] // Allow definition of lang_items
#![feature(panic_implementation,panic_info_message)]
#![feature(asm)] // Used by backtrace code #![feature(asm)] // Used by backtrace code
#![feature(const_fn)] // HACK For debugging ARM unwind #![feature(const_fn)] // HACK For debugging ARM unwind
#![no_std] #![no_std]
...@@ -45,10 +46,7 @@ mod arch; ...@@ -45,10 +46,7 @@ mod arch;
#[path="arch-armv8.rs"] #[path="arch-armv8.rs"]
mod arch; mod arch;
pub fn begin_panic<M: ::core::any::Any+Send+'static>(msg: M, file_line: &(&'static str, u32)) -> ! { fn begin_panic_fmt(msg: &::core::fmt::Arguments, file_line: (&str, u32)) -> ! {
begin_unwind(msg, file_line)
}
pub fn begin_panic_fmt(msg: &::core::fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
// Spit out that log // Spit out that log
kernel_log!("PANIC: {}:{}: {}", file_line.0, file_line.1, msg); kernel_log!("PANIC: {}:{}: {}", file_line.0, file_line.1, msg);
// - Backtrace // - Backtrace
...@@ -58,26 +56,26 @@ pub fn begin_panic_fmt(msg: &::core::fmt::Arguments, file_line: &(&'static str, ...@@ -58,26 +56,26 @@ pub fn begin_panic_fmt(msg: &::core::fmt::Arguments, file_line: &(&'static str,
::syscalls::threads::exit(0xFFFF_FFFF); ::syscalls::threads::exit(0xFFFF_FFFF);
} }
pub fn begin_unwind<M: ::core::any::Any+Send+'static>(msg: M, file_line: &(&'static str, u32)) -> ! { #[panic_implementation]
if let Some(m) = ::core::any::Any::downcast_ref::<::core::fmt::Arguments>(&msg) { pub extern fn rust_begin_unwind(info: &::core::panic::PanicInfo) -> ! {
begin_panic_fmt(&format_args!("{}", m), file_line) let file_line = match info.location()
{
Some(v) => (v.file(), v.line()),
None => ("", 0),
};
if let Some(m) = info.payload().downcast_ref::<::core::fmt::Arguments>() {
begin_panic_fmt(m, file_line)
} }
else if let Some(m) = ::core::any::Any::downcast_ref::<&str>(&msg) { else if let Some(m) = info.payload().downcast_ref::<&str>() {
begin_panic_fmt(&format_args!("{}", m), file_line) begin_panic_fmt(&format_args!("{}", m), file_line)
} }
else if let Some(m) = info.message() {
begin_panic_fmt(m, file_line)
}
else { else {
begin_panic_fmt(&format_args!("begin_unwind<{}>", type_name!(M)), file_line) begin_panic_fmt(&format_args!("Unknown"), file_line)
} }
} }
pub fn begin_unwind_fmt(msg: ::core::fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
begin_panic_fmt(&msg, file_line)
}
#[lang = "panic_fmt"]
#[no_mangle]
pub extern fn rust_begin_unwind(msg: ::core::fmt::Arguments, file: &'static str, line: usize) -> ! {
begin_panic_fmt(&msg, &(file, line as u32))
}
#[lang="eh_personality"] #[lang="eh_personality"]
fn rust_eh_personality( fn rust_eh_personality(
//version: isize, _actions: _Unwind_Action, _exception_class: u64, //version: isize, _actions: _Unwind_Action, _exception_class: u64,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment