Add custom_panic_handler and custom_alloc_error_handler feature
diff --git a/Cargo.toml b/Cargo.toml
index 51e49db..549e72a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,8 @@
[features]
alloc = ["libtock-core/alloc"]
+custom_panic_handler = ["libtock-core/custom_panic_handler"]
+custom_alloc_error_handler = ["libtock-core/custom_alloc_error_handler"]
[dependencies]
core = { package = "async-support", path = "async-support" }
diff --git a/core/Cargo.toml b/core/Cargo.toml
index b154552..004819c 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -8,6 +8,8 @@
[features]
alloc = [ "linked_list_allocator" ]
+custom_panic_handler = []
+custom_alloc_error_handler = []
[dependencies]
linked_list_allocator = { optional = true, version = "=0.6.5", default-features = false }
\ No newline at end of file
diff --git a/core/src/alloc.rs b/core/src/alloc.rs
index bcc5d6e..05e9669 100644
--- a/core/src/alloc.rs
+++ b/core/src/alloc.rs
@@ -1,4 +1,3 @@
-use crate::syscalls;
use core::alloc::GlobalAlloc;
use core::alloc::Layout;
use core::ptr;
@@ -24,8 +23,17 @@
#[global_allocator]
static ALLOCATOR: TockAllocator = TockAllocator;
+#[cfg(not(feature = "custom_alloc_error_handler"))]
#[alloc_error_handler]
unsafe fn alloc_error_handler(_: Layout) -> ! {
+ use crate::syscalls;
+
+ // Print 0x01 using the LowLevelDebug capsule (if available).
+ let _ = syscalls::command1_insecure(8, 2, 0x01);
+
+ // Signal a panic using the LowLevelDebug capsule (if available).
+ let _ = syscalls::command1_insecure(8, 1, 0x01);
+
loop {
syscalls::raw::yieldk();
}
diff --git a/core/src/lang_items.rs b/core/src/lang_items.rs
index 4932420..b5c2cd4 100644
--- a/core/src/lang_items.rs
+++ b/core/src/lang_items.rs
@@ -19,7 +19,6 @@
//! crate.
use crate::syscalls;
-use core::panic::PanicInfo;
#[lang = "start"]
extern "C" fn start<T>(main: fn() -> T, _argc: isize, _argv: *const *const u8) -> bool
@@ -47,8 +46,9 @@
}
}
+#[cfg(not(feature = "custom_panic_handler"))]
#[panic_handler]
-unsafe fn panic_handler(_info: &PanicInfo) -> ! {
+unsafe fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
report_panic()
}