Emulate the AMD-only CLZERO instruction in the Windows crash handler #27524

Closed
opened 2026-11-26 16:21:06 +00:00 by akkadbakkad89 · 0 comments
akkadbakkad89 commented 2026-11-26 16:21:06 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-11-26T16:21:06Z.


CLZERO is an AMD-only cache instruction (0f 01 fc) that zeroes the 64-byte cache line containing the linear address in rax. Intel hosts raise STATUS_ILLEGAL_INSTRUCTION (0xc000001d) when a converted title executes it.

Observed with title PPSA38500 (see discussion #27523), which uses clzero; add rax, 0x40 loops for bulk memory zeroing. On an Intel host (i7-10700) the run dies in the crash reporter with CLZERO is an AMD-only instruction this CPU lacks: relink with --to-intel.

The suggested static path does not cover this binary: --to-intel conversion fails with Branch enters an AMD-only instruction (offset 0x22e111), because a branch target lands inside the instruction window the trampoline overwrite would relocate. Runtime-generated code is also out of scope for static conversion by design.

The crash handler already emulates the AMD-only SSE4a instructions EXTRQ/INSERTQ on the faulting thread's CONTEXT (core/libs/prx/libc/src/specifics/windows/Sse4aEmulation.hpp). CLZERO fits the same pattern: decode 0f 01 fc, zero (rax & ~63) .. +64, advance rip by 3, resume. A local implementation of exactly this boots the title past the fault.

Open questions for the implementation:

  • performance: bulk-zero loops execute CLZERO once per 64 bytes, so per-instruction fault handling is orders of magnitude slower than native. Whether that is acceptable in practice or needs a different mitigation (improved static conversion coverage) is worth deciding explicitly.
  • write faulting: the zeroing write can itself fault on guard/unmapped memory; the emulation runs inside the vectored handler so a nested fault must not corrupt the report path.
  • the existing emulation is Windows-only (specifies/windows); whether a Linux equivalent is needed is a separate question since the SSE4a machinery has no Linux counterpart either.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6630833068 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/27524). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-11-26T16:21:06Z. --- CLZERO is an AMD-only cache instruction (`0f 01 fc`) that zeroes the 64-byte cache line containing the linear address in `rax`. Intel hosts raise `STATUS_ILLEGAL_INSTRUCTION` (0xc000001d) when a converted title executes it. Observed with title PPSA38500 (see discussion #27523), which uses `clzero; add rax, 0x40` loops for bulk memory zeroing. On an Intel host (i7-10700) the run dies in the crash reporter with `CLZERO is an AMD-only instruction this CPU lacks: relink with --to-intel`. The suggested static path does not cover this binary: `--to-intel` conversion fails with `Branch enters an AMD-only instruction` (offset 0x22e111), because a branch target lands inside the instruction window the trampoline overwrite would relocate. Runtime-generated code is also out of scope for static conversion by design. The crash handler already emulates the AMD-only SSE4a instructions EXTRQ/INSERTQ on the faulting thread's CONTEXT (`core/libs/prx/libc/src/specifics/windows/Sse4aEmulation.hpp`). CLZERO fits the same pattern: decode `0f 01 fc`, zero `(rax & ~63) .. +64`, advance rip by 3, resume. A local implementation of exactly this boots the title past the fault. Open questions for the implementation: - performance: bulk-zero loops execute CLZERO once per 64 bytes, so per-instruction fault handling is orders of magnitude slower than native. Whether that is acceptable in practice or needs a different mitigation (improved static conversion coverage) is worth deciding explicitly. - write faulting: the zeroing write can itself fault on guard/unmapped memory; the emulation runs inside the vectored handler so a nested fault must not corrupt the report path. - the existing emulation is Windows-only (`specifies/windows`); whether a Linux equivalent is needed is a separate question since the SSE4a machinery has no Linux counterpart either.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#27524
No description provided.