mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-15 14:38:29 +00:00
Merge "Add kata-panic support."
GitOrigin-RevId: 86b4cf1b25c2796fff0b2f90da6ef76d773c80a9
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::cell::RefCell;
|
||||
use core::panic;
|
||||
use core::ptr::{self, NonNull};
|
||||
use log::info;
|
||||
|
||||
@@ -19,9 +20,8 @@ pub struct KataHeap {
|
||||
pub static ALLOCATOR: KataHeap = KataHeap::empty();
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn alloc_error_handler(_: Layout) -> ! {
|
||||
// TODO(sleffler): at least print a msg on the console
|
||||
loop {}
|
||||
fn alloc_error_handler(layout: Layout) -> ! {
|
||||
panic!("Global allocation failure: {:?}", layout);
|
||||
}
|
||||
|
||||
impl KataHeap {
|
||||
|
@@ -9,6 +9,7 @@ description = "Kata OS DebugConsole"
|
||||
panic-halt = "0.2.0"
|
||||
kata-allocator = { path = "../kata-allocator" }
|
||||
kata-logger = { path = "../kata-logger" }
|
||||
kata-panic = { path = "../kata-panic" }
|
||||
kata-shell = { path = "../kata-shell" }
|
||||
kata-uart-client = { path = "../kata-uart-client" }
|
||||
log = "0.4"
|
||||
|
@@ -9,11 +9,9 @@
|
||||
// * kata_shell
|
||||
// * kata_debug_console main entry point fn run()
|
||||
|
||||
// std:: requires at least an allocator, which Kata does not have yet. For now
|
||||
// the CLI will be implemented with only core::.
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
extern crate kata_panic;
|
||||
|
||||
use kata_allocator;
|
||||
use kata_logger::KataLogger;
|
||||
|
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "kata-panic"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
18
apps/system/components/DebugConsole/kata-panic/src/lib.rs
Normal file
18
apps/system/components/DebugConsole/kata-panic/src/lib.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
#![no_std]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use core::sync::atomic::{self, Ordering};
|
||||
use log::error;
|
||||
|
||||
#[inline(never)]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
// Could use panic::set_hook but we're already here...
|
||||
error!("{}", info);
|
||||
|
||||
// Halt the thread.
|
||||
loop {
|
||||
// TODO(sleffler): seL4_Yield?
|
||||
atomic::compiler_fence(Ordering::SeqCst);
|
||||
}
|
||||
}
|
@@ -73,11 +73,15 @@ fn dispatch_command(cmdline: &str, output: &mut dyn io::Write) {
|
||||
// Since even the binding is static, it is fine for each command
|
||||
// implementation to use its own preferred signature.
|
||||
let result = match command {
|
||||
"echo" => echo_command(cmdline, output),
|
||||
"add" => add_command(&mut args, output),
|
||||
"echo" => echo_command(cmdline, output),
|
||||
"clear" => clear_command(output),
|
||||
"ps" => ps_command(),
|
||||
"alloc_test" => alloc_test_command(output),
|
||||
|
||||
"test_alloc" => test_alloc_command(output),
|
||||
"test_alloc_error" => test_alloc_error_command(output),
|
||||
"test_panic" => test_panic_command(),
|
||||
|
||||
_ => Err(CommandError::UnknownCommand),
|
||||
};
|
||||
if let Err(e) = result {
|
||||
@@ -143,7 +147,7 @@ fn clear_command(output: &mut dyn io::Write) -> Result<(), CommandError> {
|
||||
|
||||
/// Implements a command that tests facilities that use the global allocator.
|
||||
/// Shamelessly cribbed from https://os.phil-opp.com/heap-allocation/
|
||||
fn alloc_test_command(output: &mut dyn io::Write) -> Result<(), CommandError> {
|
||||
fn test_alloc_command(output: &mut dyn io::Write) -> Result<(), CommandError> {
|
||||
extern crate alloc;
|
||||
use alloc::{boxed::Box, rc::Rc, vec, vec::Vec};
|
||||
|
||||
@@ -177,3 +181,21 @@ fn alloc_test_command(output: &mut dyn io::Write) -> Result<(), CommandError> {
|
||||
|
||||
Ok(writeln!(output, "All tests passed!")?)
|
||||
}
|
||||
|
||||
/// Implements a command that tests the global allocator error handling.
|
||||
fn test_alloc_error_command(output: &mut dyn io::Write) -> Result<(), CommandError> {
|
||||
extern crate alloc;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
// Default heap holds 16KB.
|
||||
let mut vec = Vec::with_capacity(16384);
|
||||
for i in 0..16348 {
|
||||
vec.push(i);
|
||||
}
|
||||
Ok(writeln!(output, "vec at {:p}", vec.as_slice())?)
|
||||
}
|
||||
|
||||
/// Implements a command that tests panic handling.
|
||||
fn test_panic_command() -> Result<(), CommandError> {
|
||||
panic!("testing");
|
||||
}
|
||||
|
Reference in New Issue
Block a user