diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2020-05-01 18:46:23 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2020-05-01 22:16:38 +0200 |
commit | fd2384b7fab14732efde99da8affd830e2334e16 (patch) | |
tree | a17111e3363c457ec727b52023212c113d8304f6 /src/system_alloc.rs | |
parent | 5b449f4e1e43bc59109da5a37edf5ec911d3df8e (diff) | |
download | neco-fd2384b7fab14732efde99da8affd830e2334e16.tar neco-fd2384b7fab14732efde99da8affd830e2334e16.zip |
Nightly stuff
Diffstat (limited to 'src/system_alloc.rs')
-rw-r--r-- | src/system_alloc.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/system_alloc.rs b/src/system_alloc.rs new file mode 100644 index 0000000..ad1afcb --- /dev/null +++ b/src/system_alloc.rs @@ -0,0 +1,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"); +} |