aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorFernando Sahmkow <[email protected]>2024-01-31 14:31:13 +0100
committerFernando Sahmkow <[email protected]>2024-01-31 16:38:51 +0100
commitd57165df450e8a2fa811706758fb8ab352f623ae (patch)
treeeb8292e721409121f372e868d37ccb0426e90b42 /src
parent738e9a79a06c9d3955488022a1d3afd67bc5a11d (diff)
downloadyuzu-android-d57165df450e8a2fa811706758fb8ab352f623ae.tar.gz
yuzu-android-d57165df450e8a2fa811706758fb8ab352f623ae.zip
Device Memory Manager: ensure raster protection only within mapped device addresses.
Diffstat (limited to 'src')
-rw-r--r--src/core/device_memory_manager.inc40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/core/device_memory_manager.inc b/src/core/device_memory_manager.inc
index 7afe54949..b026f4220 100644
--- a/src/core/device_memory_manager.inc
+++ b/src/core/device_memory_manager.inc
@@ -519,18 +519,32 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE);
size_t page = addr >> Memory::YUZU_PAGEBITS;
auto [asid, base_vaddress] = ExtractCPUBacking(page);
- size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS;
auto* memory_device_inter = registered_processes[asid.id];
+ const auto release_pending = [&] {
+ if (uncache_bytes > 0) {
+ MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS,
+ uncache_bytes, false);
+ uncache_bytes = 0;
+ }
+ if (cache_bytes > 0) {
+ MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS,
+ cache_bytes, true);
+ cache_bytes = 0;
+ }
+ };
for (; page != page_end; ++page) {
CounterAtomicType& count = cached_pages->at(page >> subentries_shift).Count(page);
+ auto [asid_2, vpage] = ExtractCPUBacking(page);
+ vpage >>= Memory::YUZU_PAGEBITS;
- if (delta > 0) {
- ASSERT_MSG(count.load(std::memory_order::relaxed) < std::numeric_limits<CounterType>::max(),
- "Count may overflow!");
- } else if (delta < 0) {
- ASSERT_MSG(count.load(std::memory_order::relaxed) > 0, "Count may underflow!");
- } else {
- ASSERT_MSG(false, "Delta must be non-zero!");
+ if (vpage == 0) [[unlikely]] {
+ release_pending();
+ continue;
+ }
+
+ if (asid.id != asid_2.id) [[unlikely]] {
+ release_pending();
+ memory_device_inter = registered_processes[asid_2.id];
}
// Adds or subtracts 1, as count is a unsigned 8-bit value
@@ -557,16 +571,8 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
cache_bytes, true);
cache_bytes = 0;
}
- vpage++;
- }
- if (uncache_bytes > 0) {
- MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS,
- uncache_bytes, false);
- }
- if (cache_bytes > 0) {
- MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes,
- true);
}
+ release_pending();
}
} // namespace Core