Similar to this:
|
let image = match File::parse(&code.mmap()[..]) { |
|
Ok(image) => image, |
|
Err(_) => return, |
|
}; |
|
|
|
let text_base = match image.sections().find(|s| s.kind() == SectionKind::Text) { |
|
Some(section) => match section.data() { |
|
Ok(data) => data.as_ptr() as usize, |
|
Err(_) => return, |
|
}, |
|
None => return, |
|
}; |
|
|
|
for sym in image.symbols() { |
|
if !sym.is_definition() { |
|
continue; |
|
} |
|
if sym.kind() != SymbolKind::Text { |
|
continue; |
|
} |
|
let address = sym.address(); |
|
let size = sym.size(); |
|
if address == 0 || size == 0 { |
|
continue; |
|
} |
|
if let Ok(name) = sym.name() { |
|
let addr = text_base + address as usize; |
|
profiler.load_single_trampoline(name, addr as *const u8, size as usize, pid, tid); |
|
} |
|
} |
Rather than via a bunch of random accessors on the module and its compiled code, which is very wordy and also repeated in a bunch of different places.
Similar to this:
wasmtime/crates/wasmtime/src/trampoline/func.rs
Lines 74 to 103 in 43ec481
Rather than via a bunch of random accessors on the module and its compiled code, which is very wordy and also repeated in a bunch of different places.