mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
vm: add map_self() method to utils::shm
Add complementary unmap_self() method. Move VirtualMemory to util/vm.hpp Minor associated include cleanup. Move asm.h to util/asm.hpp
This commit is contained in:
parent
b68bdafadc
commit
1c99a2e7fb
@ -5,7 +5,7 @@
|
||||
#include "util/logs.hpp"
|
||||
#include "mutex.h"
|
||||
#include "sysinfo.h"
|
||||
#include "VirtualMemory.h"
|
||||
#include "util/vm.hpp"
|
||||
#include <immintrin.h>
|
||||
#include <zlib.h>
|
||||
|
||||
|
@ -73,6 +73,7 @@
|
||||
#endif
|
||||
|
||||
#include "sync.h"
|
||||
#include "util/vm.hpp"
|
||||
#include "util/logs.hpp"
|
||||
#include "Emu/Memory/vm_locking.h"
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "mutex.h"
|
||||
#include "util/atomic.hpp"
|
||||
#include "util/typeindices.hpp"
|
||||
#include "VirtualMemory.h"
|
||||
#include <memory>
|
||||
|
||||
namespace utils
|
||||
|
@ -39,6 +39,7 @@ target_sources(rpcs3_emu PRIVATE
|
||||
../util/logs.cpp
|
||||
../util/yaml.cpp
|
||||
../util/cereal.cpp
|
||||
../util/vm_native.cpp
|
||||
../../Utilities/bin_patch.cpp
|
||||
../../Utilities/cheat_info.cpp
|
||||
../../Utilities/cond.cpp
|
||||
@ -54,7 +55,6 @@ target_sources(rpcs3_emu PRIVATE
|
||||
../../Utilities/sysinfo.cpp
|
||||
../../Utilities/Thread.cpp
|
||||
../../Utilities/version.cpp
|
||||
../../Utilities/VirtualMemory.cpp
|
||||
)
|
||||
|
||||
target_include_directories(rpcs3_emu PUBLIC "${CMAKE_SOURCE_DIR}")
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <unordered_set>
|
||||
#include "util/yaml.hpp"
|
||||
#include "Utilities/asm.h"
|
||||
#include "util/asm.hpp"
|
||||
|
||||
LOG_CHANNEL(ppu_validator);
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "Emu/Memory/vm_reservation.h"
|
||||
#include "Emu/system_config.h"
|
||||
#include "PPUThread.h"
|
||||
#include "Utilities/asm.h"
|
||||
#include "Utilities/sysinfo.h"
|
||||
#include "Emu/Cell/Common.h"
|
||||
|
||||
@ -12,6 +11,8 @@
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
#if !defined(_MSC_VER) && defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "Emu/Cell/PPUModule.h"
|
||||
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "Utilities/bin_patch.h"
|
||||
#include "Utilities/StrUtil.h"
|
||||
#include "Crypto/sha1.h"
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "stdafx.h"
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "Utilities/sysinfo.h"
|
||||
#include "Utilities/JIT.h"
|
||||
#include "Crypto/sha1.h"
|
||||
@ -64,7 +63,7 @@
|
||||
#include <thread>
|
||||
#include <cfenv>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include "util/vm.hpp"
|
||||
|
||||
const bool s_use_ssse3 = utils::has_ssse3();
|
||||
|
||||
|
@ -8,10 +8,11 @@
|
||||
#include "SPUThread.h"
|
||||
#include "SPUInterpreter.h"
|
||||
#include "Utilities/sysinfo.h"
|
||||
#include "Utilities/asm.h"
|
||||
#include "PPUAnalyser.h"
|
||||
#include "Crypto/sha1.h"
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
@ -3,10 +3,11 @@
|
||||
|
||||
#include "Utilities/JIT.h"
|
||||
#include "Utilities/sysinfo.h"
|
||||
#include "Utilities/asm.h"
|
||||
#include "SPUThread.h"
|
||||
#include "Emu/Cell/Common.h"
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <cfenv>
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "Utilities/JIT.h"
|
||||
#include "Utilities/asm.h"
|
||||
#include "Utilities/date_time.h"
|
||||
#include "Utilities/sysinfo.h"
|
||||
#include "Emu/Memory/vm.h"
|
||||
@ -31,6 +30,8 @@
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <shared_mutex>
|
||||
#include "util/vm.hpp"
|
||||
#include "util/asm.hpp"
|
||||
|
||||
using spu_rdata_t = decltype(spu_thread::rdata);
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
#include "stdafx.h"
|
||||
#include "sys_memory.h"
|
||||
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "Emu/Memory/vm_locking.h"
|
||||
#include "Emu/CPU/CPUThread.h"
|
||||
#include "Emu/Cell/ErrorCodes.h"
|
||||
#include "Emu/IdManager.h"
|
||||
|
||||
#include "util/vm.hpp"
|
||||
|
||||
LOG_CHANNEL(sys_memory);
|
||||
|
||||
//
|
||||
|
@ -5,11 +5,12 @@
|
||||
#include "sys_ppu_thread.h"
|
||||
#include "Emu/Cell/lv2/sys_event.h"
|
||||
#include "Emu/Memory/vm_var.h"
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "sys_memory.h"
|
||||
#include "sys_sync.h"
|
||||
#include "sys_process.h"
|
||||
|
||||
#include "util/vm.hpp"
|
||||
|
||||
LOG_CHANNEL(sys_mmapper);
|
||||
|
||||
lv2_memory::lv2_memory(u32 size, u32 align, u64 flags, lv2_memory_container* ct)
|
||||
|
@ -8,6 +8,11 @@
|
||||
|
||||
struct lv2_memory_container;
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class shm;
|
||||
}
|
||||
|
||||
struct lv2_memory : lv2_obj
|
||||
{
|
||||
static const u32 id_base = 0x08000000;
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
#include "Emu/system_config.h"
|
||||
#include "Emu/Cell/ErrorCodes.h"
|
||||
#include "Utilities/asm.h"
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "Utilities/mutex.h"
|
||||
#include "Utilities/Thread.h"
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "Utilities/address_range.h"
|
||||
#include "Emu/CPU/CPUThread.h"
|
||||
#include "Emu/Cell/lv2/sys_memory.h"
|
||||
@ -18,6 +17,9 @@
|
||||
#include <deque>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include "util/vm.hpp"
|
||||
#include "util/asm.hpp"
|
||||
|
||||
LOG_CHANNEL(vm_log, "VM");
|
||||
|
||||
namespace vm
|
||||
@ -301,9 +303,9 @@ namespace vm
|
||||
// Block or signal new range locks
|
||||
g_range_lock = addr | u64{size} << 32 | flags;
|
||||
|
||||
_mm_prefetch(g_range_lock_set + 0, _MM_HINT_T0);
|
||||
_mm_prefetch(g_range_lock_set + 2, _MM_HINT_T0);
|
||||
_mm_prefetch(g_range_lock_set + 4, _MM_HINT_T0);
|
||||
utils::prefetch_read(g_range_lock_set + 0);
|
||||
utils::prefetch_read(g_range_lock_set + 2);
|
||||
utils::prefetch_read(g_range_lock_set + 4);
|
||||
|
||||
const auto range = utils::address_range::start_length(addr, size);
|
||||
|
||||
@ -497,9 +499,9 @@ namespace vm
|
||||
|
||||
g_range_lock = addr | range_locked;
|
||||
|
||||
_mm_prefetch(g_range_lock_set + 0, _MM_HINT_T0);
|
||||
_mm_prefetch(g_range_lock_set + 2, _MM_HINT_T0);
|
||||
_mm_prefetch(g_range_lock_set + 4, _MM_HINT_T0);
|
||||
utils::prefetch_read(g_range_lock_set + 0);
|
||||
utils::prefetch_read(g_range_lock_set + 2);
|
||||
utils::prefetch_read(g_range_lock_set + 4);
|
||||
|
||||
const auto range = utils::address_range::start_length(addr, 128);
|
||||
|
||||
|
@ -3,10 +3,14 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "Utilities/types.h"
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "Utilities/StrFmt.h"
|
||||
#include "Utilities/BEType.h"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class shm;
|
||||
}
|
||||
|
||||
namespace vm
|
||||
{
|
||||
extern u8* const g_base_addr;
|
||||
|
@ -14,11 +14,12 @@
|
||||
#include "Overlays/overlay_perf_metrics.h"
|
||||
#include "Utilities/date_time.h"
|
||||
#include "Utilities/span.h"
|
||||
#include "Utilities/asm.h"
|
||||
#include "Utilities/StrUtil.h"
|
||||
|
||||
#include <cereal/archives/binary.hpp>
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "Utilities/VirtualMemory.h"
|
||||
#include "Utilities/hash.h"
|
||||
#include "Utilities/File.h"
|
||||
#include "Utilities/lockless.h"
|
||||
@ -15,6 +14,9 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
|
||||
#include "util/vm.hpp"
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
enum protection_policy
|
||||
|
@ -174,7 +174,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Utilities\Thread.cpp" />
|
||||
<ClCompile Include="..\Utilities\version.cpp" />
|
||||
<ClCompile Include="..\Utilities\VirtualMemory.cpp" />
|
||||
<ClCompile Include="util\vm_native.cpp" />
|
||||
<ClCompile Include="Emu\Cell\lv2\sys_config.cpp" />
|
||||
<ClCompile Include="Crypto\md5.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release - LLVM|x64'">NotUsing</PrecompiledHeader>
|
||||
@ -550,7 +550,8 @@
|
||||
<ClInclude Include="..\Utilities\Timer.h" />
|
||||
<ClInclude Include="..\Utilities\types.h" />
|
||||
<ClInclude Include="..\Utilities\version.h" />
|
||||
<ClInclude Include="..\Utilities\VirtualMemory.h" />
|
||||
<ClInclude Include="util\vm.hpp" />
|
||||
<ClInclude Include="util\asm.hpp" />
|
||||
<ClInclude Include="Crypto\aes.h" />
|
||||
<ClInclude Include="Crypto\aesni.h" />
|
||||
<ClInclude Include="Crypto\ec.h" />
|
||||
|
@ -188,7 +188,7 @@
|
||||
<ClCompile Include="Emu\RSX\Common\VertexProgramDecompiler.cpp">
|
||||
<Filter>Emu\GPU\RSX\Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Utilities\VirtualMemory.cpp">
|
||||
<ClCompile Include="util\vm_native.cpp">
|
||||
<Filter>Utilities</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Emu\Cell\SPURecompiler.cpp">
|
||||
@ -1165,7 +1165,10 @@
|
||||
<ClInclude Include="Emu\Cell\Common.h">
|
||||
<Filter>Emu\Cell</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Utilities\VirtualMemory.h">
|
||||
<ClInclude Include="util\vm.hpp">
|
||||
<Filter>Utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="util\asm.hpp">
|
||||
<Filter>Utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\Cell\SPUASMJITRecompiler.h">
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "Utilities/types.h"
|
||||
|
||||
extern bool g_use_rtm;
|
||||
extern u64 g_rtm_tx_limit1;
|
||||
@ -67,10 +67,17 @@ namespace utils
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Rotate helpers
|
||||
#if defined(__GNUG__)
|
||||
|
||||
inline void prefetch_read(const void* ptr)
|
||||
{
|
||||
#if __has_builtin(__builtin_prefetch)
|
||||
return __builtin_prefetch(ptr);
|
||||
#else
|
||||
__asm__ volatile ("prefetcht0 0(%[ptr])" : : [ptr] "r" (ptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
inline u8 rol8(u8 x, u8 n)
|
||||
{
|
||||
#if __has_builtin(__builtin_rotateleft8)
|
||||
@ -200,6 +207,11 @@ namespace utils
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
inline void prefetch_read(const void* ptr)
|
||||
{
|
||||
return _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0);
|
||||
}
|
||||
|
||||
inline u8 rol8(u8 x, u8 n)
|
||||
{
|
||||
return _rotl8(x, n);
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "Utilities/types.h"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
@ -49,6 +49,7 @@ namespace utils
|
||||
#endif
|
||||
u32 m_size;
|
||||
u32 m_flags;
|
||||
void* m_ptr;
|
||||
|
||||
public:
|
||||
explicit shm(u32 size, u32 flags = 0);
|
||||
@ -65,12 +66,24 @@ namespace utils
|
||||
// Map shared memory over reserved memory region, which is unsafe (non-atomic) under Win32
|
||||
u8* map_critical(void* ptr, protection prot = protection::rw);
|
||||
|
||||
// Map shared memory into its own storage (not mapped by default)
|
||||
u8* map_self(protection prot = protection::rw);
|
||||
|
||||
// Unmap shared memory
|
||||
void unmap(void* ptr) const;
|
||||
|
||||
// Unmap shared memory, undoing map_critical
|
||||
void unmap_critical(void* ptr);
|
||||
|
||||
// Unmap shared memory, undoing map_self()
|
||||
void unmap_self();
|
||||
|
||||
// Get memory mapped by map_self()
|
||||
u8* get() const
|
||||
{
|
||||
return reinterpret_cast<u8*>(m_ptr);
|
||||
}
|
||||
|
||||
u32 size() const
|
||||
{
|
||||
return m_size;
|
@ -1,6 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "util/logs.hpp"
|
||||
#include "VirtualMemory.h"
|
||||
#include "util/vm.hpp"
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
@ -183,6 +183,7 @@ namespace utils
|
||||
shm::shm(u32 size, u32 flags)
|
||||
: m_size(::align(size, 0x10000))
|
||||
, m_flags(flags)
|
||||
, m_ptr(0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
m_handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE, 0, m_size, NULL);
|
||||
@ -211,6 +212,8 @@ namespace utils
|
||||
|
||||
shm::~shm()
|
||||
{
|
||||
this->unmap_self();
|
||||
|
||||
#ifdef _WIN32
|
||||
::CloseHandle(m_handle);
|
||||
#else
|
||||
@ -284,6 +287,16 @@ namespace utils
|
||||
return this->map(target, prot);
|
||||
}
|
||||
|
||||
u8* shm::map_self(protection prot)
|
||||
{
|
||||
if (!m_ptr)
|
||||
{
|
||||
m_ptr = this->map(nullptr, prot);
|
||||
}
|
||||
|
||||
return static_cast<u8*>(m_ptr);
|
||||
}
|
||||
|
||||
void shm::unmap(void* ptr) const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -325,4 +338,13 @@ namespace utils
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void shm::unmap_self()
|
||||
{
|
||||
if (m_ptr)
|
||||
{
|
||||
this->unmap(m_ptr);
|
||||
m_ptr = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user