Skip to content

Commit fb47422

Browse files
committed
Auto merge of rust-lang#79128 - m-ou-se:rollup-lzz1dym, r=m-ou-se
Rollup of 9 pull requests Successful merges: - rust-lang#77939 (Ensure that the source code display is working with DOS backline) - rust-lang#78138 (Upgrade dlmalloc to version 0.2) - rust-lang#78967 (Make codegen tests compatible with extra inlining) - rust-lang#79027 (Limit storage duration of inlined always live locals) - rust-lang#79077 (document that __rust_alloc is also magic to our LLVM fork) - rust-lang#79088 (clarify `span_label` documentation) - rust-lang#79097 (Code block invalid html tag lint) - rust-lang#79105 (std: Fix test `symlink_hard_link` on Windows) - rust-lang#79107 (build-manifest: strip newline from rustc version) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 600b7fd + bf37009 commit fb47422

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

alloc/src/alloc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ extern "Rust" {
2323
// (the code expanding that attribute macro generates those functions), or to call
2424
// the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
2525
// otherwise.
26+
// The rustc fork of LLVM also special-cases these function names to be able to optimize them
27+
// like `malloc`, `realloc`, and `free`, respectively.
2628
#[rustc_allocator]
2729
#[rustc_allocator_nounwind]
2830
fn __rust_alloc(size: usize, align: usize) -> *mut u8;

std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ features = ['read_core', 'elf', 'macho', 'pe']
3636
rand = "0.7"
3737

3838
[target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
39-
dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] }
39+
dlmalloc = { version = "0.2.1", features = ['rustc-dep-of-std'] }
4040

4141
[target.x86_64-fortanix-unknown-sgx.dependencies]
4242
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }

std/src/fs/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,9 @@ fn metadata_access_times() {
13411341
#[test]
13421342
fn symlink_hard_link() {
13431343
let tmpdir = tmpdir();
1344+
if !got_symlink_permission(&tmpdir) {
1345+
return;
1346+
};
13441347

13451348
// Create "file", a file.
13461349
check!(fs::File::create(tmpdir.join("file")));

std/src/sys/sgx/abi/mem.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ pub(crate) unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
1212

1313
extern "C" {
1414
static ENCLAVE_SIZE: usize;
15+
static HEAP_BASE: u64;
16+
static HEAP_SIZE: usize;
17+
}
18+
19+
/// Returns the base memory address of the heap
20+
pub(crate) fn heap_base() -> *const u8 {
21+
unsafe { rel_ptr_mut(HEAP_BASE) }
22+
}
23+
24+
/// Returns the size of the heap
25+
pub(crate) fn heap_size() -> usize {
26+
unsafe { HEAP_SIZE }
1527
}
1628

1729
// Do not remove inline: will result in relocation failure

std/src/sys/sgx/alloc.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use crate::alloc::{GlobalAlloc, Layout, System};
2+
use crate::ptr;
3+
use crate::sys::sgx::abi::mem as sgx_mem;
4+
use core::sync::atomic::{AtomicBool, Ordering};
25

36
use super::waitqueue::SpinMutex;
47

@@ -10,7 +13,48 @@ use super::waitqueue::SpinMutex;
1013
// dlmalloc.c from C to Rust.
1114
#[cfg_attr(test, linkage = "available_externally")]
1215
#[export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE"]
13-
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc> = SpinMutex::new(dlmalloc::DLMALLOC_INIT);
16+
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc<Sgx>> =
17+
SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));
18+
19+
struct Sgx;
20+
21+
unsafe impl dlmalloc::Allocator for Sgx {
22+
/// Allocs system resources
23+
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
24+
static INIT: AtomicBool = AtomicBool::new(false);
25+
26+
// No ordering requirement since this function is protected by the global lock.
27+
if !INIT.swap(true, Ordering::Relaxed) {
28+
(sgx_mem::heap_base() as _, sgx_mem::heap_size(), 0)
29+
} else {
30+
(ptr::null_mut(), 0, 0)
31+
}
32+
}
33+
34+
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
35+
ptr::null_mut()
36+
}
37+
38+
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
39+
false
40+
}
41+
42+
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
43+
return false;
44+
}
45+
46+
fn can_release_part(&self, _flags: u32) -> bool {
47+
false
48+
}
49+
50+
fn allocates_zeros(&self) -> bool {
51+
false
52+
}
53+
54+
fn page_size(&self) -> usize {
55+
0x1000
56+
}
57+
}
1458

1559
#[stable(feature = "alloc_system_type", since = "1.28.0")]
1660
unsafe impl GlobalAlloc for System {

std/src/sys/wasm/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use crate::alloc::{GlobalAlloc, Layout, System};
2020

21-
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
21+
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();
2222

2323
#[stable(feature = "alloc_system_type", since = "1.28.0")]
2424
unsafe impl GlobalAlloc for System {

0 commit comments

Comments
 (0)