diff options
| author | Stefan Lankes <slankes@eonerc.rwth-aachen.de> | 2019-10-06 15:26:14 +0000 |
|---|---|---|
| committer | Stefan Lankes <slankes@eonerc.rwth-aachen.de> | 2019-10-06 15:26:14 +0000 |
| commit | c1e440a90f472468c8069ba6254b23c6feedc32e (patch) | |
| tree | 6e7920b36e0ecd63e8b7b1a6ec236ff5e86a5a01 /src/libstd/sys/hermit/alloc.rs | |
| parent | 7870050796e5904a0fc85ecbe6fa6dde1cfe0c91 (diff) | |
| download | rust-c1e440a90f472468c8069ba6254b23c6feedc32e.tar.gz rust-c1e440a90f472468c8069ba6254b23c6feedc32e.zip | |
redesign of the interface to the unikernel HermitCore
- the old interface between HermitCore and the Rust Standard Library based on a small C library (newlib) - remove this interface and call directly the unikernel - remove the dependency to the HermitCore linker - use rust-lld as linker
Diffstat (limited to 'src/libstd/sys/hermit/alloc.rs')
| -rw-r--r-- | src/libstd/sys/hermit/alloc.rs | 40 |
1 files changed, 40 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..802a179fb67 --- /dev/null +++ b/src/libstd/sys/hermit/alloc.rs @@ -0,0 +1,40 @@ +use crate::alloc::{GlobalAlloc, Layout, System}; +use crate::ptr; + +extern "C" { + fn sys_malloc(size: usize, align: usize) -> *mut u8; + fn sys_realloc(ptr: *mut u8, size: usize, align: usize, new_size: usize) -> *mut u8; + fn sys_free(ptr: *mut u8, size: usize, align: usize); +} + +#[stable(feature = "alloc_system_type", since = "1.28.0")] +unsafe impl GlobalAlloc for System { + #[inline] + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + sys_malloc(layout.size(), layout.align()) + } + + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + let addr = sys_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) { + sys_free(ptr, layout.size(), layout.align()) + } + + #[inline] + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + sys_realloc(ptr, layout.size(), layout.align(), new_size) + } +} |
