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 pub mod __default_lib_allocator {
21 use super::{System, Layout, Alloc, AllocErr};
24 // for symbol names src/librustc/middle/allocator.rs
25 // for signatures src/librustc_allocator/lib.rs
27 // linkage directives are provided as part of the current compiler allocator
31 pub unsafe extern fn __rdl_alloc(size: usize,
33 err: *mut u8) -> *mut u8 {
34 let layout = Layout::from_size_align_unchecked(size, align);
35 match System.alloc(layout) {
38 ptr::write(err as *mut AllocErr, e);
45 pub unsafe extern fn __rdl_oom(err: *const u8) -> ! {
46 System.oom((*(err as *const AllocErr)).clone())
50 pub unsafe extern fn __rdl_dealloc(ptr: *mut u8,
53 System.dealloc(ptr, Layout::from_size_align_unchecked(size, align))
57 pub unsafe extern fn __rdl_usable_size(layout: *const u8,
60 let pair = System.usable_size(&*(layout as *const Layout));
66 pub unsafe extern fn __rdl_realloc(ptr: *mut u8,
71 err: *mut u8) -> *mut u8 {
72 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
73 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
74 match System.realloc(ptr, old_layout, new_layout) {
77 ptr::write(err as *mut AllocErr, e);
84 pub unsafe extern fn __rdl_alloc_zeroed(size: usize,
86 err: *mut u8) -> *mut u8 {
87 let layout = Layout::from_size_align_unchecked(size, align);
88 match System.alloc_zeroed(layout) {
91 ptr::write(err as *mut AllocErr, e);
98 pub unsafe extern fn __rdl_alloc_excess(size: usize,
101 err: *mut u8) -> *mut u8 {
102 let layout = Layout::from_size_align_unchecked(size, align);
103 match System.alloc_excess(layout) {
109 ptr::write(err as *mut AllocErr, e);
116 pub unsafe extern fn __rdl_realloc_excess(ptr: *mut u8,
122 err: *mut u8) -> *mut u8 {
123 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
124 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
125 match System.realloc_excess(ptr, old_layout, new_layout) {
131 ptr::write(err as *mut AllocErr, e);
138 pub unsafe extern fn __rdl_grow_in_place(ptr: *mut u8,
142 new_align: usize) -> u8 {
143 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
144 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
145 match System.grow_in_place(ptr, old_layout, new_layout) {
152 pub unsafe extern fn __rdl_shrink_in_place(ptr: *mut u8,
156 new_align: usize) -> u8 {
157 let old_layout = Layout::from_size_align_unchecked(old_size, old_align);
158 let new_layout = Layout::from_size_align_unchecked(new_size, new_align);
159 match System.shrink_in_place(ptr, old_layout, new_layout) {