From fb5e7d15454fde835fff54a4b92e0746cb34ab9e Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Wed, 25 Nov 2026 23:50:37 -0800 Subject: [PATCH] D3D12.X: fall back when extended cache deletion is unavailable Some filesystems do not support FileDispositionInfoEx with POSIX semantics. Fall back to legacy delete-on-close using the same DELETE-open handle so rejection still invalidates the exact loaded blob generation rather than a path replacement. Assisted-by: Codex (GPT-5.6-sol) --- crates/xcl/src/hle/d3d12x/real.rs | 49 ++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 539204ff3a..912543a0b7 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -4982,25 +4982,43 @@ pub(crate) mod driver_cache { /// process's newer replacement. pub fn invalidate(self) -> bool { use windows_sys::Win32::Storage::FileSystem::{ - FileDispositionInfoEx, SetFileInformationByHandle, - FILE_DISPOSITION_FLAG_DELETE, FILE_DISPOSITION_FLAG_POSIX_SEMANTICS, - FILE_DISPOSITION_INFO_EX, + FileStandardInfo, GetFileInformationByHandleEx, SetFileInformationByHandle, + FILE_STANDARD_INFO, }; let Some(file) = self.file else { return false }; let handle = file.as_raw_handle() as windows_sys::Win32::Foundation::HANDLE; - let ex = FILE_DISPOSITION_INFO_EX { Flags: FILE_DISPOSITION_FLAG_DELETE | FILE_DISPOSITION_FLAG_POSIX_SEMANTICS }; let _stall = crate::stall::span(crate::stall::StallKind::CacheIo); + if set_disposition_with(|class, info, size| unsafe { + SetFileInformationByHandle(handle, class, info, size) != 0 + }) { + return true; + } + let mut info = FILE_STANDARD_INFO::default(); unsafe { - SetFileInformationByHandle( - handle, - FileDispositionInfoEx, - (&ex as *const FILE_DISPOSITION_INFO_EX).cast(), - std::mem::size_of::() as u32, - ) != 0 + GetFileInformationByHandleEx( + handle, FileStandardInfo, (&mut info as *mut FILE_STANDARD_INFO).cast(), + std::mem::size_of_val(&info) as u32, + ) != 0 && info.DeletePending } } } + /// Prefer immediate POSIX unlinking, but filesystems which do not implement the extended + /// disposition class can still mark this exact open file object for deletion on close. + fn set_disposition_with(mut set: impl FnMut(i32, *const std::ffi::c_void, u32) -> bool) -> bool { + use windows_sys::Win32::Storage::FileSystem::{ + FileDispositionInfo, FileDispositionInfoEx, + FILE_DISPOSITION_FLAG_DELETE, FILE_DISPOSITION_FLAG_POSIX_SEMANTICS, + FILE_DISPOSITION_INFO, FILE_DISPOSITION_INFO_EX, + }; + let ex = FILE_DISPOSITION_INFO_EX { Flags: FILE_DISPOSITION_FLAG_DELETE | FILE_DISPOSITION_FLAG_POSIX_SEMANTICS }; + if set(FileDispositionInfoEx, (&ex as *const FILE_DISPOSITION_INFO_EX).cast(), std::mem::size_of_val(&ex) as u32) { + return true; + } + let basic = FILE_DISPOSITION_INFO { DeleteFile: true }; + set(FileDispositionInfo, (&basic as *const FILE_DISPOSITION_INFO).cast(), std::mem::size_of_val(&basic) as u32) + } + pub fn load(p: &Path) -> Option { use windows_sys::Win32::Foundation::GENERIC_READ; use windows_sys::Win32::Storage::FileSystem::{ @@ -5350,6 +5368,17 @@ pub(crate) mod driver_cache { assert!(!loaded.invalidate()); } + #[test] + fn unsupported_posix_disposition_falls_back_to_exact_handle_deletion() { + use windows_sys::Win32::Storage::FileSystem::{FileDispositionInfo, FileDispositionInfoEx}; + let mut classes = Vec::new(); + assert!(set_disposition_with(|class, _, _| { + classes.push(class); + class == FileDispositionInfo + })); + assert_eq!(classes, [FileDispositionInfoEx, FileDispositionInfo]); + } + #[test] fn a_cache_symlink_never_disposes_its_target() { use std::os::windows::fs::symlink_file;