diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 06:43:13 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 06:43:13 -0500 |
| commit | 924966e2fbde9ae0ac96dcd433803047505efa2f (patch) | |
| tree | c1a163dd8a38c0113c737ddaf005ffc34c312c8f /runtime/shims/xmem.cpp | |
| parent | f3bfc039b27e0a2a70994885a54a8602cbd24d43 (diff) | |
Adapt #622 to #1723: its arena and xmem writes become the list values' fallback
#1723's list values own list slots 71 to 74 of the lists they track and
hand 71/72 to the GPU-label path only for lists they do not track. This
keeps that, and keeps what #622 adds that #1723 lacks: landing a value
in the GPU address arena and on an xmem page the title's view refuses.
- LEONIDA_GPU_LABELS stays opt-in (`1`), as on main and in #1723.
- src/value_write_sink.h: one place for the two targets a host store
cannot reach, used by both writers. The device answers for the arena
(an address below its size that is not the title's memory, the rule
resolve_title_memory uses); xmem registers write_title_bytes for its
pages. Replaces #622's label-only sink and xmem's title_write_fn.
- The pump's land(): the arena is asked before any host store, so an
arena offset is never stored to as a host address; then
kernel_writes::store as before; then xmem's mapping when that store
faults. Counted as writes_arena and writes_title_pages.
- The arena refuses its reserved start (null region, zero page, quad
indices) and a write past its end, stores an aligned value in one
access, and is unregistered when its device goes.
- xmem's write_title_bytes stores an aligned value in one access.
- The label path keeps the same order for untracked lists.
Test, no game data: xbox_list_value_fallback. A tracked list's writes to
title memory land through the host store; to a default-heap buffer's
arena offset land in the arena (read back by a GPU copy); to the arena's
reserved start are dropped; to an xmem page the title made PAGE_NOACCESS
land through xmem's mapping. LEONIDA_GPU_LABELS=1 throughout, and no
write is handed to the label path. Without the arena step it fails at
line 168, without the xmem step at line 208 (llvmpipe and the iGPU).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index b472e58d5..40bc28f2a 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -48,6 +48,7 @@ | |||
| 48 | #include "../src/title_page_watch.h" | 48 | #include "../src/title_page_watch.h" |
| 49 | #include "../src/title_geometry_watch.h" | 49 | #include "../src/title_geometry_watch.h" |
| 50 | #include "../src/title_va_alias.h" | 50 | #include "../src/title_va_alias.h" |
| 51 | #include "../src/value_write_sink.h" | ||
| 51 | 52 | ||
| 52 | namespace { | 53 | namespace { |
| 53 | 54 | ||
| @@ -2681,16 +2682,25 @@ bool write_title_bytes(const void* address, const void* bytes, std::size_t size) | |||
| 2681 | std::size_t chunk = kPhysicalPageSize - offset; | 2682 | std::size_t chunk = kPhysicalPageSize - offset; |
| 2682 | if (chunk > size - done) chunk = size - done; | 2683 | if (chunk > size - done) chunk = size - done; |
| 2683 | std::uint8_t* const host = static_cast<std::uint8_t*>(pages[index].section->scratch) + pages[index].offset; | 2684 | std::uint8_t* const host = static_cast<std::uint8_t*>(pages[index].section->scratch) + pages[index].offset; |
| 2684 | std::memcpy(host + offset, static_cast<const std::uint8_t*>(bytes) + done, chunk); | 2685 | // An aligned value in one store, as kernel_writes::store makes it: a title thread polling the same physical |
| 2686 | // page through another view never reads half of it. | ||
| 2687 | if (chunk == size && size == 4 && !(offset & 3)) | ||
| 2688 | std::atomic_ref(*reinterpret_cast<std::uint32_t*>(host + offset)) | ||
| 2689 | .store(*static_cast<const std::uint32_t*>(bytes), std::memory_order_relaxed); | ||
| 2690 | else if (chunk == size && size == 8 && !(offset & 7)) | ||
| 2691 | std::atomic_ref(*reinterpret_cast<std::uint64_t*>(host + offset)) | ||
| 2692 | .store(*static_cast<const std::uint64_t*>(bytes), std::memory_order_relaxed); | ||
| 2693 | else | ||
| 2694 | std::memcpy(host + offset, static_cast<const std::uint8_t*>(bytes) + done, chunk); | ||
| 2685 | done += chunk; | 2695 | done += chunk; |
| 2686 | } | 2696 | } |
| 2687 | return true; | 2697 | return true; |
| 2688 | } | 2698 | } |
| 2689 | 2699 | ||
| 2690 | // The D3D12 layer calls this through a pointer (xmem.h), so that the D3D12 library does not have to link the xmem | 2700 | // The D3D12 layer calls this through leonida::value_sink (src/value_write_sink.h), so that the D3D12 library does not |
| 2691 | // shim into every consumer of that library. A process that links the shim gets the real write; one that does not | 2701 | // have to link the xmem shim into every consumer of that library. A process that links the shim gets the write; one |
| 2692 | // keeps the console's value writes dropped. | 2702 | // that does not drops a value write that its host store could not land. |
| 2693 | [[maybe_unused]] const bool g_title_write_set = (rt::xmem::title_write_fn = &write_title_bytes, true); | 2703 | [[maybe_unused]] const bool g_title_write_set = (leonida::value_sink::set_title_pages(&write_title_bytes), true); |
| 2694 | 2704 | ||
| 2695 | // The label target of an address in the pages the title maps: those pages are the title's memory, and the | 2705 | // The label target of an address in the pages the title maps: those pages are the title's memory, and the |
| 2696 | // console's value writes name them (src/gpu_label_memory.h). The region is tracked on demand, one per page, so | 2706 | // console's value writes name them (src/gpu_label_memory.h). The region is tracked on demand, one per page, so |