Skip to content

Commit 4a53c8e

Browse files
committed
fixup! Move calling 'dump_on_crash' from each driver, to common VCpu, and move logic to its own module
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 9475fd6 commit 4a53c8e

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/hyperlight_host/src/hypervisor/crashdump.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,31 @@ use super::Hypervisor;
66
use crate::{new_error, Result};
77

88
/// Dump registers + memory regions + raw memory to a tempfile
9-
#[cfg(crashdump)]
109
pub(crate) fn crashdump_to_tempfile(hv: &dyn Hypervisor) -> Result<()> {
11-
let mem_regions = hv.get_memory_regions();
12-
let mem_size = mem_regions
13-
.iter()
14-
.map(|region| region.host_region.len())
15-
.sum();
16-
let mem_start_addr = mem_regions[0].host_region.start as *const u8;
17-
18-
if mem_start_addr.is_null() || mem_size == 0 {
19-
return Err(new_error!(
20-
"Invalid address or size while creating crashdump"
21-
));
22-
}
23-
2410
let mut temp_file = NamedTempFile::with_prefix("mem")?;
25-
2611
let hv_details = format!("{:#x?}", hv);
2712

28-
// write hypervisor details such as registers, memory regions, etc.
13+
// write hypervisor details such as registers, info about mapped memory regions, etc.
2914
temp_file.write_all(hv_details.as_bytes())?;
30-
// write memory dump
3115
temp_file.write_all(b"================ MEMORY DUMP =================\n")?;
32-
// SAFETY: Address and size non-null and non-zero
33-
unsafe {
34-
let slice = std::slice::from_raw_parts(mem_start_addr, mem_size);
35-
temp_file.write_all(slice)?;
36-
temp_file.flush()?;
16+
17+
// write the raw memory dump for each memory region
18+
for region in hv.get_memory_regions() {
19+
if region.host_region.start == 0 || region.host_region.is_empty() {
20+
continue;
21+
}
22+
// SAFETY: we got this memory region from the hypervisor so should never be invalid
23+
let region_slice = unsafe {
24+
std::slice::from_raw_parts(
25+
region.host_region.start as *const u8,
26+
region.host_region.len(),
27+
)
28+
};
29+
temp_file.write_all(region_slice)?;
3730
}
31+
temp_file.flush()?;
32+
33+
// persist the tempfile to disk
3834
let persist_path = temp_file.path().with_extension("dmp");
3935
temp_file
4036
.persist(&persist_path)

0 commit comments

Comments
 (0)