Auto merge of #109507 - Amanieu:panic-oom-payload, r=davidtwco
Report allocation errors as panics OOM is now reported as a panic but with a custom payload type (`AllocErrorPanicPayload`) which holds the layout that was passed to `handle_alloc_error`. This should be review one commit at a time: - The first commit adds `AllocErrorPanicPayload` and changes allocation errors to always be reported as panics. - The second commit removes `#[alloc_error_handler]` and the `alloc_error_hook` API. ACP: https://github.com/rust-lang/libs-team/issues/192 Closes #51540 Closes #51245
This commit is contained in:
commit
c7155f2a78
@ -1,4 +1,4 @@
|
|||||||
#![feature(start, core_intrinsics, alloc_error_handler)]
|
#![feature(start, core_intrinsics)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@ -22,11 +22,6 @@ fn panic_handler(_: &core::panic::PanicInfo) -> ! {
|
|||||||
core::intrinsics::abort();
|
core::intrinsics::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[alloc_error_handler]
|
|
||||||
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
|
|
||||||
core::intrinsics::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
let world: Box<&str> = Box::new("Hello World!\0");
|
let world: Box<&str> = Box::new("Hello World!\0");
|
||||||
|
@ -6,7 +6,6 @@ use crate::prelude::*;
|
|||||||
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
|
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
|
||||||
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
|
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
|
||||||
use rustc_session::config::OomStrategy;
|
use rustc_session::config::OomStrategy;
|
||||||
use rustc_span::symbol::sym;
|
|
||||||
|
|
||||||
/// Returns whether an allocator shim was created
|
/// Returns whether an allocator shim was created
|
||||||
pub(crate) fn codegen(
|
pub(crate) fn codegen(
|
||||||
@ -15,13 +14,7 @@ pub(crate) fn codegen(
|
|||||||
unwind_context: &mut UnwindContext,
|
unwind_context: &mut UnwindContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
|
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
|
||||||
codegen_inner(
|
codegen_inner(module, unwind_context, kind, tcx.sess.opts.unstable_opts.oom);
|
||||||
module,
|
|
||||||
unwind_context,
|
|
||||||
kind,
|
|
||||||
tcx.alloc_error_handler_kind(()).unwrap(),
|
|
||||||
tcx.sess.opts.unstable_opts.oom,
|
|
||||||
);
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +22,6 @@ fn codegen_inner(
|
|||||||
module: &mut impl Module,
|
module: &mut impl Module,
|
||||||
unwind_context: &mut UnwindContext,
|
unwind_context: &mut UnwindContext,
|
||||||
kind: AllocatorKind,
|
kind: AllocatorKind,
|
||||||
alloc_error_handler_kind: AllocatorKind,
|
|
||||||
oom_strategy: OomStrategy,
|
oom_strategy: OomStrategy,
|
||||||
) {
|
) {
|
||||||
let usize_ty = module.target_config().pointer_type();
|
let usize_ty = module.target_config().pointer_type();
|
||||||
@ -71,19 +63,6 @@ fn codegen_inner(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig = Signature {
|
|
||||||
call_conv: module.target_config().default_call_conv,
|
|
||||||
params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)],
|
|
||||||
returns: vec![],
|
|
||||||
};
|
|
||||||
crate::common::create_wrapper_function(
|
|
||||||
module,
|
|
||||||
unwind_context,
|
|
||||||
sig,
|
|
||||||
"__rust_alloc_error_handler",
|
|
||||||
&alloc_error_handler_kind.fn_name(sym::oom),
|
|
||||||
);
|
|
||||||
|
|
||||||
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
|
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
|
||||||
let mut data_ctx = DataContext::new();
|
let mut data_ctx = DataContext::new();
|
||||||
data_ctx.set_align(1);
|
data_ctx.set_align(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user