-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com>
- Loading branch information
Showing
15 changed files
with
164 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::io::Write; | ||
|
||
use tempfile::NamedTempFile; | ||
|
||
use super::Hypervisor; | ||
use crate::{new_error, Result}; | ||
|
||
/// Dump registers + memory regions + raw memory to a tempfile | ||
#[cfg(crashdump)] | ||
pub(crate) fn crashdump_to_tempfile(hv: &dyn Hypervisor) -> Result<()> { | ||
let mem_regions = hv.get_memory_regions(); | ||
let mem_size = mem_regions | ||
.iter() | ||
.map(|region| region.host_region.len()) | ||
.sum(); | ||
let mem_start_addr = mem_regions[0].host_region.start as *const u8; | ||
|
||
if mem_start_addr.is_null() || mem_size == 0 { | ||
return Err(new_error!( | ||
"Invalid address or size while creating crashdump" | ||
)); | ||
} | ||
|
||
let mut temp_file = NamedTempFile::with_prefix("mem")?; | ||
|
||
let hv_details = format!("{:#x?}", hv); | ||
|
||
// write hypervisor details such as registers, memory regions, etc. | ||
temp_file.write_all(hv_details.as_bytes())?; | ||
// write memory dump | ||
temp_file.write_all(b"================ MEMORY DUMP =================\n")?; | ||
// SAFETY: Address and size non-null and non-zero | ||
unsafe { | ||
let slice = std::slice::from_raw_parts(mem_start_addr, mem_size); | ||
temp_file.write_all(slice)?; | ||
temp_file.flush()?; | ||
} | ||
let persist_path = temp_file.path().with_extension("dmp"); | ||
temp_file | ||
.persist(&persist_path) | ||
.map_err(|e| new_error!("Failed to persist crashdump file: {:?}", e))?; | ||
|
||
println!("Memory dumped to file: {:?}", persist_path); | ||
log::error!("Memory dumped to file: {:?}", persist_path); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.