hle/kernelx: harden null-arg, VirtualFreeEx, GetThreadName, and overflow paths #86
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/87"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by certified-retart on 2026-11-23T02:26:53Z.
Summary
Fixes several Win32/Xbox ABI edge cases and overflow hazards in
hle::kernelxand its downstreamgpu::umaallocation rounding:GetProcAddress/LoadLibraryEx{W,A}null-name handling:GetProcAddress(h, NULL)previously entered the(name as usize) >> 16 == 0ordinal branch as ordinal0. It now rejectsNULLwithERROR_INVALID_PARAMETER, matching real Win32GetProcAddresswhile leaving valid non-zero ordinal lookups intact.LoadLibraryExW/LoadLibraryExAwithLOAD_AS_DATAflags previously passed""intoload_as_datawhen given a null filename; they now fail withERROR_INVALID_PARAMETER.SetThreadName/GetThreadNameerror & buffer-sizing semantics:HRESULTfailures toSetLastErrorviahresult_to_win32.GetThreadNamenow rejectsbuf == NULL && len > 0withERROR_INVALID_PARAMETERand fails withFALSE+ERROR_INSUFFICIENT_BUFFER(while still populating*ret_len) wheneverbuf == NULLorlen <= n(no room for the NUL terminator), rather than silently truncating and returningTRUE.VirtualFree/VirtualFreeExsparse & graphics bookkeeping:VirtualFreeremoves an entry fromGRAPHICS_RESERVATIONSonly aftermem::VirtualFreesucceeds, preventing failedMEM_RELEASEcalls (e.g. non-zero size) from untracking live reservations.VirtualFreevalidates sparseMEM_RELEASE/MEM_DECOMMITflag exclusivity, rejects non-zeroMEM_RELEASEsize and out-of-range decommits before mutating sparse state, resolves zero-sizeMEM_DECOMMITat the reservation base to the full reservation, and propagates hostVirtualFreefailure.VirtualFreeExroutes current-process (GetCurrentProcess()) frees for sparse, UMA, and graphics reservations throughVirtualFreeso bookkeeping stays in sync without bypassing handle access checks on restricted process handles.XMemVirtualQueryprotection classification:PAGE_GUARDpages from the CPU-readable bitmask and includesPAGE_EXECUTE_WRITECOPY.kernelx+gpu::uma):aligned_heap_alloc,xmem_graphics_layout,AllocateTitlePhysicalPages,Uma::sparse_alloc, andUma::alloc_wherewith checked arithmetic so extreme sizes (includingusize::MAXandusize::MAX & !(GRAIN - 1)) fail cleanly withERROR_NOT_ENOUGH_MEMORYinstead of overflowing or panicking.Verification
cargo test -p xcl --lib hle::kernelx -- --test-threads=2: 11 passed; 0 failedget_proc_address_and_load_library_ex_reject_null_name(including Win32GetLastErrorparity and non-zero ordinal lookup),get_thread_name_sizing_truncation_and_errors,xmem_virtual_query_excludes_guard_pages,xmem_and_physical_page_overflows_fail_cleanly, andvirtual_free_ex_and_sparse_validation.cargo test -p xcl --lib gpu::uma -- --test-threads=2: 7 passed; 0 failedImported from ivall/xcl. Originally posted by ivall on 2026-11-23T10:48:03Z.
Merged. XDefiant (sparse reservations, VirtualFree-heavy) runs as before. Tested on Windows 11 with an RX 9070 (RDNA4):
cargo test --workspacegreen with the retail samples (shader pack, console DLLs, texture archive), lib tests also withXCL_SPLIT_WAVE64=1; Unicorn Overlord and XDefiant run with this round merged. Thanks!