mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-12 01:51:34 +11:00
Correctly handle OOM
This commit is contained in:
parent
94d5a71007
commit
81e9789272
|
@ -2,6 +2,9 @@ use core::alloc::{GlobalAlloc, Layout};
|
||||||
|
|
||||||
use crate::interrupt::Mutex;
|
use crate::interrupt::Mutex;
|
||||||
|
|
||||||
|
const EWRAM_START: usize = 0x0200_0000;
|
||||||
|
const EWRAM_END: usize = 0x0204_0000;
|
||||||
|
|
||||||
fn get_data_end() -> usize {
|
fn get_data_end() -> usize {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static __ewram_data_end: usize;
|
static __ewram_data_end: usize;
|
||||||
|
@ -12,7 +15,7 @@ fn get_data_end() -> usize {
|
||||||
(unsafe { &__ewram_data_end }) as *const _ as usize
|
(unsafe { &__ewram_data_end }) as *const _ as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct BumpAllocator {
|
pub(crate) struct BumpAllocator {
|
||||||
current_ptr: Mutex<*mut u8>,
|
current_ptr: Mutex<*mut u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +45,10 @@ impl BumpAllocator {
|
||||||
let resulting_ptr = ptr + amount_to_add;
|
let resulting_ptr = ptr + amount_to_add;
|
||||||
*current_ptr = (resulting_ptr + layout.size()) as *mut _;
|
*current_ptr = (resulting_ptr + layout.size()) as *mut _;
|
||||||
|
|
||||||
|
if *current_ptr as usize >= EWRAM_END {
|
||||||
|
return core::ptr::null_mut();
|
||||||
|
}
|
||||||
|
|
||||||
resulting_ptr as *mut _
|
resulting_ptr as *mut _
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue