Skip to content

Commit 08e7eff

Browse files
authored
Rollup merge of rust-lang#92535 - Amanieu:oom_hook_unwind, r=m-ou-se
Allow unwinding from OOM hooks This is split off from rust-lang#88098 and contains just the bare minimum to allow specifying a custom OOM hook with `set_alloc_error_hook` which unwinds instead of aborting. See rust-lang#88098 for an actual command-line flag which switches the default OOM behavior to unwind instead of aborting. Previous perf results show a negligible impact on performance.
2 parents 21fe214 + f4545cc commit 08e7eff

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

library/alloc/src/alloc.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ extern "Rust" {
348348
// This is the magic symbol to call the global alloc error handler. rustc generates
349349
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
350350
// default implementations below (`__rdl_oom`) otherwise.
351-
#[rustc_allocator_nounwind]
352351
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
353352
}
354353

@@ -367,7 +366,6 @@ extern "Rust" {
367366
#[stable(feature = "global_alloc", since = "1.28.0")]
368367
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
369368
#[cfg(all(not(no_global_oom_handling), not(test)))]
370-
#[rustc_allocator_nounwind]
371369
#[cold]
372370
pub const fn handle_alloc_error(layout: Layout) -> ! {
373371
const fn ct_error(_: Layout) -> ! {
@@ -398,13 +396,13 @@ pub mod __alloc_error_handler {
398396

399397
// if there is no `#[alloc_error_handler]`
400398
#[rustc_std_internal_symbol]
401-
pub unsafe extern "C" fn __rdl_oom(size: usize, _align: usize) -> ! {
399+
pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! {
402400
panic!("memory allocation of {} bytes failed", size)
403401
}
404402

405403
// if there is an `#[alloc_error_handler]`
406404
#[rustc_std_internal_symbol]
407-
pub unsafe extern "C" fn __rg_oom(size: usize, align: usize) -> ! {
405+
pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! {
408406
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
409407
extern "Rust" {
410408
#[lang = "oom"]

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
#![cfg_attr(test, feature(test))]
169169
#![feature(unboxed_closures)]
170170
#![feature(unsized_fn_params)]
171+
#![feature(c_unwind)]
171172
//
172173
// Rustdoc features:
173174
#![feature(doc_cfg)]

0 commit comments

Comments
 (0)