about summary refs log tree commit diff
path: root/library/std/src/sys/alloc/hermit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/alloc/hermit.rs')
-rw-r--r--library/std/src/sys/alloc/hermit.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/library/std/src/sys/alloc/hermit.rs b/library/std/src/sys/alloc/hermit.rs
new file mode 100644
index 00000000000..77f8200a70a
--- /dev/null
+++ b/library/std/src/sys/alloc/hermit.rs
@@ -0,0 +1,27 @@
+use crate::alloc::{GlobalAlloc, Layout, System};
+
+#[stable(feature = "alloc_system_type", since = "1.28.0")]
+unsafe impl GlobalAlloc for System {
+    #[inline]
+    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+        let size = layout.size();
+        let align = layout.align();
+        unsafe { hermit_abi::malloc(size, align) }
+    }
+
+    #[inline]
+    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
+        let size = layout.size();
+        let align = layout.align();
+        unsafe {
+            hermit_abi::free(ptr, size, align);
+        }
+    }
+
+    #[inline]
+    unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
+        let size = layout.size();
+        let align = layout.align();
+        unsafe { hermit_abi::realloc(ptr, size, align, new_size) }
+    }
+}