Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Add a simple allocation error handler gated behind a feature #3

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ xtensa-lx = { version = "0.7.0", features = ["esp32s2"] }
[target.xtensa-esp32s3-none-elf.dependencies]
linked_list_allocator = "0.9.1"
xtensa-lx = { version = "0.7.0", features = ["esp32s3"] }

[features]
oom-handler = []
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! `nightly` release channel.

#![no_std]
#![cfg_attr(feature = "oom-handler", feature(alloc_error_handler))]

use core::{
alloc::{GlobalAlloc, Layout},
Expand All @@ -25,6 +26,12 @@ use riscv::interrupt;
#[cfg(target_arch = "xtensa")]
use xtensa_lx::interrupt;

#[cfg(feature = "oom-handler")]
#[alloc_error_handler]
fn oom(_: core::alloc::Layout) -> ! {
panic!("Allocation failed, out of memory");
}

pub struct EspHeap {
heap: Mutex<RefCell<Heap>>,
}
Expand Down