Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial libstd support #17

Merged
merged 2 commits into from
Aug 6, 2023
Merged
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ members = ["cdylib", "example"]
gimli = { version = "0.26.1", default-features = false, features = ["read-core"] }
libc = { version = "0.2", optional = true }
spin = { version = "0.9.8", optional = true, default-features = false, features = ["mutex", "spin_mutex"] }
core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }
compiler_builtins = { version = "0.1.2", optional = true }

[features]
alloc = []
Expand All @@ -36,6 +38,7 @@ panic-handler = ["print", "panic"]
panic-handler-dummy = []
system-alloc = []
default = ["unwinder", "dwarf-expr", "hide-trace", "fde-phdr-dl", "fde-registry"]
rustc-dep-of-std = ["core", "gimli/rustc-dep-of-std", "compiler_builtins"]

[profile.release]
debug = true
Expand Down
24 changes: 15 additions & 9 deletions src/unwinder/find_fde/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub unsafe trait EhFrameFinder {
}

pub struct FrameInfo {
pub text_base: usize,
pub text_base: Option<usize>,
pub kind: FrameInfoKind,
}

Expand Down Expand Up @@ -102,13 +102,14 @@ fn find_fde<T: EhFrameFinder + ?Sized>(eh_frame_finder: &T, pc: usize) -> Option

fn find_fde_with_eh_frame_hdr(
pc: usize,
text_base: usize,
text_base: Option<usize>,
eh_frame_hdr: usize,
) -> Option<FDESearchResult> {
unsafe {
let bases = BaseAddresses::default()
.set_text(text_base as _)
.set_eh_frame_hdr(eh_frame_hdr as _);
let mut bases = BaseAddresses::default().set_eh_frame_hdr(eh_frame_hdr as _);
if let Some(text_base) = text_base {
bases = bases.set_text(text_base as _);
}
let eh_frame_hdr = EhFrameHdr::new(
get_unlimited_slice(eh_frame_hdr as usize as _),
NativeEndian,
Expand Down Expand Up @@ -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 {
let bases = BaseAddresses::default()
.set_text(text_base as _)
.set_eh_frame(eh_frame as _);
let mut bases = BaseAddresses::default().set_eh_frame(eh_frame as _);
if let Some(text_base) = text_base {
bases = bases.set_text(text_base as _);
}
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) {
Expand Down