Skip to content

Commit

Permalink
Merge pull request #32 from hermit-os/hermit-offset
Browse files Browse the repository at this point in the history
feat(frontend): add binary offset for hermit
  • Loading branch information
mkroening authored Mar 25, 2024
2 parents 6e30a47 + 0ef0191 commit a8ee6bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion rftrace-frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ repository = "https://github.com/tlambertz/rftrace"
crate-type = ['rlib']

[dependencies]
byteorder = "~1.3.2"
byteorder = "~1.3.2"
cfg-if = "1"
46 changes: 25 additions & 21 deletions rftrace-frontend/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,31 @@ pub fn dump_full_uftrace(events: &mut Events, out_dir: &str, binary_name: &str)

let mapfilename = format!("{}/sid-{}.map", out_dir, sid);
let mut mapfile = File::create(mapfilename)?;
if cfg!(target_os = "linux") {
// see uftrace's record_proc_maps(..)
// TODO: implement section-merging
println!(
" Creating (incorrect) ./sid-{}.map by copying /proc/self/maps",
sid
);
let mut procfile = File::open("/proc/self/maps")?;
io::copy(&mut procfile, &mut mapfile)?;
} else {
println!(" Creating ./sid-{}.map fake memory map file", sid);

writeln!(
mapfile,
"000000000000-ffffffffffff r-xp 00000000 00:00 0 {}",
binary_name
)?;
writeln!(
mapfile,
"ffffffffffff-ffffffffffff rw-p 00000000 00:00 0 [stack]"
)?;
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
// see uftrace's record_proc_maps(..)
// TODO: implement section-merging
println!(
" Creating (incorrect) ./sid-{}.map by copying /proc/self/maps",
sid
);
let mut procfile = File::open("/proc/self/maps")?;
io::copy(&mut procfile, &mut mapfile)?;
} else if #[cfg(target_os = "hermit")] {
extern "C" {
fn sys_image_start_addr() -> usize;
}

let addr = unsafe { sys_image_start_addr() };

writeln!(mapfile, "{addr:0>12x}-ffffffffffff r-xp 00000000 00:00 0 {binary_name}")?;
writeln!(mapfile, "ffffffffffff-ffffffffffff rw-p 00000000 00:00 0 [stack]")?;
} else {
println!(" Creating ./sid-{sid}.map fake memory map file");

writeln!(mapfile, "000000000000-ffffffffffff r-xp 00000000 00:00 0 {binary_name}")?;
writeln!(mapfile, "ffffffffffff-ffffffffffff rw-p 00000000 00:00 0 [stack]")?;
}
}

if cfg!(target_os = "linux") {
Expand Down

0 comments on commit a8ee6bc

Please sign in to comment.