Skip to content
Snippets Groups Projects
panic.rs 844 B
Newer Older
Jeremy Soller's avatar
Jeremy Soller committed
//! Intrinsics for panic handling

use core::alloc::Layout;
use core::panic::PanicInfo;

#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}

/// Required to handle panics
#[panic_handler]
#[no_mangle]
pub extern "C" fn rust_begin_unwind(info: &PanicInfo) -> ! {
        println!("BOOTLOADER PANIC:\n{}", info);
Jeremy Soller's avatar
Jeremy Soller committed
            llvm_asm!("hlt" : : : : "intel", "volatile");
        }
    }
}

#[lang = "oom"]
#[no_mangle]
#[allow(improper_ctypes_definitions)] // Layout is not repr(C)
pub extern fn rust_oom(_layout: Layout) -> ! {
    panic!("memory allocation failed");
Jeremy Soller's avatar
Jeremy Soller committed
}

#[allow(non_snake_case)]
#[no_mangle]
/// Required to handle panics
pub extern "C" fn _Unwind_Resume() -> ! {
    loop {
        unsafe {
            llvm_asm!("hlt" : : : : "intel", "volatile");
        }
    }
}