Merge fork main 8dd30ab: writes through one view of a page are seen at its other views
The fork's guard over every view of a physical page is kept on our own block bits, known holes, kernel writes and changing blocks; what both had, ours. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
c45d109380
23 files changed
+4164
-221
No files matched your search
@@ -555,7 +555,13 @@ pub extern "system" fn ReadFile(
|
||||
done
|
||||
}
|
||||
|
||||
/// The host CRT reads large requests straight into the caller's buffer.
|
||||
/// The host CRT reads large requests straight into the caller's buffer
|
||||
/// through the kernel, whose write fails on a guarded block instead of
|
||||
/// faulting into the guard. So the bytes are read beside, a chunk at a time
|
||||
/// (a caller may ask for far more than the file holds), and copied in from
|
||||
/// user mode, where a guarded block faults into the guard like the title's
|
||||
/// own writes. Returns the items read, as the CRT does; the bytes of a
|
||||
/// partial last item are copied too, as the CRT leaves them.
|
||||
pub extern "C" fn fread(buffer: *mut u8, size: usize, count: usize, stream: File) -> usize {
|
||||
let _writing = victory_gpu::kernel_writing(buffer as usize, size.saturating_mul(count));
|
||||
host!("ucrtbase.dll", "fread": extern "C" fn(*mut u8, usize, usize, File) -> usize)(
|
||||
@@ -772,6 +778,40 @@ mod tests {
|
||||
assert_eq!((&out, n), (b"0123456789", 10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fread_reads_beside_in_chunks() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("data.bin");
|
||||
// Over two chunks, and not a whole number of 3-byte items.
|
||||
let bytes: Vec<u8> = (0..(5 << 19) + 1).map(|i| (i * 7 + i / 251) as u8).collect();
|
||||
std::fs::write(&path, &bytes).unwrap();
|
||||
let fclose = host!("ucrtbase.dll", "fclose": extern "C" fn(File) -> i32);
|
||||
let open = || {
|
||||
let f = _wfopen(w(&path.to_string_lossy()).as_ptr(), w("rb").as_ptr());
|
||||
assert!(!f.is_null());
|
||||
f
|
||||
};
|
||||
|
||||
// Asked for far more than the file holds: the whole file, in items.
|
||||
let f = open();
|
||||
let mut out = vec![0xaau8; bytes.len() + 64];
|
||||
let items = fread(out.as_mut_ptr(), 3, out.len() / 3, f);
|
||||
assert_eq!(items, bytes.len() / 3);
|
||||
assert_eq!(&out[..bytes.len()], &bytes[..], "the partial last item's bytes too");
|
||||
assert!(out[bytes.len()..].iter().all(|&b| b == 0xaa), "nothing past what was read");
|
||||
fclose(f);
|
||||
|
||||
// Exact reads continue where the last one stopped.
|
||||
let f = open();
|
||||
let mut a = vec![0u8; 1000];
|
||||
let mut b = vec![0u8; (1 << 20) + 5];
|
||||
assert_eq!(fread(a.as_mut_ptr(), 1000, 1, f), 1);
|
||||
assert_eq!(fread(b.as_mut_ptr(), 1, b.len(), f), b.len());
|
||||
assert_eq!(a, bytes[..1000]);
|
||||
assert_eq!(b, bytes[1000..1000 + b.len()]);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
fn text(v: &[u16]) -> String {
|
||||
String::from_utf16_lossy(&v[..v.len() - 1])
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user