upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/xmem.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-27 06:21:29 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-27 06:21:29 -0500
commit23c33411962b84ecae28f4e82bd62fc6fba79444 (patch)
treeb9c960176efdf66a19b9a9f6d2547a76241ccd7d /runtime/shims/xmem.cpp
parentba32cd6acf9e6f5dfa2128ef53e05dec2cf34a38 (diff)
parent054cbe0f3d597395acdc459963721a3d160d207d (diff)
Merge branch 'test/round2' into heaps-in-place: heaps read in place under the mirror's B and C steps
With the mirror's steps B and C (title memory resolved to heap_base + its address, ordinary memory mirrored when a reader names it, the write-back of GPU stores from the homes, a separate bind flush), the in-place filter changes: - Lock order console_heap_mutex, then page_mirror.mutex, then slot_change_mutex. vsharp_address's mirror path takes the mirror's lock under console_heap_mutex now, so the filter, which runs inside the mirror's fills, takes no other lock of ours: the in-place heaps' filter state is under the mirror's lock (page_mirror.in_place), and the mirror's refresh no longer takes console_heap_mutex. Under the lock the filter does only reachability (arena, a buffer of ours, or the mirror through page_mirror_resolve_locked, which names ordinary memory as any reader does), nulls and the list of what is left: a V# the mirror does not hold and a T# to bind are finished in the heap's refresh (finish_in_place), outside the mirror's lock, and written into the home unless the title rewrote the slot since. The change list is taken under the mirror's lock when a heap is read in place, so the entries it has not read stay. - No write-back from a heap read in place: page_mirror_write_back skips filtered pages (TitleMirror::filtered_at), as their homes hold the filtered slots, not the title's bytes. - The heap's pages are named to the mirror when the heap is made (ordinary memory is mirrored then), after its filter range and its second binding are set. The binds go in flush_page_mirror's batch. d3d12_heap_in_place_test also checks that a GPU store into the heap's pages is not copied back over the title's bytes; title_mirror_hooks_test checks filtered_at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/xmem.cpp')
-rw-r--r--runtime/shims/xmem.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp
index 75b01546e..69a0b9b44 100644
--- a/runtime/shims/xmem.cpp
+++ b/runtime/shims/xmem.cpp
@@ -1049,7 +1049,7 @@ void* xmem_virtual_alloc(void* address, SIZE_T size, DWORD allocation_type, ULON
1049 // places it, as before). 1049 // places it, as before).
1050 const auto in_mirror_space = [&](auto&& reserve) -> void* { 1050 const auto in_mirror_space = [&](auto&& reserve) -> void* {
1051 void* made = nullptr; 1051 void* made = nullptr;
1052 leonida::title_mirror_space::take(size, base_granularity, [&](std::uint64_t at) { 1052 leonida::title_mirror_space::take(size, base_granularity, !(new_placeholder || window), [&](std::uint64_t at) {
1053 made = reserve(reinterpret_cast<void*>(static_cast<uintptr_t>(at))); 1053 made = reserve(reinterpret_cast<void*>(static_cast<uintptr_t>(at)));
1054 return made != nullptr; 1054 return made != nullptr;
1055 }); 1055 });
@@ -2404,8 +2404,21 @@ constexpr DWORD kMemTitle = 0x40000000;
2404LPVOID WINAPI TitleVirtualAlloc(LPVOID address, SIZE_T size, DWORD allocation_type, DWORD protect) { 2404LPVOID WINAPI TitleVirtualAlloc(LPVOID address, SIZE_T size, DWORD allocation_type, DWORD protect) {
2405 const DWORD type = allocation_type & ~(kMemGraphics | kMemTitle); 2405 const DWORD type = allocation_type & ~(kMemGraphics | kMemTitle);
2406 const DWORD host_prot = host_protect(protect); 2406 const DWORD host_prot = host_protect(protect);
2407 LPVOID result = 2407 LPVOID result = nullptr;
2408 reserve_watched(type, address, size, [&](DWORD t) { return VirtualAlloc(address, size, t, host_prot); }); 2408 // A reservation the host would place goes into the page mirror's range too (src/title_mirror_space.h), as an
2409 // XMemVirtualAlloc one does: a V# or pointer the title writes with its address reaches the mirror.
2410 if (!address && size && (type & (MEM_RESERVE | MEM_COMMIT)) && !(type & (MEM_PHYSICAL | MEM_LARGE_PAGES))) {
2411 SIZE_T rounded = 0;
2412 if (round_up_size(size, kXmemPageSize64k, rounded))
2413 leonida::title_mirror_space::take(rounded, kXmemPageSize64k, true, [&](std::uint64_t at) {
2414 void* const there = reinterpret_cast<void*>(static_cast<uintptr_t>(at));
2415 result = reserve_watched(type | MEM_RESERVE, there, size,
2416 [&](DWORD t) { return VirtualAlloc(there, size, t, host_prot); });
2417 return result != nullptr;
2418 });
2419 }
2420 if (!result)
2421 result = reserve_watched(type, address, size, [&](DWORD t) { return VirtualAlloc(address, size, t, host_prot); });
2409 if (result) { 2422 if (result) {
2410 leonida::title_memory_map::changed(result, size); 2423 leonida::title_memory_map::changed(result, size);
2411 leonida::title_va_aliases().add_title_memory(reinterpret_cast<uintptr_t>(result), size); 2424 leonida::title_va_aliases().add_title_memory(reinterpret_cast<uintptr_t>(result), size);