forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalloc.rs
More file actions
33 lines (26 loc) · 876 Bytes
/
Copy pathalloc.rs
File metadata and controls
33 lines (26 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::alloc::{GlobalAlloc, Layout};
use crate::ptr;
use crate::sys::hermit::abi;
#[derive(Debug, Default, Copy, Clone)]
pub(crate) struct System;
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)
}
}