gate dump-section reads on is_mapped; trim doc comments
Without the page-state guard, read_bulk faulted on PROT_NONE pages of the 4 GiB host reservation. Per-page is_mapped check skips uncommitted pages, leaving the buffer's leading zero bytes in place. Total LOC budget after trim: 70.
This commit is contained in:
@@ -221,11 +221,7 @@ enum Commands {
|
||||
/// `XENIA_MEM_WATCH`. Example: `--mem-watch=0x828F40B4`.
|
||||
#[arg(long)]
|
||||
mem_watch: Option<String>,
|
||||
/// Diagnostic. Dump a contiguous guest memory range to a file at
|
||||
/// end-of-run. Format: `BASE:LEN:PATH` (BASE/LEN hex or decimal).
|
||||
/// Example: `--dump-section=0x80000000:0x10000000:v80.bin`.
|
||||
/// Read via `GuestMemory::read_bulk`; uncommitted pages read as
|
||||
/// zero. Read-only; lockstep digest unaffected.
|
||||
/// `--dump-section=BASE:LEN:PATH` end-of-run guest memory snapshot.
|
||||
#[arg(long)]
|
||||
dump_section: Option<String>,
|
||||
},
|
||||
@@ -3265,17 +3261,24 @@ fn dump_thread_diagnostic(
|
||||
) {
|
||||
if let Some((base, len, ref path)) = kernel.dump_section {
|
||||
let mut buf = vec![0u8; len as usize];
|
||||
const CHUNK: usize = 4096;
|
||||
let mut off = 0usize;
|
||||
while off < buf.len() {
|
||||
let take = CHUNK.min(buf.len() - off);
|
||||
mem.read_bulk(base.wrapping_add(off as u32), &mut buf[off..off + take]);
|
||||
const CHUNK: u32 = 4096;
|
||||
let mut off: u32 = 0;
|
||||
let mut committed_pages = 0u32;
|
||||
while off < len {
|
||||
let take = CHUNK.min(len - off);
|
||||
let addr = base.wrapping_add(off);
|
||||
if mem.is_mapped(addr) {
|
||||
let s = off as usize;
|
||||
let e = s + take as usize;
|
||||
mem.read_bulk(addr, &mut buf[s..e]);
|
||||
committed_pages += 1;
|
||||
}
|
||||
off += take;
|
||||
}
|
||||
match std::fs::write(path, &buf) {
|
||||
Ok(()) => eprintln!(
|
||||
"dump-section: wrote {} bytes from {:#010x} to {}",
|
||||
buf.len(), base, path.display(),
|
||||
"dump-section: wrote {} bytes from {:#010x} ({} committed pages) to {}",
|
||||
buf.len(), base, committed_pages, path.display(),
|
||||
),
|
||||
Err(e) => eprintln!(
|
||||
"dump-section: failed to write {}: {e}",
|
||||
|
||||
Reference in New Issue
Block a user