KernelX: memory tracing keeps the caller's last error #223
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/226"
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 Kalmarv on 2026-11-23T21:22:20Z.
hle::kernelx::tests::xmem_and_physical_page_overflows_fail_cleanlyfails on main now and then (last error 203 where 8 is expected), now that CI runs the tests. The cause is in the code, not the test.Cause
trace_memreadsXCL_TRACE_MEMinto aOnceLockon its first call. With the variable unset,GetEnvironmentVariableWsets the thread's last error to 203 (ERROR_ENVVAR_NOT_FOUND).XMemAllocDefaultand theVirtualAllochooks trace after the call has set its error. So the first traced call in a process replaced its own error with 203:XMemAllocDefault(usize::MAX, 0)reported 203 instead ofERROR_NOT_ENOUGH_MEMORY. A title would see the same.The test fails whenever it is the process's first caller of
trace_mem. That happens every time when it runs alone, and in some runs of the whole module, depending on which test thread gets there first.Change
trace_memruns its body underkeep_last_error, a 6-line helper that saves the thread's last error and puts it back. That covers the first-call lookup and the logging.Tested
Windows 11, MSVC, debug, CPU only; no GPU device is created by these tests.
cargo test -p xcl --lib -- --exact hle::kernelx::tests::xmem_and_physical_page_overflows_fail_cleanly, 10 runs each: mainaf20b4bfails 10 of 10 (left: 203, right: 8); this branch (594f63a) passes 10 of 10.hle::kernelxwith the library test binary built from each commit, 30 runs each: mainaf20b4bfails 9 of 30, every time in this test with 203; this branch fails 0 of 30 (16 tests per run, including the new one).tracing_keeps_the_last_error. It setsERROR_NOT_ENOUGH_MEMORY, then checks that the error survives an unset-variable lookup underkeep_last_error, and atrace_memcall. It doesn't depend on test order. With the restore removed it fails with 203.Not tested
XCL_TRACE_MEMlookup (trace_mem_on, reached fromreserved_outsideafter a reservation), which can set 203 the same way. It merges with this branch without conflicts; wrapping that lookup inkeep_last_errortoo would cover it.AI use: Claude Code, Claude Opus 5.5.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T21:26:16Z.
Rebased on main
d4f17ca(adeac80). The only conflict was the test module, next to the affinity tests #221 added; both are kept.cargo test --release -p xcl --lib hle::kernelx -- --test-threads=1: 18 passed, includingtracing_keeps_the_last_errorandxmem_and_physical_page_overflows_fail_cleanly.🤖 Claude Opus 5.5
Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T21:31:58Z.
Merged into main (
0f34407) as594f63a, the head before your rebase - the rebased one has the same content (main and your head agree on every file it touches), so GitHub does not show it as merged; closing by hand. Checked on an RX 9070 (RDNA4):cargo build --workspace && cargo test --workspace -- --test-threads=4- 611 unit tests passed, 0 failed; the retail game still reaches its first menu at 30 fps.Pull request closed