Kernel reads, remapped views, freed memory and lost writes of title memory

- What the kernel is writing (file reads) is not guarded by a refresh before
  the call is done (`kernel_writing`): the read would have failed.
- A title thread that uses a page while the runtime remaps another page of
  the same view waits for that in the fault handler; it faulted on a page
  the title never gave up.
- Blocks being unmapped are not guarded again, memory the title frees leaves
  no notes of its blocks (its VirtualFree is taken over), and other memory at
  an address once guarded or absent keeps its protection.
- The second part of a submission's one asking has a number of its own.
- What shaders wrote waits for a change of mapping instead of being lost;
  what could not be written is counted and said; zeros into title memory
  that went are no fault.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 23:10:44 -06:00
1 parent 338f42479e
commit 26d818c57f
9 files changed
+803 -32

No files matched your search

+37
View File
@@ -213,6 +213,43 @@ fn a_piece_lands_what_the_card_wrote_in_its_parts() {
}
}
/// A piece whose title memory is away only while the runtime changes a
/// mapping lands when that is done; where it stays away the copy's CPU side
/// takes the card's bytes (`take`) or not.
#[test]
fn a_piece_waits_for_a_change_of_mapping() {
use windows_sys::Win32::System::Memory::{MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_NOACCESS, VirtualAlloc, VirtualFree};
assert!(crate::safecopy::on());
// SAFETY: a reservation of ours, nothing of it committed.
let at = unsafe { VirtualAlloc(std::ptr::null(), BLOCK, MEM_RESERVE, PAGE_NOACCESS) } as usize;
assert_ne!(at, 0);
let now = [9u8; 100];
for take in [true, false] {
let mut held = [0u8; 100];
// SAFETY: arrays of 100 bytes.
let put = unsafe { piece(at, now.as_ptr(), held.as_mut_ptr(), &[(0, 100)], take, &mut Notes::default()) };
assert_eq!((put, held), (0, [if take { 9 } else { 0 }; 100]));
}
let (began, wait) = std::sync::mpsc::channel();
let change = std::thread::spawn(move || {
let _changing = crate::watch::title_memory_remapping();
began.send(()).unwrap();
std::thread::sleep(std::time::Duration::from_millis(50));
// SAFETY: the reservation's first page.
assert!(!unsafe { VirtualAlloc(at as _, PAGE, MEM_COMMIT, PAGE_READWRITE) }.is_null());
});
wait.recv().unwrap();
let mut held = [0u8; 100];
// SAFETY: as above.
let put = unsafe { piece(at, now.as_ptr(), held.as_mut_ptr(), &[(0, 100)], true, &mut Notes::default()) };
change.join().unwrap();
assert_eq!((put, held), (100, now));
// SAFETY: committed by now.
assert_eq!(unsafe { std::slice::from_raw_parts(at as *const u8, 100) }, now);
// SAFETY: our reservation.
unsafe { VirtualFree(at as _, 0, MEM_RELEASE) };
}
/// Landings on several threads beside title threads that write the same
/// blocks (other dwords) and a thread that refreshes a copy, guarding what
/// it takes: no write of the title's is lost or undone, all the card wrote