Skip to content

Commit

Permalink
Make dump_ram_around_address unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
k-sareen committed Nov 29, 2024
1 parent eebe06e commit 6d3b1e0
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/util/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,26 @@ pub fn set_pattern(start: Address, pattern: usize, len: usize) {
/// Dump RAM around a given address. Note that be careful when using this function as it may
/// segfault for unmapped memory. ONLY use it for locations that are KNOWN to be broken AND
/// allocated by MMTk.
pub fn dump_ram_around_address(addr: Address, bytes: usize) -> String {
///
/// # Safety
/// Extremely unsafe for arbitrary addresses since they may not have been mapped. Only use
/// this function for locations that are KNOWN to be broken AND allocated by MMTk.
pub unsafe fn dump_ram_around_address(addr: Address, bytes: usize) -> String {
let mut string: String = String::new();
let end_addr = (addr + bytes).to_ptr::<usize>();
let mut current = (addr - bytes).to_ptr::<usize>();
while current < end_addr {
unsafe {
if current == addr.to_ptr::<usize>() {
string.push_str(" | ");
} else {
string.push_str(" ");
}
let s = unsafe { current.read() };
#[cfg(target_pointer_width = "64")]
string.push_str(format!("{:#018x}", s).as_str());
#[cfg(target_pointer_width = "32")]
string.push_str(format!("{:#010x}", s).as_str());
current = current.add(1);
if current == addr.to_ptr::<usize>() {
string.push_str(" | ");
} else {
string.push(' ');
}
let s = current.read();
#[cfg(target_pointer_width = "64")]
string.push_str(format!("{:#018x}", s).as_str());
#[cfg(target_pointer_width = "32")]
string.push_str(format!("{:#010x}", s).as_str());
current = current.add(1);
}
string
}
Expand Down

0 comments on commit 6d3b1e0

Please sign in to comment.