There are major questions remaining about the reentrancy that this allows. It doesn't have any users on github outside of a single project that uses it in a panic=abort project to show backtraces. It can still be emulated through #[alloc_error_handler] or set_alloc_error_hook depending on if you use the standard library or not. And finally it makes it harder to do various improvements to the allocator shim.
26 lines
722 B
Rust
26 lines
722 B
Rust
//! Test that out-of-memory conditions trigger catchable panics with `set_alloc_error_hook`.
|
|
|
|
//@ run-pass
|
|
//@ needs-unwind
|
|
//@ only-linux
|
|
//@ ignore-backends: gcc
|
|
|
|
#![feature(alloc_error_hook)]
|
|
|
|
use std::hint::black_box;
|
|
use std::mem::forget;
|
|
use std::panic::catch_unwind;
|
|
|
|
fn main() {
|
|
std::alloc::set_alloc_error_hook(|_| panic!());
|
|
|
|
let panic = catch_unwind(|| {
|
|
// This is guaranteed to exceed even the size of the address space
|
|
for _ in 0..16 {
|
|
// Truncates to a suitable value for both 32-bit and 64-bit targets.
|
|
let alloc_size = 0x1000_0000_1000_0000u64 as usize;
|
|
forget(black_box(vec![0u8; alloc_size]));
|
|
}
|
|
});
|
|
assert!(panic.is_err());
|
|
}
|