]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/hermit/alloc.rs
Rollup merge of #102445 - jmillikin:cstr-is-empty, r=Mark-Simulacrum
[rust.git] / library / std / src / sys / hermit / alloc.rs
1 use crate::alloc::{GlobalAlloc, Layout, System};
2 use crate::ptr;
3 use crate::sys::hermit::abi;
4
5 #[stable(feature = "alloc_system_type", since = "1.28.0")]
6 unsafe impl GlobalAlloc for System {
7     #[inline]
8     unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
9         abi::malloc(layout.size(), layout.align())
10     }
11
12     unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
13         let addr = abi::malloc(layout.size(), layout.align());
14
15         if !addr.is_null() {
16             ptr::write_bytes(addr, 0x00, layout.size());
17         }
18
19         addr
20     }
21
22     #[inline]
23     unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
24         abi::free(ptr, layout.size(), layout.align())
25     }
26
27     #[inline]
28     unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
29         abi::realloc(ptr, layout.size(), layout.align(), new_size)
30     }
31 }