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:
1 parent
9f22d574bc
commit
8a475da9cf
9 files changed
+803
-32
No files matched your search
@@ -519,7 +519,7 @@ pub extern "C" fn _wfsopen(path: *const u16, mode: *const u16, share: i32) -> Fi
|
||||
// fail there instead of faulting into its handler; the title's
|
||||
// synchronous reads (title+0x313fc0) read straight into 4 KiB-aligned
|
||||
// destinations and retry a failed `ReadFile` forever. So the destination
|
||||
// is opened first.
|
||||
// is opened first, and not guarded again before the call is done.
|
||||
|
||||
pub extern "system" fn ReadFile(
|
||||
file: *mut c_void,
|
||||
@@ -528,15 +528,36 @@ pub extern "system" fn ReadFile(
|
||||
read: *mut u32,
|
||||
overlapped: *mut c_void,
|
||||
) -> i32 {
|
||||
victory_gpu::kernel_will_write(buffer as usize, len as usize);
|
||||
host!("kernel32.dll", "ReadFile": extern "system" fn(*mut c_void, *mut u8, u32, *mut u32, *mut c_void) -> i32)(
|
||||
let writing = victory_gpu::kernel_writing(buffer as usize, len as usize);
|
||||
let done = host!("kernel32.dll", "ReadFile": extern "system" fn(*mut c_void, *mut u8, u32, *mut u32, *mut c_void) -> i32)(
|
||||
file, buffer, len, read, overlapped,
|
||||
)
|
||||
);
|
||||
// The call's error is the title's to ask for.
|
||||
// SAFETY: plain calls.
|
||||
let error = unsafe { windows_sys::Win32::Foundation::GetLastError() };
|
||||
// shortcut: a read that goes on after the call (overlapped) is written
|
||||
// into pages the kernel has locked by now: it lands all the same, but a
|
||||
// refresh that guards its blocks before it does will not see it.
|
||||
if done == 0 && error == windows_sys::Win32::Foundation::ERROR_IO_PENDING {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| tracing::info!(len, "ReadFile: a read of the title's goes on after the call"));
|
||||
}
|
||||
if done == 0 && error == windows_sys::Win32::Foundation::ERROR_NOACCESS {
|
||||
static FAILED: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
let n = FAILED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
|
||||
if n.is_power_of_two() {
|
||||
tracing::warn!(n, buffer = format_args!("{buffer:p}"), len, "ReadFile: the title's buffer could not be written");
|
||||
}
|
||||
}
|
||||
drop(writing);
|
||||
// SAFETY: as above.
|
||||
unsafe { windows_sys::Win32::Foundation::SetLastError(error) };
|
||||
done
|
||||
}
|
||||
|
||||
/// The host CRT reads large requests straight into the caller's buffer.
|
||||
pub extern "C" fn fread(buffer: *mut u8, size: usize, count: usize, stream: File) -> usize {
|
||||
victory_gpu::kernel_will_write(buffer as usize, size.saturating_mul(count));
|
||||
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)(
|
||||
buffer, size, count, stream,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user