about summary refs log tree commit diff
path: root/src/libstd/sys/hermit/alloc.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-26 19:35:59 +0000
committerbors <bors@rust-lang.org>2019-10-26 19:35:59 +0000
commitfae75cd216c481de048e4951697c8f8525669c65 (patch)
tree157e46f84638aa1fa3b0339ced417876e8ca209a /src/libstd/sys/hermit/alloc.rs
parent46e6c533d08a2c6d22083a2756a0b569e001c3c4 (diff)
parent805a330ab4c7f33421acacbee0545f6991b2fc70 (diff)
downloadrust-fae75cd216c481de048e4951697c8f8525669c65.tar.gz
rust-fae75cd216c481de048e4951697c8f8525669c65.zip
Auto merge of #65167 - hermitcore:rusty-hermit, r=alexcrichton
Redesign the interface to the unikernel HermitCore

We are developing the unikernel HermitCore, where the kernel is written in Rust and is already part of the Rust Standard Library. The interface between the standard library and the kernel based on a small C library. With this pull request, we remove completely the dependency to C and use lld as linker. Currently, the kernel will be linked to the application as static library, which is published at https://github.com/hermitcore/libhermit-rs.

We don’t longer support the C interface to the kernel. Consequently, we remove this part from the Rust Standard Library.
Diffstat (limited to 'src/libstd/sys/hermit/alloc.rs')
-rw-r--r--src/libstd/sys/hermit/alloc.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libstd/sys/hermit/alloc.rs b/src/libstd/sys/hermit/alloc.rs
new file mode 100644
index 00000000000..86cc4463632
--- /dev/null
+++ b/src/libstd/sys/hermit/alloc.rs
@@ -0,0 +1,35 @@
+use crate::alloc::{GlobalAlloc, Layout, System};
+use crate::ptr;
+use crate::sys::hermit::abi;
+
+#[stable(feature = "alloc_system_type", since = "1.28.0")]
+unsafe impl GlobalAlloc for System {
+    #[inline]
+    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+        abi::malloc(layout.size(), layout.align())
+    }
+
+    unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
+        let addr = abi::malloc(layout.size(), layout.align());
+
+        if !addr.is_null() {
+            ptr::write_bytes(
+                addr,
+                0x00,
+                layout.size()
+            );
+        }
+
+        addr
+    }
+
+    #[inline]
+    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
+        abi::free(ptr, layout.size(), layout.align())
+    }
+
+    #[inline]
+    unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
+        abi::realloc(ptr, layout.size(), layout.align(), new_size)
+    }
+}