cpu: lower LAR, LSL, VERR, and VERW segment inspection instructions #2035
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2042"
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 R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T23:33:34Z.
Change
Add a bounded Windows x64 AOT lifter (
tools/cpu_seg_inspect_aot.py), source-built MASM fixture (tests/cpu/seg_inspect.asm,tests/cpu/seg_inspect.def), differential verification harness (tests/cpu/seg_inspect_check.py), and CTest registration (cpu_aot_seg_inspectinCMakeLists.txt) covering theIntegersegment inspection mnemonics fromdocs/coverage/x64_zen2.tsv:lar r16/r32/r64, r/m16(load access rights byte)lsl r16/r32/r64, r/m16(load segment limit)verr r/m16(verify segment for reading)verw r/m16(verify segment for writing)Key architectural semantics modeled for Windows x64 user-mode (
CPL=3) GDT descriptors:LAR/LSL: onZF=1,r16updates[15:0]preserving[63:16], whiler32/r64zero-extend the 32-bit result to 64 bits; onZF=0, all 64 bits of the destination remain untouched. OnlyZFis updated;CF,PF,SF, andOFare preserved. Architecturally undefinedLARbits[19:16](00FXFF00H) are masked (0x00F0FF00u) only on 32/64-bitLARwithZF=1.VERR/VERW: setsZF=1only for readable/writable user-mode GDT selectors (TI=0, non-null, present,S=1,DPL >= max(CPL, RPL)unless conforming code, and readable/writable type bits), leaving all other flags and GPRs untouched.m16selector loads execute unconditionally viavolatileload_always<std::uint16_t>()so/O2never eliminates faulting reads even when the result is discarded.CMOVE/CMOVNEzero-extendsdst[63:32]even when the condition is false.XOR/OR/ADD, and undefined GPR/flag reads.Verification
Tested on commit
88767ebc(Windows x64, MSVC 14.50,devDebug andrelease/O2):cmake --build --preset dev --target cpu_seg_inspect_original cpu_seg_inspect_original_lifted cpu_seg_inspect_altered cpu_seg_inspect_altered_liftedcmake --build --preset release --target cpu_seg_inspect_original cpu_seg_inspect_original_lifted cpu_seg_inspect_altered cpu_seg_inspect_altered_liftedctest --preset dev -R "^cpu_aot_seg_inspect$" --output-on-failure -V1/1 Test #648: cpu_aot_seg_inspect .............. Passed(unit rejections (6 raw + 21 IR), 7 PE-patched rejections, and CLI non-traceback rejections passed;seg_inspect passed: 2628 native, 2628 lifted, 2628 /O2 cases across 20 exports; ALTER_IMM diverged on {'verr_reg': 8, 'verw_reg': 8, 'verr_mem_disp': 8, 'verw_mem_disp': 8, 'seg_imm_select': 23, 'seg_flags_preserve': 23}). Capability skips: none (exits77on non-standard segment layouts).ctest --preset release -R "^cpu_aot_seg_inspect$" --output-on-failure1/1 Test #648: cpu_aot_seg_inspect .............. Passed.FORM_COVERAGE_RECORDoutput (out/build/dev/form_coverage/cpu_aot_seg_inspect.txtandrelease):add, cmove, lar, lsl, mov, ret, setb, sete, seto, setp, sets, verr, verw..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.pyform coverage checks passed(exit 0)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.pySelf-test passed. Checked 18 Markdown files and 391 links.(exit 0)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.pySelf-test passed. Checked 1404 tracked source, script and build/CI files: no bidirectional controls.(exit 0).Evidence and follow-up
tests/cpu/seg_inspect.asmandtests/cpu/seg_inspect.defare original, source-built synthetic MASM test fixtures under the repository MIT license; no external binaries or game files are used.ALTER_IMMmutant exports verifying divergence from the original, and aNULL-pointer faulting test for discardedm16reads under/O2.0x20..0x23,0x28..0x2B,0x30..0x33); hosts with non-standard segment layouts skip cleanly with exit code77.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:47:16Z.
I added the fixed GDT profile and reproduction command to the experiment documentation and CLI help. The Windows Release retest exercised 2,628 cases per native, lifted and /O2 variant, including selector mutations and rejection controls. I also corrected compiler-output decoding under a non-English locale. No skips in the local test.