mallocator/lib.rs
1#![no_std]
2
3use core::alloc::{GlobalAlloc, Layout};
4
5pub struct Mallocator;
6
7extern "C" {
8 fn malloc(size: usize) -> *mut u8;
9 fn free(ptr: *mut u8);
10}
11
12unsafe impl GlobalAlloc for Mallocator {
13 unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
14 malloc(layout.size())
15 }
16
17 unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
18 free(ptr)
19 }
20}