summaryrefslogtreecommitdiffstats
path: root/src/system_alloc.rs
blob: ad1afcb945b3bd67cfed63d146c1345b7e9ff55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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");
}