Repository navigation
fix(libc): emulate faulting BMI2 shifts on Windows - #3746
Closed
SuleimanKh97 wants to merge 1 commit into
Closed
SuleimanKh97 wants to merge 1 commit into
SuleimanKh97 wants to merge 1 commit into
Conversation
9 tasks done
9 tasks done
This was referenced Oct 11, 2026
Collaborator
|
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. |
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.
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 repository