]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/sgx/alloc.rs
Add x86_64-fortanix-unknown-sgx target to libstd and dependencies
[rust.git] / src / libstd / sys / sgx / alloc.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 extern crate dlmalloc;
12
13 use alloc::{GlobalAlloc, Layout, System};
14
15 // FIXME: protect this value for concurrent access
16 static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
17
18 #[stable(feature = "alloc_system_type", since = "1.28.0")]
19 unsafe impl GlobalAlloc for System {
20     #[inline]
21     unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
22         DLMALLOC.malloc(layout.size(), layout.align())
23     }
24
25     #[inline]
26     unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
27         DLMALLOC.calloc(layout.size(), layout.align())
28     }
29
30     #[inline]
31     unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
32         DLMALLOC.free(ptr, layout.size(), layout.align())
33     }
34
35     #[inline]
36     unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
37         DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size)
38     }
39 }