blob: 7c0bac9b49bd0ec4fe796c00ae298959c28a13e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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;
#[cfg(not(test))]
#[alloc_error_handler]
fn alloc_error(_: core::alloc::Layout) -> ! {
panic!("allocation failure");
}
|