Skip to content

Commit

Permalink
read/cfi: add FrameDescriptionEntry::end_address (#727)
Browse files Browse the repository at this point in the history
This provides consistent overflow handling.
  • Loading branch information
philipc authored Jun 28, 2024
1 parent e5c51f0 commit 11c6544
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ fn dump_eh_frame<R: Reader, W: Write>(
w,
" range_size: {:#018x} (end_addr = {:#018x})",
fde.len(),
fde.initial_address() + fde.len()
fde.end_address(),
)?;
if let Some(lsda) = fde.lsda() {
write!(w, " lsda: ")?;
Expand Down
16 changes: 11 additions & 5 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,14 @@ impl<R: Reader> FrameDescriptionEntry<R> {
self.initial_address
}

/// One more than the last address that this entry has unwind information for.
///
/// This uses wrapping arithmetic, so the result may be less than
/// `initial_address`.
pub fn end_address(&self) -> u64 {
self.initial_address.wrapping_add(self.address_range)
}

/// The number of bytes of instructions that this entry has unwind
/// information for.
pub fn len(&self) -> u64 {
Expand All @@ -1843,9 +1851,7 @@ impl<R: Reader> FrameDescriptionEntry<R> {
/// This is equivalent to `entry.initial_address() <= address <
/// entry.initial_address() + entry.len()`.
pub fn contains(&self, address: u64) -> bool {
let start = self.initial_address();
let end = start + self.len();
start <= address && address < end
self.initial_address() <= address && address < self.end_address()
}

/// The address of this FDE's language-specific data area (LSDA), if it has
Expand Down Expand Up @@ -2263,7 +2269,7 @@ where
code_alignment_factor: Wrapping(fde.cie().code_alignment_factor()),
data_alignment_factor: Wrapping(fde.cie().data_alignment_factor()),
next_start_address: fde.initial_address(),
last_end_address: fde.initial_address().wrapping_add(fde.len()),
last_end_address: fde.end_address(),
returned_last_row: false,
current_row_valid: false,
instructions: fde.instructions(section, bases),
Expand Down Expand Up @@ -6439,7 +6445,7 @@ mod tests {
*unwind_info,
UnwindTableRow {
start_address: fde1.initial_address() + 100,
end_address: fde1.initial_address() + fde1.len(),
end_address: fde1.end_address(),
saved_args_size: 0,
cfa: CfaRule::RegisterAndOffset {
register: Register(4),
Expand Down

0 comments on commit 11c6544

Please sign in to comment.