Skip to content

Haiku: add support for finding libraries and mapping library segments #411

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

Merged
merged 1 commit into from
Mar 2, 2021
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exclude = ['crates/without_debuginfo', 'crates/macos_frames_test', 'crates/line-
cfg-if = "1.0"
rustc-demangle = "0.1.4"
backtrace-sys = { path = "crates/backtrace-sys", version = "0.1.35", optional = true, default_features = false }
libc = { version = "0.2.81", default-features = false }
libc = { version = "0.2.87", default-features = false }

# Optionally enable the ability to serialize a `Backtrace`, controlled through
# the `serialize-*` features below.
Expand Down
57 changes: 57 additions & 0 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cfg_if::cfg_if! {
target_os = "android",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos",
Expand Down Expand Up @@ -447,6 +448,62 @@ cfg_if::cfg_if! {

ret
}
} else if #[cfg(target_os = "haiku")] {
// Haiku implements the image_info struct and the get_next_image_info()
// functions to iterate through the loaded executable images. The
// image_info struct contains a pointer to the start of the .text
// section within the virtual address space, as well as the size of
// that section. All the read-only segments of the ELF-binary are in
// that part of the address space.

use mystd::os::unix::prelude::*;
use mystd::ffi::{OsStr, CStr};

mod elf;
use self::elf::Object;

fn native_libraries() -> Vec<Library> {
let mut libraries: Vec<Library> = Vec::new();

unsafe {
let mut info = mem::MaybeUninit::<libc::image_info>::zeroed();
let mut cookie: i32 = 0;
// Load the first image to get a valid info struct
let mut status = libc::get_next_image_info(
libc::B_CURRENT_TEAM,
&mut cookie,
info.as_mut_ptr(),
);
if status != libc::B_OK {
return libraries;
}
let mut info = info.assume_init();

while status == libc::B_OK {
let mut segments = Vec::new();
segments.push(LibrarySegment {
stated_virtual_memory_address: 0,
len: info.text_size as usize,
});

let bytes = CStr::from_ptr(info.name.as_ptr()).to_bytes();
let name = OsStr::from_bytes(bytes).to_owned();
libraries.push(Library{
name: name,
segments: segments,
bias: info.text as usize
});

status = libc::get_next_image_info(
libc::B_CURRENT_TEAM,
&mut cookie,
&mut info
);
}
}

libraries
}
} else {
// Everything else should use ELF, but doesn't know how to load native
// libraries.
Expand Down