21 lines
483 B
Rust
21 lines
483 B
Rust
use safe_libc as libc;
|
|
|
|
struct System;
|
|
|
|
unsafe impl alloc::alloc::GlobalAlloc for System {
|
|
unsafe fn alloc(&self, layout: alloc::alloc::Layout) -> *mut u8 {
|
|
libc::memalign(layout.align(), layout.size()).cast()
|
|
}
|
|
|
|
unsafe fn dealloc(&self, ptr: *mut u8, _layout: alloc::alloc::Layout) {
|
|
libc::free(ptr.cast());
|
|
}
|
|
}
|
|
|
|
#[global_allocator]
|
|
static SYSTEM_ALLOC: System = System;
|
|
|
|
#[alloc_error_handler]
|
|
fn alloc_error(_: core::alloc::Layout) -> ! {
|
|
panic!("allocation failure");
|
|
}
|