2017-06-03 21:54:08 +00:00
|
|
|
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! dox
|
|
|
|
|
|
|
|
#![unstable(issue = "32838", feature = "allocator_api")]
|
|
|
|
|
2018-04-03 19:15:06 +00:00
|
|
|
#[doc(inline)] #[allow(deprecated)] pub use alloc_crate::alloc::Heap;
|
2018-05-15 00:56:46 +00:00
|
|
|
#[doc(inline)] pub use alloc_crate::alloc::{Global, Layout, oom};
|
2018-04-03 19:05:10 +00:00
|
|
|
#[doc(inline)] pub use alloc_system::System;
|
|
|
|
#[doc(inline)] pub use core::alloc::*;
|
2017-06-03 21:54:08 +00:00
|
|
|
|
2018-04-21 04:05:13 +00:00
|
|
|
#[cfg(not(test))]
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[lang = "oom"]
|
2018-05-15 00:56:46 +00:00
|
|
|
pub extern fn rust_oom(_: Layout) -> ! {
|
2018-04-21 04:05:13 +00:00
|
|
|
rtabort!("memory allocation failed");
|
|
|
|
}
|
|
|
|
|
2017-07-17 16:32:08 +00:00
|
|
|
#[cfg(not(test))]
|
2017-06-03 21:54:08 +00:00
|
|
|
#[doc(hidden)]
|
2017-11-01 20:16:36 +00:00
|
|
|
#[allow(unused_attributes)]
|
2017-06-03 21:54:08 +00:00
|
|
|
pub mod __default_lib_allocator {
|
2018-04-11 15:19:48 +00:00
|
|
|
use super::{System, Layout, GlobalAlloc, Opaque};
|
2017-06-03 21:54:08 +00:00
|
|
|
// for symbol names src/librustc/middle/allocator.rs
|
|
|
|
// for signatures src/librustc_allocator/lib.rs
|
|
|
|
|
|
|
|
// linkage directives are provided as part of the current compiler allocator
|
|
|
|
// ABI
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-11-01 20:16:36 +00:00
|
|
|
#[rustc_std_internal_symbol]
|
2018-04-03 15:12:57 +00:00
|
|
|
pub unsafe extern fn __rdl_alloc(size: usize, align: usize) -> *mut u8 {
|
2017-06-03 21:54:08 +00:00
|
|
|
let layout = Layout::from_size_align_unchecked(size, align);
|
2018-04-03 15:12:57 +00:00
|
|
|
System.alloc(layout) as *mut u8
|
2017-06-03 21:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-11-01 20:16:36 +00:00
|
|
|
#[rustc_std_internal_symbol]
|
2017-06-03 21:54:08 +00:00
|
|
|
pub unsafe extern fn __rdl_dealloc(ptr: *mut u8,
|
|
|
|
size: usize,
|
|
|
|
align: usize) {
|
2018-04-11 15:19:48 +00:00
|
|
|
System.dealloc(ptr as *mut Opaque, Layout::from_size_align_unchecked(size, align))
|
2017-06-03 21:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-11-01 20:16:36 +00:00
|
|
|
#[rustc_std_internal_symbol]
|
2017-06-03 21:54:08 +00:00
|
|
|
pub unsafe extern fn __rdl_realloc(ptr: *mut u8,
|
|
|
|
old_size: usize,
|
2018-04-03 15:12:57 +00:00
|
|
|
align: usize,
|
|
|
|
new_size: usize) -> *mut u8 {
|
|
|
|
let old_layout = Layout::from_size_align_unchecked(old_size, align);
|
2018-04-11 15:19:48 +00:00
|
|
|
System.realloc(ptr as *mut Opaque, old_layout, new_size) as *mut u8
|
2017-06-03 21:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-11-01 20:16:36 +00:00
|
|
|
#[rustc_std_internal_symbol]
|
2018-04-03 15:12:57 +00:00
|
|
|
pub unsafe extern fn __rdl_alloc_zeroed(size: usize, align: usize) -> *mut u8 {
|
2017-06-03 21:54:08 +00:00
|
|
|
let layout = Layout::from_size_align_unchecked(size, align);
|
2018-04-03 15:12:57 +00:00
|
|
|
System.alloc_zeroed(layout) as *mut u8
|
2017-06-03 21:54:08 +00:00
|
|
|
}
|
|
|
|
}
|