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::alloc::{GlobalAlloc, Layout};
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
use core::panic;
|
||||||
use core::ptr::{self, NonNull};
|
use core::ptr::{self, NonNull};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
@@ -19,9 +20,8 @@ pub struct KataHeap {
|
|||||||
pub static ALLOCATOR: KataHeap = KataHeap::empty();
|
pub static ALLOCATOR: KataHeap = KataHeap::empty();
|
||||||
|
|
||||||
#[alloc_error_handler]
|
#[alloc_error_handler]
|
||||||
fn alloc_error_handler(_: Layout) -> ! {
|
fn alloc_error_handler(layout: Layout) -> ! {
|
||||||
// TODO(sleffler): at least print a msg on the console
|
panic!("Global allocation failure: {:?}", layout);
|
||||||
loop {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KataHeap {
|
impl KataHeap {
|
||||||
|
@@ -9,6 +9,7 @@ description = "Kata OS DebugConsole"
|
|||||||
panic-halt = "0.2.0"
|
panic-halt = "0.2.0"
|
||||||
kata-allocator = { path = "../kata-allocator" }
|
kata-allocator = { path = "../kata-allocator" }
|
||||||
kata-logger = { path = "../kata-logger" }
|
kata-logger = { path = "../kata-logger" }
|
||||||
|
kata-panic = { path = "../kata-panic" }
|
||||||
kata-shell = { path = "../kata-shell" }
|
kata-shell = { path = "../kata-shell" }
|
||||||
kata-uart-client = { path = "../kata-uart-client" }
|
kata-uart-client = { path = "../kata-uart-client" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
@@ -9,11 +9,9 @@
|
|||||||
// * kata_shell
|
// * kata_shell
|
||||||
// * kata_debug_console main entry point fn run()
|
// * 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]
|
#![no_std]
|
||||||
|
|
||||||
extern crate panic_halt;
|
extern crate kata_panic;
|
||||||
|
|
||||||
use kata_allocator;
|
use kata_allocator;
|
||||||
use kata_logger::KataLogger;
|
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
|
// Since even the binding is static, it is fine for each command
|
||||||
// implementation to use its own preferred signature.
|
// implementation to use its own preferred signature.
|
||||||
let result = match command {
|
let result = match command {
|
||||||
"echo" => echo_command(cmdline, output),
|
|
||||||
"add" => add_command(&mut args, output),
|
"add" => add_command(&mut args, output),
|
||||||
|
"echo" => echo_command(cmdline, output),
|
||||||
"clear" => clear_command(output),
|
"clear" => clear_command(output),
|
||||||
"ps" => ps_command(),
|
"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),
|
_ => Err(CommandError::UnknownCommand),
|
||||||
};
|
};
|
||||||
if let Err(e) = result {
|
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.
|
/// Implements a command that tests facilities that use the global allocator.
|
||||||
/// Shamelessly cribbed from https://os.phil-opp.com/heap-allocation/
|
/// 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;
|
extern crate alloc;
|
||||||
use alloc::{boxed::Box, rc::Rc, vec, vec::Vec};
|
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!")?)
|
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");
|
||||||
|
}
|
||||||
|
@@ -8,9 +8,9 @@ edition = "2018"
|
|||||||
arrayvec = { version = "0.7", default-features = false }
|
arrayvec = { version = "0.7", default-features = false }
|
||||||
kata-allocator = { path = "../../DebugConsole/kata-allocator" }
|
kata-allocator = { path = "../../DebugConsole/kata-allocator" }
|
||||||
kata-logger = { path = "../../DebugConsole/kata-logger" }
|
kata-logger = { path = "../../DebugConsole/kata-logger" }
|
||||||
|
kata-panic = { path = "../../DebugConsole/kata-panic" }
|
||||||
kata-proc-common = { path = "../kata-proc-common" }
|
kata-proc-common = { path = "../kata-proc-common" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
panic-halt = "0.2.0"
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "kata_process_manager"
|
name = "kata_process_manager"
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
#![feature(const_fn_trait_bound)] // NB: for ProcessManager::empty using manager: None
|
#![feature(const_fn_trait_bound)] // NB: for ProcessManager::empty using manager: None
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
extern crate panic_halt;
|
extern crate kata_panic;
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use core::marker::Sync;
|
use core::marker::Sync;
|
||||||
|
Reference in New Issue
Block a user