This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
neco/src/system_alloc.rs
2020-05-01 22:16:38 +02:00

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");
}