diff options
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index 19425e9cd..de99914d6 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -784,6 +784,47 @@ bool table_frame(std::uintptr_t page, leonida::title_frames::Frame& out) { | |||
| 784 | return true; | 784 | return true; |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | // Single-lock, zero-shared_ptr run_end over g_table_frames (src/title_frames.h). | ||
| 788 | std::uintptr_t table_frame_run_end(std::uintptr_t from, std::uintptr_t to, bool& is_backed) { | ||
| 789 | constexpr std::uintptr_t kPage = leonida::title_frames::kPage; | ||
| 790 | if (from >= to) { | ||
| 791 | is_backed = false; | ||
| 792 | return to; | ||
| 793 | } | ||
| 794 | AcquireSRWLockShared(&g_frame_lock); | ||
| 795 | const auto has = [](std::uintptr_t p) -> bool { | ||
| 796 | const auto it = g_table_frames.find(p); | ||
| 797 | return it != g_table_frames.end() && it->second.section && it->second.section->scratch; | ||
| 798 | }; | ||
| 799 | const std::uintptr_t first_page = from & ~(kPage - 1); | ||
| 800 | is_backed = has(first_page); | ||
| 801 | if (!is_backed && g_table_frames.empty()) { | ||
| 802 | ReleaseSRWLockShared(&g_frame_lock); | ||
| 803 | return to; | ||
| 804 | } | ||
| 805 | std::uintptr_t at = first_page + kPage; | ||
| 806 | while (at < to && at > from && has(at) == is_backed) at += kPage; | ||
| 807 | ReleaseSRWLockShared(&g_frame_lock); | ||
| 808 | return at < to && at > from ? at : to; | ||
| 809 | } | ||
| 810 | |||
| 811 | // Single-lock, zero-shared_ptr batch existence check over g_table_frames (src/title_frames.h). | ||
| 812 | void table_frame_backed_batch(const std::uintptr_t* pages, std::uint8_t* out_backed, std::size_t count) { | ||
| 813 | constexpr std::uintptr_t kPage = leonida::title_frames::kPage; | ||
| 814 | if (!count) return; | ||
| 815 | AcquireSRWLockShared(&g_frame_lock); | ||
| 816 | if (g_table_frames.empty()) { | ||
| 817 | ReleaseSRWLockShared(&g_frame_lock); | ||
| 818 | for (std::size_t k = 0; k < count; ++k) out_backed[k] = 0; | ||
| 819 | return; | ||
| 820 | } | ||
| 821 | for (std::size_t k = 0; k < count; ++k) { | ||
| 822 | const auto it = g_table_frames.find(pages[k] & ~(kPage - 1)); | ||
| 823 | out_backed[k] = (it != g_table_frames.end() && it->second.section && it->second.section->scratch) ? 1u : 0u; | ||
| 824 | } | ||
| 825 | ReleaseSRWLockShared(&g_frame_lock); | ||
| 826 | } | ||
| 827 | |||
| 787 | // Appends `value` in hex (with 0x) or decimal at `at`, which has room for it: no CRT, so no lock and no allocation. | 828 | // Appends `value` in hex (with 0x) or decimal at `at`, which has room for it: no CRT, so no lock and no allocation. |
| 788 | char* append_number(char* at, unsigned long long value, bool hex) { | 829 | char* append_number(char* at, unsigned long long value, bool hex) { |
| 789 | char digits[24]; | 830 | char digits[24]; |
| @@ -3126,7 +3167,9 @@ void attach_mirror_locked(void* context, leonida::title_frames::Feed feed) { | |||
| 3126 | [[maybe_unused]] const bool g_mirror_attach_set = (leonida::title_frames::attach_fn = &attach_mirror, true); | 3167 | [[maybe_unused]] const bool g_mirror_attach_set = (leonida::title_frames::attach_fn = &attach_mirror, true); |
| 3127 | 3168 | ||
| 3128 | [[maybe_unused]] const bool g_title_frames_set = | 3169 | [[maybe_unused]] const bool g_title_frames_set = |
| 3129 | (leonida::title_frames::set_lookup(&table_frame, &geometry_aliases), true); | 3170 | (leonida::title_frames::set_lookup(&table_frame, &geometry_aliases, &table_frame_run_end, |
| 3171 | &table_frame_backed_batch), | ||
| 3172 | true); | ||
| 3130 | 3173 | ||
| 3131 | void set_fault_race_hook(FaultRaceHook hook) { g_fault_race_hook.store(hook, std::memory_order_release); } | 3174 | void set_fault_race_hook(FaultRaceHook hook) { g_fault_race_hook.store(hook, std::memory_order_release); } |
| 3132 | 3175 | ||