Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions library/std/src/sys/personality/dwarf/eh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ pub const DW_EH_PE_aligned: u8 = 0x50;
pub const DW_EH_PE_indirect: u8 = 0x80;

#[derive(Copy, Clone)]
pub struct EHContext<'a> {
pub ip: *const u8, // Current instruction pointer
pub func_start: *const u8, // Pointer to the current function
pub get_text_start: &'a dyn Fn() -> *const u8, // Get pointer to the code section
pub get_data_start: &'a dyn Fn() -> *const u8, // Get pointer to the data section
pub(crate) struct EHContext {
pub(crate) ip: *const u8, // Current instruction pointer
pub(crate) func_start: *const u8, // Pointer to the current function
pub(crate) raw_context: *mut unwind::_Unwind_Context,
}

/// Landing pad.
Expand All @@ -63,7 +62,7 @@ pub enum EHAction {
pub const USING_SJLJ_EXCEPTIONS: bool =
cfg!(all(target_vendor = "apple", not(target_os = "watchos"), target_arch = "arm"));

pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>) -> Result<EHAction, ()> {
pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext) -> Result<EHAction, ()> {
if lsda.is_null() {
return Ok(EHAction::None);
}
Expand Down Expand Up @@ -224,7 +223,7 @@ unsafe fn read_encoded_offset(reader: &mut DwarfReader, encoding: u8) -> Result<
/// [LSB-dwarf-ext]: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html
unsafe fn read_encoded_pointer(
reader: &mut DwarfReader,
context: &EHContext<'_>,
context: &EHContext,
encoding: u8,
) -> Result<*const u8, ()> {
if encoding == DW_EH_PE_omit {
Expand All @@ -241,8 +240,8 @@ unsafe fn read_encoded_pointer(
}
context.func_start
}
DW_EH_PE_textrel => (*context.get_text_start)(),
DW_EH_PE_datarel => (*context.get_data_start)(),
DW_EH_PE_textrel => unsafe { unwind::_Unwind_GetTextRelBase(context.raw_context) },
DW_EH_PE_datarel => unsafe { unwind::_Unwind_GetDataRelBase(context.raw_context) },
// aligned means the value is aligned to the size of a pointer
DW_EH_PE_aligned => {
reader.ptr = reader.ptr.with_addr(round_up(reader.ptr.addr(), size_of::<*const u8>())?);
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/personality/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ unsafe fn find_eh_action(context: *mut uw::_Unwind_Context) -> Result<EHAction,
// `ip = -1` has special meaning, so use wrapping sub to allow for that
ip: if ip_before_instr != 0 { ip } else { ip.wrapping_sub(1) },
func_start: uw::_Unwind_GetRegionStart(context),
get_text_start: &|| uw::_Unwind_GetTextRelBase(context),
get_data_start: &|| uw::_Unwind_GetDataRelBase(context),
raw_context: context,
};
eh::find_eh_action(lsda, &eh_context)
}
Expand Down
Loading