find_fde: make text_base optional

No platforms currently use relative addressing. Make this parameter
optional in order to support targets where this value is not available.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2023-08-05 20:44:54 +08:00 committed by Gary Guo
parent 1b30c6a79d
commit 2f9e374431

View File

@ -22,7 +22,7 @@ pub unsafe trait EhFrameFinder {
} }
pub struct FrameInfo { pub struct FrameInfo {
pub text_base: usize, pub text_base: Option<usize>,
pub kind: FrameInfoKind, pub kind: FrameInfoKind,
} }
@ -102,13 +102,14 @@ fn find_fde<T: EhFrameFinder + ?Sized>(eh_frame_finder: &T, pc: usize) -> Option
fn find_fde_with_eh_frame_hdr( fn find_fde_with_eh_frame_hdr(
pc: usize, pc: usize,
text_base: usize, text_base: Option<usize>,
eh_frame_hdr: usize, eh_frame_hdr: usize,
) -> Option<FDESearchResult> { ) -> Option<FDESearchResult> {
unsafe { unsafe {
let bases = BaseAddresses::default() let mut bases = BaseAddresses::default().set_eh_frame_hdr(eh_frame_hdr as _);
.set_text(text_base as _) if let Some(text_base) = text_base {
.set_eh_frame_hdr(eh_frame_hdr as _); bases = bases.set_text(text_base as _);
}
let eh_frame_hdr = EhFrameHdr::new( let eh_frame_hdr = EhFrameHdr::new(
get_unlimited_slice(eh_frame_hdr as usize as _), get_unlimited_slice(eh_frame_hdr as usize as _),
NativeEndian, NativeEndian,
@ -145,11 +146,16 @@ fn find_fde_with_eh_frame_hdr(
} }
} }
fn find_fde_with_eh_frame(pc: usize, text_base: usize, eh_frame: usize) -> Option<FDESearchResult> { fn find_fde_with_eh_frame(
pc: usize,
text_base: Option<usize>,
eh_frame: usize,
) -> Option<FDESearchResult> {
unsafe { unsafe {
let bases = BaseAddresses::default() let mut bases = BaseAddresses::default().set_eh_frame(eh_frame as _);
.set_text(text_base as _) if let Some(text_base) = text_base {
.set_eh_frame(eh_frame as _); bases = bases.set_text(text_base as _);
}
let eh_frame = EhFrame::new(get_unlimited_slice(eh_frame as _), NativeEndian); let eh_frame = EhFrame::new(get_unlimited_slice(eh_frame as _), NativeEndian);
if let Ok(fde) = eh_frame.fde_for_address(&bases, pc as _, EhFrame::cie_from_offset) { if let Ok(fde) = eh_frame.fde_for_address(&bases, pc as _, EhFrame::cie_from_offset) {