1 // Copyright 2017 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.
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.
13 #![unstable(issue = "32838", feature = "allocator_api")]
15 pub use alloc::heap::{Heap, Alloc, Layout, Excess, CannotReallocInPlace, AllocErr};
16 pub use alloc_system::System;
20 #[allow(unused_attributes)]
21 pub mod __default_lib_allocator {
22 use super::{System, Layout, Alloc, AllocErr};
25 // for symbol names src/librustc/middle/allocator.rs
26 // for signatures src/librustc_allocator/lib.rs
28 // linkage directives are provided as part of the current compiler allocator
32 #[rustc_std_internal_symbol]
33 pub unsafe extern fn __rdl_alloc(size: usize,
35 err: *mut u8) -> *mut u8 {
36 let layout = Layout::from_size_align_unchecked(size, align);
37 match System.alloc(layout) {
40 ptr::write(err as *mut AllocErr, e);
47 #[rustc_std_internal_symbol]
48 pub unsafe extern fn __rdl_oom(err: *const u8) -> ! {
49 System.oom((*(err as *const AllocErr)).clone())
53 #[rustc_std_internal_symbol]
54 pub unsafe extern fn __rdl_dealloc(ptr: *mut u8,
57 System.dealloc(ptr, Layout::from_size_align_unchecked(size, align))
61 #[rustc_std_internal_symbol]
62 pub unsafe extern fn __rdl_usable_size(layout: *const u8,
65 let pair = System.usable_size(&*(layout as *const Layout));
71 #[rustc_std_internal_symbol]
72 pub unsafe extern fn __rdl_realloc(ptr: *mut u8,
77 err: *mut u8) -> *mut u8 {
78 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
79 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
80 match System.realloc(ptr, old_layout, new_layout) {
83 ptr::write(err as *mut AllocErr, e);
90 #[rustc_std_internal_symbol]
91 pub unsafe extern fn __rdl_alloc_zeroed(size: usize,
93 err: *mut u8) -> *mut u8 {
94 let layout = Layout::from_size_align_unchecked(size, align);
95 match System.alloc_zeroed(layout) {
98 ptr::write(err as *mut AllocErr, e);
105 #[rustc_std_internal_symbol]
106 pub unsafe extern fn __rdl_alloc_excess(size: usize,
109 err: *mut u8) -> *mut u8 {
110 let layout = Layout::from_size_align_unchecked(size, align);
111 match System.alloc_excess(layout) {
117 ptr::write(err as *mut AllocErr, e);
124 #[rustc_std_internal_symbol]
125 pub unsafe extern fn __rdl_realloc_excess(ptr: *mut u8,
131 err: *mut u8) -> *mut u8 {
132 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
133 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
134 match System.realloc_excess(ptr, old_layout, new_layout) {
140 ptr::write(err as *mut AllocErr, e);
147 #[rustc_std_internal_symbol]
148 pub unsafe extern fn __rdl_grow_in_place(ptr: *mut u8,
152 new_align: usize) -> u8 {
153 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
154 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
155 match System.grow_in_place(ptr, old_layout, new_layout) {
162 #[rustc_std_internal_symbol]
163 pub unsafe extern fn __rdl_shrink_in_place(ptr: *mut u8,
167 new_align: usize) -> u8 {
168 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
169 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
170 match System.shrink_in_place(ptr, old_layout, new_layout) {