From f3029b2b4298c4207a326e98b032cae4bea4b539 Mon Sep 17 00:00:00 2001 From: Rui Pinheiro Date: Sat, 22 Sep 2018 15:45:55 +0100 Subject: [PATCH] Change Cell->RSX map/unmap notifications This allows for further flexibility on the RSX side, allowing us to fix some bugs and crashes in later commits. --- rpcs3/Emu/Memory/vm.cpp | 29 +++++++++++++++++------------ rpcs3/Emu/RSX/RSXThread.cpp | 9 ++++++++- rpcs3/Emu/RSX/RSXThread.h | 9 ++++++++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 2376385b6d..a58c74eede 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -292,6 +292,14 @@ namespace vm } } + // Notify rsx that range has become valid + // Note: This must be done *before* memory gets mapped while holding the vm lock, otherwise + // the RSX might try to invalidate memory that got unmapped and remapped + if (const auto rsxthr = fxm::check_unlocked()) + { + rsxthr->on_notify_memory_mapped(addr, size); + } + if (!shm) { utils::memory_protect(g_base_addr + addr, size, utils::protection::rw); @@ -413,6 +421,15 @@ namespace vm } } + // Notify rsx to invalidate range + // Note: This must be done *before* memory gets unmapped while holding the vm lock, otherwise + // the RSX might try to call VirtualProtect on memory that is already unmapped + if (const auto rsxthr = fxm::check_unlocked()) + { + rsxthr->on_notify_memory_unmapped(addr, size); + } + + // Actually unmap memory if (!shm) { utils::memory_protect(g_base_addr + addr, size, utils::protection::no); @@ -581,12 +598,6 @@ namespace vm m_common->unmap_critical(vm::base(addr)); } } - - // Notify rsx to invalidate range (TODO) - if (const auto rsxthr = fxm::check_unlocked()) - { - rsxthr->on_notify_memory_unmapped(addr, size); - } } u32 block_t::alloc(const u32 orig_size, u32 align, const std::shared_ptr* src) @@ -718,12 +729,6 @@ namespace vm m_map.erase(found); } - // Notify rsx to invalidate range (TODO) - if (const auto rsxthr = fxm::check_unlocked()) - { - rsxthr->on_notify_memory_unmapped(addr, result); - } - return result; } diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 5ae59f4630..9eba7b4e71 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "Emu/Memory/vm.h" #include "Emu/System.h" #include "Emu/IdManager.h" @@ -1382,6 +1382,7 @@ namespace rsx } } + //std::future thread::add_internal_task(std::function callback) //{ // std::lock_guard lock(m_mtx_task); @@ -2673,6 +2674,12 @@ namespace rsx check_zcull_status(false); } + void thread::on_notify_memory_mapped(u32 address, u32 size) + { + // TODO + } + + void thread::on_notify_memory_unmapped(u32 base_address, u32 size) { if (!m_rsx_thread_exiting && base_address < 0xC0000000) diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index 3700e27add..663ffaa51f 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -599,6 +599,13 @@ namespace rsx */ void write_inline_array_to_buffer(void *dst_buffer); + /** + * Notify that a section of memory has been mapped + * If there is a notify_memory_unmapped request on this range yet to be handled, + * handles it immediately. + */ + void on_notify_memory_mapped(u32 address_base, u32 size); + /** * Notify that a section of memory has been unmapped * Any data held in the defined range is discarded