Skip to content

Commit 719b04c

Browse files
committed
Auto merge of #92535 - Amanieu:oom_hook_unwind, r=m-ou-se
Allow unwinding from OOM hooks This is split off from #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 #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 88fb06a + 2082842 commit 719b04c

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
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
@@ -163,6 +163,7 @@
163163
#![cfg_attr(test, feature(test))]
164164
#![feature(unboxed_closures)]
165165
#![feature(unsized_fn_params)]
166+
#![feature(c_unwind)]
166167
//
167168
// Rustdoc features:
168169
#![feature(doc_cfg)]

0 commit comments

Comments
 (0)