1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#![doc(html_root_url = "https://docs.rs/ruspiro-allocator/0.0.2")]
#![no_std]
#![feature(global_asm)]
#![feature(alloc_error_handler)]
#[global_allocator]
static ALLOCATOR: RusPiRoAllocator = RusPiRoAllocator;
use core::alloc::{GlobalAlloc, Layout};
struct RusPiRoAllocator;
unsafe impl GlobalAlloc for RusPiRoAllocator {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
m_alloca(layout.size() as u32, layout.align() as u16)
}
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
m_freea(ptr)
}
#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let ptr = m_alloca(layout.size() as u32, layout.align() as u16);
m_memset(ptr, 0x0, layout.size() as u32);
ptr
}
}
#[alloc_error_handler]
fn alloc_error_handler(_: Layout) -> ! {
loop { }
}
extern "C" {
fn m_alloca(size: u32, align: u16) -> *mut u8;
fn m_freea(ptr: *mut u8);
fn m_memset(ptr: *mut u8, value: u32, size: u32);
}
global_asm!(include_str!("./asm/memset.s"));