Skip to content

Commit f96a8d4

Browse files
author
Kai Luo
committed
Enhance implementation
1 parent 7823bf1 commit f96a8d4

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/symbolize/gimli/libs_aix.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ use super::{Library, LibrarySegment, Vec};
66
pub(super) fn native_libraries() -> Vec<Library> {
77
let mut ret = Vec::new();
88
unsafe {
9-
const BUFFER_SIZE: usize = 4 << 20;
10-
let mut buffer = vec![0i8; BUFFER_SIZE];
11-
if libc::loadquery(libc::L_GETINFO, buffer.as_mut_ptr(), BUFFER_SIZE as u32) < 0 {
12-
panic!("loadquery failed");
9+
let mut buffer = vec![std::mem::zeroed::<libc::ld_info>(); 64];
10+
loop {
11+
if libc::loadquery(
12+
libc::L_GETINFO,
13+
buffer.as_mut_ptr() as *mut i8,
14+
(std::mem::size_of::<libc::ld_info>() * buffer.len()) as u32,
15+
) >= 0
16+
{
17+
break;
18+
} else {
19+
if std::io::Error::last_os_error().raw_os_error().unwrap() != libc::ENOMEM {
20+
return Vec::new();
21+
}
22+
buffer.resize(buffer.len() * 2, std::mem::zeroed::<libc::ld_info>());
23+
}
1324
}
1425
let mut current = buffer.as_ptr() as *mut libc::ld_info;
1526
loop {
@@ -30,7 +41,8 @@ pub(super) fn native_libraries() -> Vec<Library> {
3041
if (*current).ldinfo_next == 0 {
3142
break;
3243
}
33-
current = ((current as i64) + ((*current).ldinfo_next) as i64) as *mut libc::ld_info;
44+
current =
45+
(current as *mut i8).offset((*current).ldinfo_next as isize) as *mut libc::ld_info;
3446
}
3547
}
3648
return ret;

src/symbolize/gimli/xcoff.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
use super::{Context, Mapping, Path, Stash, Vec};
2-
use object::read::xcoff::XcoffFile64;
2+
use object::read::xcoff::{FileHeader, SectionHeader, SectionTable, XcoffFile};
33
use object::Object as _;
44
use object::ObjectSection as _;
55
use object::ObjectSymbol as _;
66

7+
#[cfg(target_pointer_width = "32")]
8+
type Xcoff = object::xcoff::FileHeader32;
9+
#[cfg(target_pointer_width = "64")]
10+
type Xcoff = object::xcoff::FileHeader64;
11+
712
impl Mapping {
813
pub fn new(path: &Path) -> Option<Mapping> {
914
let map = super::mmap(path)?;
@@ -21,12 +26,12 @@ struct ParsedSym<'a> {
2126

2227
pub struct Object<'a> {
2328
syms: Vec<ParsedSym<'a>>,
24-
file: XcoffFile64<'a>,
29+
file: XcoffFile<'a, Xcoff>,
2530
}
2631

2732
impl<'a> Object<'a> {
2833
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
29-
let file = XcoffFile64::parse(data).ok()?;
34+
let file = XcoffFile::parse(data).ok()?;
3035
let mut syms = file
3136
.symbols()
3237
.map(|sym| {

0 commit comments

Comments
 (0)