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
;
16 pub use alloc_system
::System
;
17 pub use core
::heap
::*;
21 #[allow(unused_attributes)]
22 pub mod __default_lib_allocator
{
23 use super::{System, Layout, Alloc, AllocErr}
;
26 // for symbol names src/librustc/middle/allocator.rs
27 // for signatures src/librustc_allocator/lib.rs
29 // linkage directives are provided as part of the current compiler allocator
33 #[rustc_std_internal_symbol]
34 pub unsafe extern fn __rdl_alloc(size
: usize,
36 err
: *mut u8) -> *mut u8 {
37 let layout
= Layout
::from_size_align_unchecked(size
, align
);
38 match System
.alloc(layout
) {
41 ptr
::write(err
as *mut AllocErr
, e
);
48 #[rustc_std_internal_symbol]
49 pub unsafe extern fn __rdl_oom(err
: *const u8) -> ! {
50 System
.oom((*(err
as *const AllocErr
)).clone())
54 #[rustc_std_internal_symbol]
55 pub unsafe extern fn __rdl_dealloc(ptr
: *mut u8,
58 System
.dealloc(ptr
, Layout
::from_size_align_unchecked(size
, align
))
62 #[rustc_std_internal_symbol]
63 pub unsafe extern fn __rdl_usable_size(layout
: *const u8,
66 let pair
= System
.usable_size(&*(layout
as *const Layout
));
72 #[rustc_std_internal_symbol]
73 pub unsafe extern fn __rdl_realloc(ptr
: *mut u8,
78 err
: *mut u8) -> *mut u8 {
79 let old_layout
= Layout
::from_size_align_unchecked(old_size
, old_align
);
80 let new_layout
= Layout
::from_size_align_unchecked(new_size
, new_align
);
81 match System
.realloc(ptr
, old_layout
, new_layout
) {
84 ptr
::write(err
as *mut AllocErr
, e
);
91 #[rustc_std_internal_symbol]
92 pub unsafe extern fn __rdl_alloc_zeroed(size
: usize,
94 err
: *mut u8) -> *mut u8 {
95 let layout
= Layout
::from_size_align_unchecked(size
, align
);
96 match System
.alloc_zeroed(layout
) {
99 ptr
::write(err
as *mut AllocErr
, e
);
106 #[rustc_std_internal_symbol]
107 pub unsafe extern fn __rdl_alloc_excess(size
: usize,
110 err
: *mut u8) -> *mut u8 {
111 let layout
= Layout
::from_size_align_unchecked(size
, align
);
112 match System
.alloc_excess(layout
) {
118 ptr
::write(err
as *mut AllocErr
, e
);
125 #[rustc_std_internal_symbol]
126 pub unsafe extern fn __rdl_realloc_excess(ptr
: *mut u8,
132 err
: *mut u8) -> *mut u8 {
133 let old_layout
= Layout
::from_size_align_unchecked(old_size
, old_align
);
134 let new_layout
= Layout
::from_size_align_unchecked(new_size
, new_align
);
135 match System
.realloc_excess(ptr
, old_layout
, new_layout
) {
141 ptr
::write(err
as *mut AllocErr
, e
);
148 #[rustc_std_internal_symbol]
149 pub unsafe extern fn __rdl_grow_in_place(ptr
: *mut u8,
153 new_align
: usize) -> u8 {
154 let old_layout
= Layout
::from_size_align_unchecked(old_size
, old_align
);
155 let new_layout
= Layout
::from_size_align_unchecked(new_size
, new_align
);
156 match System
.grow_in_place(ptr
, old_layout
, new_layout
) {
163 #[rustc_std_internal_symbol]
164 pub unsafe extern fn __rdl_shrink_in_place(ptr
: *mut u8,
168 new_align
: usize) -> u8 {
169 let old_layout
= Layout
::from_size_align_unchecked(old_size
, old_align
);
170 let new_layout
= Layout
::from_size_align_unchecked(new_size
, new_align
);
171 match System
.shrink_in_place(ptr
, old_layout
, new_layout
) {