fix(libc): emulate faulting BMI2 shifts on Windows #3746
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3746"
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 boykopovar/AnyPS5. Originally posted by SuleimanKh97 on 2026-10-11T16:19:18Z.
What
Addresses #3719. Sons of Sparta (PPSA28997) crashes in its guest libc with
STATUS_ILLEGAL_INSTRUCTIONat bytesc4 62 e9 f7 c0, which encodeshlx r8, rax, rdx. The logged inputs (rax = 1,rdx = 0x25) requirer8 = 0x2000000000while preserving flags.The Windows crash handler now emulates faulting SHLX, SHRX and SARX instructions on the saved thread context and resumes after the instruction. It supports 32-bit and 64-bit register operands and unprefixed 64-bit memory addressing, including SIB, signed displacements and RIP-relative operands. Unsupported encodings and failed memory reads leave the context untouched and continue through the existing fatal-reporting path.
Instruction semantics follow Intel SDM volume 2B, "SARX/SHLX/SHRX — Shift Without Affecting Flags". Known coverage and performance limits are recorded in TechnicalDebt.
Tested
Windows, MinGW-w64 GCC 15.2.0 (WinLibs x86_64-ucrt-posix-seh r7):
-std=c++20 -O2 -Wall -Wextra -Werror.-fsyntax-onlyand the same warning settings.python tools/check_conventions.py --base origin/mainpassed.git diff --checkpassed.Executable tests were not run: Windows Application Control blocks the assembler, and the bundled CMake also fails to start. No full library build or Sons of Sparta launch was performed. This PR remains a draft pending runtime validation.
Added a Windows CTest target, available in both full and relinker-only configurations. Tests cover the exact crash inputs, all register combinations, operand widths, masked shift counts, sign propagation, flags and unrelated-context preservation, memory addressing, truncation, unreadable memory, injected Windows exception recovery, and native BMI2 comparison when supported. These are authored tests, not reported passing runtime results.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (unsupported instructions retain fatal reporting; no silent stubs added).mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T07:47:46Z.
Closing now that #5705 is in: titles run natively, so a host CPU without BMI2 now stops at start-up with the CPU's name and the missing extensions. Emulating the faulting instructions would only cover the ones we trap, and the rest of a title's code is built for the same extensions. Thanks for digging into #3719.
Pull request closed