Skip to content

Commit 4a20f96

Browse files
committed
Use u64 instead of usize or i64 for offsets
1 parent c8acc28 commit 4a20f96

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

src/symbolize/gimli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ struct Cache {
270270
struct Library {
271271
name: OsString,
272272
#[cfg(target_os = "android")]
273-
zip_offset: Option<i64>,
273+
zip_offset: Option<u64>,
274274
#[cfg(target_os = "aix")]
275275
/// On AIX, the library mmapped can be a member of a big-archive file.
276276
/// For example, with a big-archive named libfoo.a containing libbar.so,

src/symbolize/gimli/elf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl Mapping {
5050
/// `zip_offset` should be page-aligned; the dynamic linker
5151
/// requires this when it loads libraries.
5252
#[cfg(target_os = "android")]
53-
pub fn new_android(path: &Path, zip_offset: Option<i64>) -> Option<Mapping> {
54-
fn map_embedded_library(path: &Path, zip_offset: i64) -> Option<Mapping> {
53+
pub fn new_android(path: &Path, zip_offset: Option<u64>) -> Option<Mapping> {
54+
fn map_embedded_library(path: &Path, zip_offset: u64) -> Option<Mapping> {
5555
// get path of ZIP archive (delimited by `!/`)
5656
let raw_path = path.as_os_str().as_bytes();
5757
let zip_path = raw_path
@@ -61,12 +61,12 @@ impl Mapping {
6161
.map(|(index, _)| Path::new(OsStr::from_bytes(raw_path.split_at(index).0)))?;
6262

6363
let file = fs::File::open(zip_path).ok()?;
64-
let len: usize = file.metadata().ok()?.len().try_into().ok()?;
64+
let len = file.metadata().ok()?.len();
6565

6666
// NOTE: we map the remainder of the entire archive instead of just the library so we don't have to determine its length
6767
// NOTE: mmap will fail if `zip_offset` is not page-aligned
6868
let map = unsafe {
69-
super::mmap::Mmap::map(&file, len - usize::try_from(zip_offset).ok()?, zip_offset)
69+
super::mmap::Mmap::map(&file, usize::try_from(len - zip_offset).ok()?, zip_offset)
7070
}?;
7171

7272
Mapping::mk(map, |map, stash| {

src/symbolize/gimli/libs_dl_iterate_phdr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ unsafe extern "C" fn callback(
8585
}
8686
};
8787
#[cfg(target_os = "android")]
88-
let zip_offset: Option<i64> = {
88+
let zip_offset: Option<u64> = {
8989
// only check for ZIP-embedded file if we have data from /proc/self/maps
9090
maps.as_ref().and_then(|maps| {
9191
// check if file is embedded within a ZIP archive by searching for `!/`
@@ -96,7 +96,7 @@ unsafe extern "C" fn callback(
9696
// find MapsEntry matching library's base address
9797
maps.iter()
9898
.find(|m| m.ip_matches(dlpi_addr as usize))
99-
.and_then(|m| m.offset().try_into().ok())
99+
.and_then(|m| Some(m.offset()))
100100
})
101101
})
102102
};

src/symbolize/gimli/mmap_fake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ pub struct Mmap {
88
}
99

1010
impl Mmap {
11-
pub unsafe fn map(mut file: &File, len: usize, offset: i64) -> Option<Mmap> {
11+
pub unsafe fn map(mut file: &File, len: usize, offset: u64) -> Option<Mmap> {
1212
let mut mmap = Mmap {
1313
vec: Vec::with_capacity(len),
1414
};
15-
file.seek(SeekFrom::Start(offset.try_into().ok()?));
15+
file.seek(SeekFrom::Start(offset));
1616
file.read_to_end(&mut mmap.vec).ok()?;
1717
Some(mmap)
1818
}

src/symbolize/gimli/mmap_unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Mmap {
1515
}
1616

1717
impl Mmap {
18-
pub unsafe fn map(file: &File, len: usize, offset: i64) -> Option<Mmap> {
18+
pub unsafe fn map(file: &File, len: usize, offset: u64) -> Option<Mmap> {
1919
let ptr = mmap64(
2020
ptr::null_mut(),
2121
len,

src/symbolize/gimli/mmap_windows.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ pub struct Mmap {
1616
}
1717

1818
impl Mmap {
19-
pub unsafe fn map(file: &File, len: usize, offset: i64) -> Option<Mmap> {
20-
if offset.is_negative() {
21-
return None;
22-
}
19+
pub unsafe fn map(file: &File, len: usize, offset: u64) -> Option<Mmap> {
2320
let file = file.try_clone().ok()?;
2421
let mapping = CreateFileMappingA(
2522
file.as_raw_handle(),

src/symbolize/gimli/parse_running_mmaps_unix.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) struct MapsEntry {
2020
/// p = private (copy on write)
2121
perms: [char; 4],
2222
/// Offset into the file (or "whatever").
23-
offset: usize,
23+
offset: u64,
2424
/// device (major, minor)
2525
dev: (usize, usize),
2626
/// inode on the device. 0 indicates that no inode is associated with the memory region (e.g. uninitalized data aka BSS).
@@ -78,7 +78,7 @@ impl MapsEntry {
7878
}
7979

8080
#[cfg(target_os = "android")]
81-
pub(super) fn offset(&self) -> usize {
81+
pub(super) fn offset(&self) -> u64 {
8282
self.offset
8383
}
8484
}
@@ -123,6 +123,8 @@ impl FromStr for MapsEntry {
123123
let pathname_str = s.trim_start();
124124

125125
let hex = |s| usize::from_str_radix(s, 16).map_err(|_| "Couldn't parse hex number");
126+
let hex64 = |s| u64::from_str_radix(s, 16).map_err(|_| "Couldn't parse hex number");
127+
126128
let address = if let Some((start, limit)) = range_str.split_once('-') {
127129
(hex(start)?, hex(limit)?)
128130
} else {
@@ -137,7 +139,7 @@ impl FromStr for MapsEntry {
137139
}
138140
perms
139141
};
140-
let offset = hex(offset_str)?;
142+
let offset = hex64(offset_str)?;
141143
let dev = if let Some((major, minor)) = dev_str.split_once(':') {
142144
(hex(major)?, hex(minor)?)
143145
} else {

0 commit comments

Comments
 (0)