[PR #1717] [CLOSED] d3d12_vulkan: copy_guarded and hash_guarded catch page faults under clang-cl (RT-CLANG-EHA) #1731

Closed
opened 2026-11-26 21:18:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1717
Author: @ImLele69
Created: 11/25/2026
Status: ❌ Closed

Base: main ← Head: rt-clang-eha


📝 Commits (3)

  • 291a354 runtime: gta6rt builds with /EHa under clang-cl, so __try catches faults inside memcpy
  • 44e7d30 runtime: gta6rt_d3d12_com builds with /EHa under clang-cl too
  • 36612c9 d3d12_vulkan: copy_guarded and hash_guarded call their body through a volatile pointer instead of relying on /EHa

📊 Changes

1 file changed (+43 additions, -27 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+43 -27)

📄 Description

Claimed in the coordination issue as: RT-CLANG-EHA — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158385623

What and why

copy_guarded and hash_guarded (shims/d3d12_vulkan_device.cpp) read the title's memory inside __try/__except, so that a page the title unmaps between the check and the read comes back as false instead of killing the process. That holds under MSVC. Under clang-cl with /EHsc it does not: clang lowers memcpy to an intrinsic it treats as unable to throw, and loads inlined into the __try block (the hash, the MOVNTDQA path) are not covered either, so the __except never runs.

Seen on a clang-cl/xwin build under Wine 11.21 (Fedora 44, RTX 2070 SUPER), twice during the story load: a slot-133 shadow refresh copied a page xmem had just unmapped and the process died. Startup trace exception record: read of 0x7fe6bac60000 in ucrtbase.dll+0x171a6 (memcpy), region MEM_RESERVE/MEM_PRIVATE; with a linker map, the stack is copy_guarded < ShadowPages::refresh < the device's submission callback < VulkanQueue::execute_now < CommandQueue::ExecuteCommandLists.

Change

The bodies become noinline functions (copy_unguarded, hash_unguarded) that the guards call through a volatile function pointer inside the __try. clang-cl then sees a call it cannot prove nothrow and covers it. No build flag changes.

The first version of this PR added /EHa instead. That did not work: /EHa on gta6rt never reached these functions, which gta6rt_d3d12_com compiles, and /EHa on that library or on every source does not link with clang 20 (std::variant's trivial destructor is referenced but never emitted: 155 targets failed). Those commits are undone in this branch; the diff against main is only d3d12_vulkan_device.cpp.

Tested

  • A small program with the same toolchain (clang-cl 20, lld-link 20, xwin), /EHsc, under Wine 11.21: a fault from a MEM_RESERVE page is caught through the pointer call, both via memcpy and via a MOVNTDQA loop, and a copy from committed memory still succeeds. The same function with memcpy directly in the __try dies at the same ucrtbase.dll address as the game run.
  • Every target under runtime/ cross-builds (ninja -k 0, 0 failed) on main 3de22a190.
  • A boot of the retail 1.0.2.1 with this change (on top of other local changes, counts only) went past the point where the two earlier runs died in this copy; it then stopped on an unrelated abort, which I'm handling separately.

Other __try users (file_system.cpp, pe_loader.cpp, title_page_watch.h, startup_trace.h) may have the same limit under clang-cl; I have not changed or tested them here.

AI-assisted: yes (Claude Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1717 **Author:** [@ImLele69](https://github.com/ImLele69) **Created:** 11/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `rt-clang-eha` --- ### 📝 Commits (3) - [`291a354`](https://github.com/ubiquitarianism/leonida/commit/291a354b2ffd67f47f011ddae91fa4ae81bd219f) runtime: gta6rt builds with /EHa under clang-cl, so __try catches faults inside memcpy - [`44e7d30`](https://github.com/ubiquitarianism/leonida/commit/44e7d30e032e58272995dd92a7ef06de9683958d) runtime: gta6rt_d3d12_com builds with /EHa under clang-cl too - [`36612c9`](https://github.com/ubiquitarianism/leonida/commit/36612c984f0a099030166a88f1e8c67021702ddf) d3d12_vulkan: copy_guarded and hash_guarded call their body through a volatile pointer instead of relying on /EHa ### 📊 Changes **1 file changed** (+43 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+43 -27) </details> ### 📄 Description Claimed in the coordination issue as: RT-CLANG-EHA — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158385623 ### What and why `copy_guarded` and `hash_guarded` (`shims/d3d12_vulkan_device.cpp`) read the title's memory inside `__try`/`__except`, so that a page the title unmaps between the check and the read comes back as `false` instead of killing the process. That holds under MSVC. Under clang-cl with `/EHsc` it does not: clang lowers `memcpy` to an intrinsic it treats as unable to throw, and loads inlined into the `__try` block (the hash, the `MOVNTDQA` path) are not covered either, so the `__except` never runs. Seen on a clang-cl/xwin build under Wine 11.21 (Fedora 44, RTX 2070 SUPER), twice during the story load: a slot-133 shadow refresh copied a page xmem had just unmapped and the process died. Startup trace exception record: read of `0x7fe6bac60000` in `ucrtbase.dll+0x171a6` (memcpy), region `MEM_RESERVE`/`MEM_PRIVATE`; with a linker map, the stack is `copy_guarded` < `ShadowPages::refresh` < the device's submission callback < `VulkanQueue::execute_now` < `CommandQueue::ExecuteCommandLists`. ### Change The bodies become `noinline` functions (`copy_unguarded`, `hash_unguarded`) that the guards call through a `volatile` function pointer inside the `__try`. clang-cl then sees a call it cannot prove `nothrow` and covers it. No build flag changes. The first version of this PR added `/EHa` instead. That did not work: `/EHa` on `gta6rt` never reached these functions, which `gta6rt_d3d12_com` compiles, and `/EHa` on that library or on every source does not link with clang 20 (`std::variant`'s trivial destructor is referenced but never emitted: 155 targets failed). Those commits are undone in this branch; the diff against `main` is only `d3d12_vulkan_device.cpp`. ### Tested - A small program with the same toolchain (clang-cl 20, lld-link 20, xwin), `/EHsc`, under Wine 11.21: a fault from a `MEM_RESERVE` page is caught through the pointer call, both via `memcpy` and via a `MOVNTDQA` loop, and a copy from committed memory still succeeds. The same function with `memcpy` directly in the `__try` dies at the same `ucrtbase.dll` address as the game run. - Every target under `runtime/` cross-builds (`ninja -k 0`, 0 failed) on `main` `3de22a190`. - A boot of the retail 1.0.2.1 with this change (on top of other local changes, counts only) went past the point where the two earlier runs died in this copy; it then stopped on an unrelated abort, which I'm handling separately. Other `__try` users (`file_system.cpp`, `pe_loader.cpp`, `title_page_watch.h`, `startup_trace.h`) may have the same limit under clang-cl; I have not changed or tested them here. AI-assisted: yes (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:18:46 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1731
No description provided.