mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:30:53 +01:00
[PR #1472] cpu_emulation: rewrite CLWB in place at its first #UD (RT-CLWB-PATCH) #1500
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1500
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1472
Author: @ImLele69
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:rt-clwb-patch📝 Commits (1)
85b8f5bcpu_emulation: rewrite CLWB in place at its first #UD (RT-CLWB-PATCH)📊 Changes
2 files changed (+46 additions, -0 deletions)
View changed files
📝
runtime/src/cpu_emulation.h(+35 -0)📝
runtime/test/cpu_emulation_test.cpp(+11 -0)📄 Description
Claimed in #14 as
RT-CLWB-PATCH.What and why
On a CPU without CLWB (Intel desktop before Ice Lake, AMD before Zen 2) every execution of CLWB raises #UD and the vectored handler in
cpu_emulation.hemulates it. The retail title's GPU upload worker flushes whole buffers with CLWB in a 64-byte loop (exe+0x532f1b0on 1.0.2.1), so each buffer costs one exception per cache line. Under Wine an exception costs tens of microseconds, and in thread snapshots (LEONIDA_STACKS) that worker sat in the same loop at 420, 540 and 660 s while the main thread polled its event (WaitForSingleObject(h, 0)in a 1 ms loop) in session0xd. The first-run pages never finished.The handler now rewrites the instruction at its first #UD:
66 0F AE /6(CLWB) becomes66 0F AE /7(CLFLUSHOPT): the same operand and length (only the ModRM reg field changes), and it also writes the line back (and then evicts it);66 0F 1F /0, a NOP of the same length that touches no memory.Each site then faults once.
LEONIDA_CLWB_PATCH=0keeps the per-execution emulation.Tested
cpu_emulation_testunder Wine 11.21 (Staging) on an i9-9900KF (no CLWB, has CLFLUSHOPT): all checks pass, including the new ones (both sites rewritten, SIB and displacement kept, the rewritten code runs again).0xdto0) into the story load. Without it, the same setup stays in0xd.No game data in the change or in this text.
AI-assisted: yes
🤖 Generated with Claude Code
https://claude.ai/code/session_01RBZntAmGCDe3LdLjbzZzuc
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.