|
@@ -210,7 +210,8 @@ fn open(g: &mut Guards, start: usize, end: usize) -> bool {
|
|
|
/// The runtime calls it (as `kernel_will_write`) before the title's kernel
|
|
/// The runtime calls it (as `kernel_will_write`) before the title's kernel
|
|
|
/// reads into its own memory.
|
|
/// reads into its own memory.
|
|
|
pub fn writing(at: usize, len: usize) {
|
|
pub fn writing(at: usize, len: usize) {
|
|
|
- open(&mut guards(), at, at + len);
|
|
|
|
|
|
|
+ // The length is the title's (`fread`'s size times count, saturated).
|
|
|
|
|
+ open(&mut guards(), at, at.saturating_add(len));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// The runtime mapped or unmapped title memory `[at, at + len)`: what it
|
|
/// The runtime mapped or unmapped title memory `[at, at + len)`: what it
|
|
@@ -219,7 +220,7 @@ pub fn title_memory_remapped(at: usize, len: usize) {
|
|
|
let mut g = guards();
|
|
let mut g = guards();
|
|
|
let blocks: Vec<usize> = g
|
|
let blocks: Vec<usize> = g
|
|
|
.protected
|
|
.protected
|
|
|
- .range(at / BLOCK..(at + len).div_ceil(BLOCK))
|
|
|
|
|
|
|
+ .range(at / BLOCK..at.saturating_add(len).div_ceil(BLOCK))
|
|
|
.copied()
|
|
.copied()
|
|
|
.collect();
|
|
.collect();
|
|
|
for block in blocks {
|
|
for block in blocks {
|
|
@@ -364,4 +365,14 @@ mod tests {
|
|
|
unsafe { UnmapViewOfFile(windows_sys::Win32::System::Memory::MEMORY_MAPPED_VIEW_ADDRESS { Value: view as *mut _ }) };
|
|
unsafe { UnmapViewOfFile(windows_sys::Win32::System::Memory::MEMORY_MAPPED_VIEW_ADDRESS { Value: view as *mut _ }) };
|
|
|
title_memory_remapped(view, 2 * BLOCK);
|
|
title_memory_remapped(view, 2 * BLOCK);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /// A write or mapping that runs past the end of the address space (a
|
|
|
|
|
+ /// title's `fread` with a huge count) covers up to the end; the sum used
|
|
|
|
|
+ /// to overflow. Up there no test has guarded blocks.
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn ranges_past_the_address_space_end_do_not_overflow() {
|
|
|
|
|
+ let top = usize::MAX - 16;
|
|
|
|
|
+ writing(top, PAGE);
|
|
|
|
|
+ title_memory_remapped(top, usize::MAX);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|