| Crates.io | polished_panic_handler |
| lib.rs | polished_panic_handler |
| version | 0.1.1 |
| created_at | 2025-06-12 08:24:59.489582+00 |
| updated_at | 2025-06-12 20:25:09.165815+00 |
| description | Panic handler for Polished OS, providing custom panic behavior and logging. |
| homepage | |
| repository | https://codeberg.org/ofluffydev/polished |
| max_upload_size | |
| id | 1709530 |
| size | 12,829 |
A custom panic handler for the Polished OS kernel and other low-level, no_std Rust environments.
polished_panic_handler provides a robust, serial-port-based panic handler for use in operating system kernels, bootloaders, and other environments where the Rust standard library is unavailable. It is designed for use in the Polished OS project, but can be reused in any similar context.
serial_logging crate, making it accessible even when no display is available.no_std Rust project.In standard Rust applications, the standard library provides a default panic handler. However, in no_std environments (such as kernels and bootloaders), you must provide your own panic handler. Rust looks for a function marked with the #[panic_handler] attribute. When a panic occurs (e.g., via panic!() or an assertion failure), this function is called with a reference to a [core::panic::PanicInfo] struct, which contains information about the panic location and message.
This crate implements such a function, ensuring that all panics are logged and the system is safely halted.
#[panic_handler] is invoked automatically by the Rust runtime.cli and hlt instructions to ensure the system does not continue in an unsafe state.Cargo.toml:
polished_panic_handler = { path = "../panic_handler" }
serial_logging crate is initialized early in your boot process so that panic output is visible.When a panic occurs, the serial port will output something like:
Kernel panic occurred!
=== PANIC ===
Location: src/main.rs:42:13
Message: assertion failed: x == 0
=============
This crate is licensed under the zlib License. See the root LICENSE file for details.