Repository navigation
hle/kernelx: harden null-arg, VirtualFreeEx, GetThreadName, and overflow paths - #87
Merged
Merged
Conversation
ivall
added a commit
that referenced
this pull request
Nov 23, 2026
Collaborator
|
Merged. XDefiant (sparse reservations, VirtualFree-heavy) runs as before. Tested on Windows 11 with an RX 9070 (RDNA4): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 failed