Intel CPUs: AMD-only CLZERO / MONITORX / MWAITX cause 0xC000001D (STATUS_ILLEGAL_INSTRUCTION) #184

Closed
opened 2026-11-26 04:14:14 +00:00 by github-bot · 3 comments
Owner

@⁠jrod0117-hub on GitHub · 2026-11-23 19:32 UTC · original

Summary

On an Intel CPU, a retail Xbox Series X|S (GDK) title dies with
0xC000001D (STATUS_ILLEGAL_INSTRUCTION) because the console code contains
AMD-only instructions that XCL passes through natively (by design, no CPU emulation):

Bytes Instruction Semantics Intel
0F 01 FC CLZERO zero the 64-byte cache line containing RAX #UD
0F 01 FA MONITORX arm the monitor #UD
0F 01 FB MWAITX wait for the monitor / timeout #UD

The title was compiled for Zen 2 (RSG-LLVM); it uses CLZERO in a 64-byte-stride
clear loop and MONITORX/MWAITX in spin-wait code.

Reproduction

  • CPU: Intel Core i9-14900HX, Windows 11 26300, RTX 4090 Laptop.
  • XCL built from main (cargo build --release -p xcl).
  • XCL_NETWORK=0 xcl run <game folder>.
  • Crash 1: 0xC000001D at game.exe+0x4e8aa70, bytes 0f 01 fc = clzero
    (verified against the exe on disk; minidump exception address matches).
  • With CLZERO emulated: the title gets from System Init to Game Init
    (6,960 CLZERO emulations), then crash 2 at game.exe+0x4fb0bd7,
    bytes 0f 01 fa = monitorx.

Fix (tested here)

A first-chance vectored exception handler in the host process. Only fires on #UD,
so there is no cost in normal execution. crates/xcl/src/eh.rs:

diff --git a/crates/xcl/src/eh.rs b/crates/xcl/src/eh.rs
index 0102a29..5e767f5 100644
--- a/crates/xcl/src/eh.rs
+++ b/crates/xcl/src/eh.rs
@@ -133,6 +133,56 @@ unsafe extern "system" fn hk_nt_terminate_process(h: isize, status: i32) -> i32
     orig(h, status)
 }
 
+/// AMD-only instructions that the Xbox (Zen 2) code uses and Intel CPUs raise #UD on:
+/// `CLZERO` (`0F 01 FC`), `MONITORX` (`0F 01 FA`), `MWAITX` (`0F 01 FB`). Emulate them so a
+/// console title runs natively on an Intel CPU.
+const STATUS_ILLEGAL_INSTRUCTION: u32 = 0xC000_001D;
+
+static AMD_EMULATED: [std::sync::atomic::AtomicU64; 3] =
+    [std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0)];
+
+unsafe extern "system" fn amd_insn_handler(info: *mut EXCEPTION_POINTERS) -> i32 {
+    use std::sync::atomic::Ordering;
+    use windows_sys::Win32::System::Diagnostics::Debug::{EXCEPTION_CONTINUE_EXECUTION, EXCEPTION_CONTINUE_SEARCH};
+    if info.is_null() {
+        return EXCEPTION_CONTINUE_SEARCH;
+    }
+    let info = &*info;
+    if info.ExceptionRecord.is_null() || info.ContextRecord.is_null() {
+        return EXCEPTION_CONTINUE_SEARCH;
+    }
+    if (*info.ExceptionRecord).ExceptionCode as u32 != STATUS_ILLEGAL_INSTRUCTION {
+        return EXCEPTION_CONTINUE_SEARCH;
+    }
+    let ctx = &mut *info.ContextRecord;
+    let rip = ctx.Rip as usize;
+    // the faulting code page was just executed, so it is mapped and readable
+    let code = std::slice::from_raw_parts(rip as *const u8, 3);
+    if code[0] != 0x0f || code[1] != 0x01 {
+        return EXCEPTION_CONTINUE_SEARCH;
+    }
+    let which = match code[2] {
+        0xfc => 0usize, // CLZERO: zero the 64-byte cache line containing RAX
+        0xfa => 1usize, // MONITORX: arm the monitor – no architectural effect we need
+        0xfb => 2usize, // MWAITX: wait for the monitor / timeout – the caller re-checks
+        _ => return EXCEPTION_CONTINUE_SEARCH,
+    };
+    if which == 0 {
+        let line = (ctx.Rax as usize) & !0x3f;
+        std::ptr::write_bytes(line as *mut u8, 0, 64);
+    } else if which == 2 {
+        // a no-op MWAITX turns the wait into a hot spin; back off a little
+        std::arch::x86_64::_mm_pause();
+    }
+    ctx.Rip = rip.wrapping_add(3) as u64;
+    let n = AMD_EMULATED[which].fetch_add(1, Ordering::Relaxed);
+    if n < 3 {
+        let name = ["CLZERO", "MONITORX", "MWAITX"][which];
+        crate::xlog_info!("emulated AMD {name} at {rip:#x} (Intel CPU)");
+    }
+    EXCEPTION_CONTINUE_EXECUTION
+}
+
 pub fn install_crash_handler() {
     unsafe {
         if let Err(e) = hooks::hook("ntdll.dll", "NtTerminateProcess", hk_nt_terminate_process as usize, &ORIG_NT_TERMINATE) {
@@ -140,6 +190,7 @@ pub fn install_crash_handler() {
         }
         SetUnhandledExceptionFilter(Some(unhandled_filter));
         install_invalid_parameter_handler();
+        windows_sys::Win32::System::Diagnostics::Debug::AddVectoredExceptionHandler(1, Some(amd_insn_handler));
         windows_sys::Win32::System::Diagnostics::Debug::AddVectoredExceptionHandler(0, Some(cpp_exception_logger));
     }
 }

Result

After both emulations the same title runs at a steady 30 fps (19,500+ frames
presented, 3840x2160 display target) on the Intel machine. No other #UD has appeared.

Notes / caveats

  • CLZERO must actually zero the line — a plain NOP would leave stale data.
  • MWAITX as a no-op turns the wait into a spin; _mm_pause() keeps it from pegging a core.
  • The handler reads 3 bytes at RIP; the page was just executed, so it is mapped.
  • Other AMD-only encodings (RDPRU 0F 01 FD, STGI/CLGI/SKINIT/INVLPGA 0F 01 DC-DF)
    are not handled yet.
  • This is a report from a user running a retail GDK title; no game files are included.
    Happy to turn it into a PR if you want the patch upstream.
**@⁠jrod0117-hub** on GitHub · 2026-11-23 19:32 UTC · [original](https://github.com/xcl-dev/xcl/issues/184) ## Summary On an **Intel** CPU, a retail Xbox Series X|S (GDK) title dies with `0xC000001D` (STATUS_ILLEGAL_INSTRUCTION) because the console code contains **AMD-only instructions** that XCL passes through natively (by design, no CPU emulation): | Bytes | Instruction | Semantics | Intel | |---|---|---|---| | `0F 01 FC` | `CLZERO` | zero the 64-byte cache line containing RAX | #UD | | `0F 01 FA` | `MONITORX` | arm the monitor | #UD | | `0F 01 FB` | `MWAITX` | wait for the monitor / timeout | #UD | The title was compiled for Zen 2 (RSG-LLVM); it uses `CLZERO` in a 64-byte-stride clear loop and `MONITORX`/`MWAITX` in spin-wait code. ## Reproduction - CPU: Intel Core i9-14900HX, Windows 11 26300, RTX 4090 Laptop. - XCL built from `main` (`cargo build --release -p xcl`). - `XCL_NETWORK=0 xcl run <game folder>`. - Crash 1: `0xC000001D` at `game.exe+0x4e8aa70`, bytes `0f 01 fc` = `clzero` (verified against the exe on disk; minidump exception address matches). - With CLZERO emulated: the title gets from `System Init` to `Game Init` (6,960 CLZERO emulations), then crash 2 at `game.exe+0x4fb0bd7`, bytes `0f 01 fa` = `monitorx`. ## Fix (tested here) A first-chance vectored exception handler in the host process. Only fires on #UD, so there is no cost in normal execution. `crates/xcl/src/eh.rs`: ```diff diff --git a/crates/xcl/src/eh.rs b/crates/xcl/src/eh.rs index 0102a29..5e767f5 100644 --- a/crates/xcl/src/eh.rs +++ b/crates/xcl/src/eh.rs @@ -133,6 +133,56 @@ unsafe extern "system" fn hk_nt_terminate_process(h: isize, status: i32) -> i32 orig(h, status) } +/// AMD-only instructions that the Xbox (Zen 2) code uses and Intel CPUs raise #UD on: +/// `CLZERO` (`0F 01 FC`), `MONITORX` (`0F 01 FA`), `MWAITX` (`0F 01 FB`). Emulate them so a +/// console title runs natively on an Intel CPU. +const STATUS_ILLEGAL_INSTRUCTION: u32 = 0xC000_001D; + +static AMD_EMULATED: [std::sync::atomic::AtomicU64; 3] = + [std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0)]; + +unsafe extern "system" fn amd_insn_handler(info: *mut EXCEPTION_POINTERS) -> i32 { + use std::sync::atomic::Ordering; + use windows_sys::Win32::System::Diagnostics::Debug::{EXCEPTION_CONTINUE_EXECUTION, EXCEPTION_CONTINUE_SEARCH}; + if info.is_null() { + return EXCEPTION_CONTINUE_SEARCH; + } + let info = &*info; + if info.ExceptionRecord.is_null() || info.ContextRecord.is_null() { + return EXCEPTION_CONTINUE_SEARCH; + } + if (*info.ExceptionRecord).ExceptionCode as u32 != STATUS_ILLEGAL_INSTRUCTION { + return EXCEPTION_CONTINUE_SEARCH; + } + let ctx = &mut *info.ContextRecord; + let rip = ctx.Rip as usize; + // the faulting code page was just executed, so it is mapped and readable + let code = std::slice::from_raw_parts(rip as *const u8, 3); + if code[0] != 0x0f || code[1] != 0x01 { + return EXCEPTION_CONTINUE_SEARCH; + } + let which = match code[2] { + 0xfc => 0usize, // CLZERO: zero the 64-byte cache line containing RAX + 0xfa => 1usize, // MONITORX: arm the monitor – no architectural effect we need + 0xfb => 2usize, // MWAITX: wait for the monitor / timeout – the caller re-checks + _ => return EXCEPTION_CONTINUE_SEARCH, + }; + if which == 0 { + let line = (ctx.Rax as usize) & !0x3f; + std::ptr::write_bytes(line as *mut u8, 0, 64); + } else if which == 2 { + // a no-op MWAITX turns the wait into a hot spin; back off a little + std::arch::x86_64::_mm_pause(); + } + ctx.Rip = rip.wrapping_add(3) as u64; + let n = AMD_EMULATED[which].fetch_add(1, Ordering::Relaxed); + if n < 3 { + let name = ["CLZERO", "MONITORX", "MWAITX"][which]; + crate::xlog_info!("emulated AMD {name} at {rip:#x} (Intel CPU)"); + } + EXCEPTION_CONTINUE_EXECUTION +} + pub fn install_crash_handler() { unsafe { if let Err(e) = hooks::hook("ntdll.dll", "NtTerminateProcess", hk_nt_terminate_process as usize, &ORIG_NT_TERMINATE) { @@ -140,6 +190,7 @@ pub fn install_crash_handler() { } SetUnhandledExceptionFilter(Some(unhandled_filter)); install_invalid_parameter_handler(); + windows_sys::Win32::System::Diagnostics::Debug::AddVectoredExceptionHandler(1, Some(amd_insn_handler)); windows_sys::Win32::System::Diagnostics::Debug::AddVectoredExceptionHandler(0, Some(cpp_exception_logger)); } } ``` ## Result After both emulations the same title runs at a steady **30 fps** (19,500+ frames presented, 3840x2160 display target) on the Intel machine. No other #UD has appeared. ## Notes / caveats - `CLZERO` must actually zero the line — a plain NOP would leave stale data. - `MWAITX` as a no-op turns the wait into a spin; `_mm_pause()` keeps it from pegging a core. - The handler reads 3 bytes at RIP; the page was just executed, so it is mapped. - Other AMD-only encodings (`RDPRU` `0F 01 FD`, `STGI/CLGI/SKINIT/INVLPGA` `0F 01 DC-DF`) are not handled yet. - This is a report from a user running a retail GDK title; no game files are included. Happy to turn it into a PR if you want the patch upstream.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:14 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 20:58 UTC · original

Fixed on main by #151 (merged in 2abc562): CLZERO, MONITORX / MWAITX and the other console instructions a PC CPU lacks are emulated in a vectored handler (insn.rs). Testers there went from this crash to exit 0 on an i9-14900K, i7-14700KF and i5-13600K. Please reopen if it still happens on current main.

**@⁠ivall** on GitHub · 2026-11-23 20:58 UTC · [original](https://github.com/xcl-dev/xcl/issues/184#issuecomment-7113812759) Fixed on main by #151 (merged in 2abc562): CLZERO, MONITORX / MWAITX and the other console instructions a PC CPU lacks are emulated in a vectored handler (`insn.rs`). Testers there went from this crash to exit 0 on an i9-14900K, i7-14700KF and i5-13600K. Please reopen if it still happens on current main.
Author
Owner

@⁠jrod0117-hub on GitHub · 2026-11-24 01:28 UTC · original

Real-run data (the called_stubs list from HANDOFF "Next steps 1")

Title: retail Xbox GDK build 1.0.2.1 (RockstarGamesInc.28872443D20A7)
Machine: Intel i9-14900HX, RTX 4090 Laptop 16 GB, Windows 11 26300
Backend: D3D12 real. Run ended normally (crash: null, exit 0), 30 fps, image still black (known mesh/AS limitation).

Shaders in this run: 4,624 unique / 219,509 submitted — stages as 599, cs 2,742, ps 108,317, vs 107,724, rootsig 127.
RDNA2: 16,634,641 instructions decoded, 0 undecoded, 0 Xbox errors.

called_stubs (calls × interface::slot, first caller):

calls stub first caller
6,316 ID3D12CommandAllocator::#9 (not on PC) game+0x188501
6,315 ID3D12GraphicsCommandList10::#126 (not on PC) game+0x3263e
6,315 ID3D12GraphicsCommandList10::#142 (not on PC) game+0x329e9
6,315 ID3D12GraphicsCommandList10::#75 (console extension) game+0x32820
179 XGTextureAddressComputer::#10 game+0x344287
16 ID3D12CommandQueue::#31 (newer layout) 0x0
4 ID3D12GraphicsCommandList10::#131 (not on PC) game+0x2478cba
4 ID3D12GraphicsCommandList10::#132 (not on PC) game+0x2478c99
2 #131 game+0x2478bc5
1 #132 game+0x2478ba4

Other counters: audio all zero (no voices yet — the title did not reach audio), VFS no writes/whiteouts.

The four high-count stubs (#9 allocator, #126/#142/#75 list) fire ~6,300× each in ~3 minutes of presenting — likely worth mapping next. #131/#132 and queue #31 match the slots already listed as open in HANDOFF.

No game files or links included; this is just the run report.

**@⁠jrod0117-hub** on GitHub · 2026-11-24 01:28 UTC · [original](https://github.com/xcl-dev/xcl/issues/184#issuecomment-7119135682) ## Real-run data (the `called_stubs` list from HANDOFF "Next steps 1") Title: retail Xbox GDK build `1.0.2.1` (RockstarGamesInc.28872443D20A7) Machine: Intel i9-14900HX, RTX 4090 Laptop 16 GB, Windows 11 26300 Backend: D3D12 **real**. Run ended normally (`crash: null`, exit 0), **30 fps**, image still black (known mesh/AS limitation). Shaders in this run: 4,624 unique / 219,509 submitted — stages `as` 599, `cs` 2,742, `ps` 108,317, `vs` 107,724, `rootsig` 127. RDNA2: 16,634,641 instructions decoded, **0 undecoded**, 0 Xbox errors. `called_stubs` (calls × interface::slot, first caller): | calls | stub | first caller | |---|---|---| | 6,316 | `ID3D12CommandAllocator::#9 (not on PC)` | game+0x188501 | | 6,315 | `ID3D12GraphicsCommandList10::#126 (not on PC)` | game+0x3263e | | 6,315 | `ID3D12GraphicsCommandList10::#142 (not on PC)` | game+0x329e9 | | 6,315 | `ID3D12GraphicsCommandList10::#75 (console extension)` | game+0x32820 | | 179 | `XGTextureAddressComputer::#10` | game+0x344287 | | 16 | `ID3D12CommandQueue::#31 (newer layout)` | 0x0 | | 4 | `ID3D12GraphicsCommandList10::#131 (not on PC)` | game+0x2478cba | | 4 | `ID3D12GraphicsCommandList10::#132 (not on PC)` | game+0x2478c99 | | 2 | `#131` | game+0x2478bc5 | | 1 | `#132` | game+0x2478ba4 | Other counters: audio all zero (no voices yet — the title did not reach audio), VFS no writes/whiteouts. The four high-count stubs (#9 allocator, #126/#142/#75 list) fire ~6,300× each in ~3 minutes of presenting — likely worth mapping next. #131/#132 and queue #31 match the slots already listed as open in HANDOFF. No game files or links included; this is just the run report.
Author
Owner

@⁠jrod0117-hub on GitHub · 2026-11-24 01:51 UTC · original

Follow-up: the console's mesh subobject is in slot 24, not 25

Instrumented a real run. The 5 mesh streams that were rejected carry these subobjects:

[0, 24, 2, 3, 4, 5, 8, 9, 10, 21, 17, 12, 14, 15, 16]
  • slot 24 payload = console bytecode (the MS container)
  • slot 25 = absent
  • no AS subobject at all

Current code looks for D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS (25) in translated_mesh_stream; not found → returns None → falls through to stream_pipeline / finish_pso with console bytecode → the driver rejects it with 0x80070057 (the "PSO stream rejected, the fallback version too" errors).

Local change that fixes the rejection:

// console: MS is slot 24 (PC enum: AS=24, MS=25); slot 25, when present, is the console AS
let ms_slot = if subs.iter().any(|s| s.0 == 25) { 25u32 } else { 24u32 };
let ms = subs.iter().find(|s| s.0 == ms_slot).and_then(|s| payload_shader(s.1))?;
if !is_console(ms) { return None; }
let as_slot = if ms_slot == 25 { 24 } else { 25 };

After it:

  • the 5 PSO stream rejected errors are gone;
  • no "mesh pipeline with AS … not supported yet" either (these streams have no AS);
  • draws report 4,096 draws with translated pipelines (0 skipped, 0 with PC pipelines).

Image is still black, but the title is still on a loading screen with ~2,200 pipelines queued, so this is not yet a picture claim — just the slot mapping. Patch available if you want it.

**@⁠jrod0117-hub** on GitHub · 2026-11-24 01:51 UTC · [original](https://github.com/xcl-dev/xcl/issues/184#issuecomment-7119508484) ## Follow-up: the console's mesh subobject is in slot 24, not 25 Instrumented a real run. The 5 mesh streams that were rejected carry these subobjects: ``` [0, 24, 2, 3, 4, 5, 8, 9, 10, 21, 17, 12, 14, 15, 16] ``` - slot **24** payload = console bytecode (the MS container) - slot **25** = absent - **no AS subobject at all** Current code looks for `D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS` (25) in `translated_mesh_stream`; not found → returns `None` → falls through to `stream_pipeline` / `finish_pso` with console bytecode → the driver rejects it with `0x80070057` (the "PSO stream rejected, the fallback version too" errors). Local change that fixes the rejection: ```rust // console: MS is slot 24 (PC enum: AS=24, MS=25); slot 25, when present, is the console AS let ms_slot = if subs.iter().any(|s| s.0 == 25) { 25u32 } else { 24u32 }; let ms = subs.iter().find(|s| s.0 == ms_slot).and_then(|s| payload_shader(s.1))?; if !is_console(ms) { return None; } let as_slot = if ms_slot == 25 { 24 } else { 25 }; ``` After it: - the 5 `PSO stream rejected` errors are **gone**; - no "mesh pipeline with AS … not supported yet" either (these streams have no AS); - draws report `4,096 draws with translated pipelines (0 skipped, 0 with PC pipelines)`. Image is still black, but the title is still on a loading screen with ~2,200 pipelines queued, so this is not yet a picture claim — just the slot mapping. Patch available if you want it.
This discussion has been locked. Commenting is limited to contributors.
No description provided.