Repository navigation
Conversation
A table-driven dispatcher for STATUS_ILLEGAL_INSTRUCTION (cpu_ud_emulate), installed at startup only when the host CPU has no CLZERO. Unknown instructions and unwritable targets pass on untouched.
…EH; fix the startup message quoting
…n any emulated instruction is missing
# Conflicts: # runtime/README.md
svds12343
left a comment
There was a problem hiding this comment.
Independent native Windows review of 0604a58367c41e65b0b26727f140bebfd86aa1e4: all four CPU suites pass; one low-priority exception-metadata discrepancy found by comparison with native CLWB.
Windows 11 Pro N build 26200, Intel Core i7-12700K, MSVC 19.44.35230, Windows SDK 10.0.26100, CMake 4.4.5 / Ninja 1.13.2, RelWithDebInfo. CPU-only; GPU/driver not involved. CPUID reports CLWB present and CLZERO/MONITORX/SSE4a absent.
Validation:
- CMake build of
cpu_ud_emulate_test,cpu_ud_emulate_clwb_test,cpu_ud_monitorx_test,cpu_ud_insertq_test;ctest --test-dir runtime/build-review -R '^cpu_ud' --output-on-failure -V: 4/4 pass. Direct suite totals: CLWB 50/50, CLZERO 47/47, MONITORX 10/10, INSERTQ 67/67. - The four truncated-instruction checks and the complete-at-page-end check run and pass on Windows. CLWB's real-#UD path is skipped because this CPU executes it natively; INSERTQ's comparison with native SSE4a is skipped because this CPU lacks SSE4a.
- Negative control: the current CLWB test linked against the pre-fix implementation/header at
3b60f08cfails 14 of 50 checks. The PR implementation passes all 50. - A separate scratch program links the production
cpu_ud_emulate.cpp, executes hand-built CLWB instructions natively, captures Windows' exception record and CONTEXT, then gives the same context to the emulator as a synthetic #UD. Low unmapped addresses, PAGE_NOACCESS and decommitted pages agree on read AV classification, exact fault address and unchanged CONTEXT. READWRITE, READONLY, EXECUTE and EXECUTE_READ pages succeed in both paths. - A deterministic 20,000-encoding sweep (seed 7692; ModRM/SIB, disp8/disp32, RIP-relative and optional REX) produced 16,467 canonical-address AVs whose code, parameter count, access kind, fault address and preserved CONTEXT all matched. Another 243 noncanonical-address AVs differ only in the metadata described below; the remaining 3,290 executions did not fault and are not counted as emulator comparisons. Counts depend on the process's actual register values/address layout; the minimal reproductions below are fixed.
Finding, low priority: runtime/src/cpu_ud_emulate.cpp:187-188 funnels noncanonical addresses through the same fault_at(address, false) path as ordinary inaccessible memory. On this native Windows/Intel host:
| Hand-written instruction and operand | Native ExceptionInformation[0:2] | Emulator |
|---|---|---|
66 0F AE 31 (clwb [rcx]), RCX=0x0000800000000000 |
{0, 0xffffffffffffffff} |
{0, 0x0000800000000000} |
Same instruction, RCX=0xffff7fffffffffff |
{0, 0xffffffffffffffff} |
{0, 0xffff7fffffffffff} |
66 0F AE 34 0C (clwb [rsp+rcx]), RCX=0x0000800000000000 |
{3, 0} |
{0, effective_address} |
All raise STATUS_ACCESS_VIOLATION, with two parameters and RIP unchanged. The canonical control RCX=0xffffffffffffffff agrees in both paths. The random sweep's differences were 204 of the first kind and 39 of the RSP/RBP-based kind, with no other mismatches. Thus ordinary invalid accesses are fixed, but handlers inspecting exception parameters can still distinguish these malformed operands from native execution. This is a fidelity follow-up, not evidence of a valid-address regression; no retail occurrence was tested. The inline note marks the new branch.
Commands for the standard suites:
cmake -S runtime -B runtime/build-review -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build runtime/build-review --target cpu_ud_emulate_test cpu_ud_emulate_clwb_test cpu_ud_monitorx_test cpu_ud_insertq_test -j 8
ctest --test-dir runtime/build-review -R '^cpu_ud' --output-on-failure -V
The scratch oracle and negative control were built with cl /std:c++17 /W4 /EHsc /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX, linking the respective production source. They compile without warnings. The CMake build has one C4244 warning in the unchanged CLZERO test at line 215.
Scope: synthetic code and memory only; no game files, GPU tests, full-runtime suite or translator changes. FS/GS, guard-page and address-size-prefix limitations already documented by the author were not re-reported. Rechecked the coordination board and unchanged PR head before publishing. AI-assisted (Codex).
Claim: #7694 (comment)
| address += displacement; | ||
| } | ||
| MEMORY_BASIC_INFORMATION mbi{}; | ||
| if (!canonical(address) || VirtualQuery(reinterpret_cast<const void*>(address), &mbi, sizeof mbi) != sizeof mbi || |
There was a problem hiding this comment.
[P3] Preserve native fault metadata for noncanonical CLWB operands
This branch gives noncanonical operands the same {0, address} parameters as an ordinary read page fault. In a native Windows 11 / i7-12700K comparison, clwb [rcx] with RCX=0x0000800000000000 instead reports STATUS_ACCESS_VIOLATION with {0, UINT64_MAX}; clwb [rsp+rcx] with the same RCX reports {3, 0}. The emulator preserves the exception code and RIP but changes the parameters visible to subsequent handlers. Consider separating noncanonical faults from the VirtualQuery failures (and retaining the addressing form needed for the stack-based case), with native-oracle regressions. This affects already-invalid operands only; all canonical fault comparisons passed. See the review body for exact encodings and controls.
|
Tested
So the native #UD handler path is still untested on real hardware: Zen 3 has both CLWB and CLZERO. It needs a CPU AI-assisted: yes (Claude ran the build and tests; results checked by me). |
|
PASS with notes — but stack-bound. Tested head 0604a58 against main dde82f2: merges clean (tree be2dd8736). However, the heads of your three open bases — #7055 (e1a4764), #7096 (c96c285), #7098 (c011e26) — are all ancestors of this head (re-verified with merge-base at current heads), and none are in main (runtime/src/cpu_ud_emulate.cpp is absent; no CLWB/INSERTQ code anywhere on main). Merging this PR alone would land all three other PRs' contents at once — it should merge last, or the CLWB-delta commits (6b4ba67, 0604a58) rebase onto main once the bases land. The CLWB fix itself reviews well: fault-on-inaccessible-operand with CLZERO write faults preserved, Wine negative control 38/8 → 43/0, CI pending. C++ — not runnable here. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
What
Compute the CLWB memory operand and report an access violation for inaccessible memory, preserving CLZERO write faults. Segment overrides are ignored.
Stacked on #7055, #7096 and #7098.
Why
The emulator previously skipped invalid CLWB operands; native Windows hardware raised an access violation in the #7098 review. The read access classification follows the requested contract; that review did not report its access-type field.
Tested
AI-assisted.
@ItsNotRexed: an exe PR, as you asked.
Claim: #6910 (comment)
Known limits (from the review): a CLWB with an FS/GS override is skipped without the readability check (the segment base is not known to the emulator); a guard page is reported as a plain access violation (as for CLZERO in #7055, the CPU would raise STATUS_GUARD_PAGE_VIOLATION); the
67address-size prefix is not decoded. Stacked on #7055, #7096 and #7098.