1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Split Emu/Memory into more logical headers

- Add vm_locking.h and vm_reservation.h and move relevant functions
  and types to these headers.
- Change include order and make vm_ptr.h, vm_var.h and vm_ref.h headers
  usable invidually and them including vm.h instead of other way around
- Because usage of vm::ptr now requires including vm_ptr.h instead of
  vm.h updated multiple #includes
- Added additional #includes to vm_reservation.h and vm_locking to
  where vm::reservation_* and locking related functions are used
This commit is contained in:
Lassi Hämäläinen 2018-09-25 23:34:45 +03:00 committed by Ivan
parent 8e942eb50c
commit 499035512b
40 changed files with 160 additions and 104 deletions

View File

@ -1,6 +1,6 @@
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_locking.h"
#include "CPUThread.h"
#include "Emu/IdManager.h"
#include "Utilities/GDBDebugServer.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// Error codes
enum

View File

@ -1,6 +1,7 @@
#pragma once
#include "Utilities/BitField.h"
#include "Emu/Memory/vm_ptr.h"
enum
{

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// error codes
enum CellOskDialogError : u32

View File

@ -1,6 +1,6 @@
#pragma once
#pragma once
#include <Emu/Memory/vm_ptr.h>
// Return codes
enum CellSaveDataError : u32

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// Error codes
enum SceNpTrophyError : u32

View File

@ -1,4 +1,5 @@
#include "stdafx.h"
#include "Emu/Memory/vm_reservation.h"
#include "Emu/System.h"
#include "PPUThread.h"
#include "PPUInterpreter.h"

View File

@ -1,9 +1,10 @@
#pragma once
#pragma once
#include "PPUFunction.h"
#include "PPUCallback.h"
#include "ErrorCodes.h"
#include <typeinfo>
#include "Emu/Memory/vm_var.h"
// Helper function
constexpr const char* ppu_select_name(const char* name, u32 id)

View File

@ -3,7 +3,7 @@
#include "Utilities/sysinfo.h"
#include "Utilities/JIT.h"
#include "Crypto/sha1.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_reservation.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "PPUThread.h"

View File

@ -1,7 +1,8 @@
#pragma once
#include "../CPU/CPUThread.h"
#include "../Memory/vm.h"
#include "../Memory/vm_ref.h"
#include "../Memory/vm_ptr.h"
#include "Utilities/lockless.h"
enum class ppu_cmd : u32

View File

@ -1,7 +1,8 @@
#include "stdafx.h"
#include "Utilities/JIT.h"
#include "Utilities/sysinfo.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Memory/vm_reservation.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/PPUFunction.h"
#include "Emu/Cell/ErrorCodes.h"

View File

@ -1,5 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// Syscalls
error_code sys_dbg_read_process_memory(s32 pid, u32 address, u32 size, vm::ptr<void> data);

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// Open Flags

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/Memory/vm_ptr.h"
//Syscalls

View File

@ -1,5 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
enum : u64
{
SYS_GPIO_UNKNOWN_DEVICE_ID,

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Utilities/VirtualMemory.h"
#include "Emu/Memory/vm_locking.h"
#include "Emu/IdManager.h"
#include "sys_memory.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/IdManager.h"

View File

@ -2,6 +2,7 @@
#include "Emu/Cell/PPUThread.h"
#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_mmapper.h"

View File

@ -2,6 +2,7 @@
#include "sys_sync.h"
#include <vector>
#include "Emu/Memory/vm_ptr.h"
struct lv2_memory_container;

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Crypto/unself.h"

View File

@ -1,6 +1,7 @@
#pragma once
#include "sys_sync.h"
#include "Emu/Memory/vm_ptr.h"
class ppu_thread;

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Emu/Memory/vm.h"
#include "Utilities/types.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"

View File

@ -1,5 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// Process Local Object Type
enum : u32
{

View File

@ -1,5 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
struct RsxDriverInfo
{
be_t<u32> version_driver; // 0x0

View File

@ -4,7 +4,7 @@
#include "Utilities/sema.h"
#include "Utilities/cond.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_locking.h"
#include "Emu/CPU/CPUThread.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/IdManager.h"

View File

@ -1,5 +1,5 @@
#include "stdafx.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/System.h"
#include "Emu/Cell/ErrorCodes.h"

View File

@ -1,5 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// SysCalls
s32 sys_time_get_timezone(vm::ptr<s32> timezone, vm::ptr<s32> summertime);
s32 sys_time_get_current_time(vm::ptr<s64> sec, vm::ptr<s64> nsec);

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// TTY channels

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
// SysCalls

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/IdManager.h"
#include "sys_memory.h"

View File

@ -1,4 +1,10 @@
#include "stdafx.h"
#include "stdafx.h"
#include "vm_locking.h"
#include "vm_ptr.h"
#include "vm_ref.h"
#include "vm_reservation.h"
#include "vm_var.h"
#include "Emu/System.h"
#include "Utilities/mutex.h"
#include "Utilities/cond.h"

View File

@ -3,11 +3,11 @@
#include <map>
#include <functional>
#include <memory>
#include "Utilities/types.h"
#include "Utilities/Atomic.h"
#include "Utilities/VirtualMemory.h"
class shared_mutex;
class cpu_thread;
class shared_cond;
#include "Utilities/StrFmt.h"
#include "Utilities/BEType.h"
namespace vm
{
@ -18,6 +18,8 @@ namespace vm
extern u8* const g_reservations;
extern u8* const g_reservations2;
struct writer_lock;
enum memory_location_t : uint
{
main,
@ -48,79 +50,6 @@ namespace vm
// Address type
enum addr_t : u32 {};
extern shared_mutex g_mutex;
extern thread_local atomic_t<cpu_thread*>* g_tls_locked;
// Register reader
void passive_lock(cpu_thread& cpu);
atomic_t<u64>* passive_lock(const u32 begin, const u32 end);
// Unregister reader
void passive_unlock(cpu_thread& cpu);
// Unregister reader (foreign thread)
void cleanup_unlock(cpu_thread& cpu) noexcept;
// Optimization (set cpu_flag::memory)
void temporary_unlock(cpu_thread& cpu) noexcept;
void temporary_unlock() noexcept;
class reader_lock final
{
bool m_upgraded = false;
public:
reader_lock(const reader_lock&) = delete;
reader_lock& operator=(const reader_lock&) = delete;
reader_lock();
~reader_lock();
void upgrade();
};
struct writer_lock final
{
writer_lock(const writer_lock&) = delete;
writer_lock& operator=(const writer_lock&) = delete;
writer_lock(u32 addr = 0);
~writer_lock();
};
// Get reservation status for further atomic update: last update timestamp
inline atomic_t<u64>& reservation_acquire(u32 addr, u32 size)
{
// Access reservation info: stamp and the lock bit
return reinterpret_cast<atomic_t<u64>*>(g_reservations)[addr / 128];
}
// Update reservation status
inline void reservation_update(u32 addr, u32 size, bool lsb = false)
{
// Update reservation info with new timestamp
reservation_acquire(addr, size) += 128;
}
// Get reservation sync variable
inline shared_cond& reservation_notifier(u32 addr, u32 size)
{
return *reinterpret_cast<shared_cond*>(g_reservations2 + addr / 128 * 8);
}
void reservation_lock_internal(atomic_t<u64>&);
inline atomic_t<u64>& reservation_lock(u32 addr, u32 size)
{
auto& res = vm::reservation_acquire(addr, size);
if (UNLIKELY(atomic_storage<u64>::bts(res.raw(), 0)))
{
reservation_lock_internal(res);
}
return res;
}
// Change memory protection of specified memory region
bool page_protect(u32 addr, u32 size, u8 flags_test = 0, u8 flags_set = 0, u8 flags_clear = 0);
@ -172,11 +101,11 @@ namespace vm
// Get memory at specified address (if size = 0, addr assumed exact)
std::pair<u32, std::shared_ptr<utils::shm>> get(u32 addr, u32 size = 0);
// Internal
u32 imp_used(const vm::writer_lock&);
// Get allocated memory count
u32 used();
// Internal
u32 imp_used(const vm::writer_lock&);
};
// Create new memory block with specified parameters and return it
@ -343,4 +272,3 @@ namespace vm
void close();
}
#include "vm_var.h"

View File

@ -0,0 +1,48 @@
#pragma once
#include "vm.h"
class cpu_thread;
class shared_mutex;
namespace vm
{
extern shared_mutex g_mutex;
extern thread_local atomic_t<cpu_thread*>* g_tls_locked;
// Register reader
void passive_lock(cpu_thread& cpu);
atomic_t<u64>* passive_lock(const u32 begin, const u32 end);
// Unregister reader
void passive_unlock(cpu_thread& cpu);
// Unregister reader (foreign thread)
void cleanup_unlock(cpu_thread& cpu) noexcept;
// Optimization (set cpu_flag::memory)
void temporary_unlock(cpu_thread& cpu) noexcept;
void temporary_unlock() noexcept;
class reader_lock final
{
bool m_upgraded = false;
public:
reader_lock(const reader_lock&) = delete;
reader_lock& operator=(const reader_lock&) = delete;
reader_lock();
~reader_lock();
void upgrade();
};
struct writer_lock final
{
writer_lock(const writer_lock&) = delete;
writer_lock& operator=(const writer_lock&) = delete;
writer_lock(u32 addr = 0);
~writer_lock();
};
} // namespace vm

View File

@ -1,5 +1,6 @@
#pragma once
#include "Utilities/types.h"
#include "vm_ref.h"
class ppu_thread;

View File

@ -1,5 +1,9 @@
#pragma once
#include <type_traits>
#include "Utilities/BEType.h"
#include "vm.h"
namespace vm
{
template<typename T, typename AT>

View File

@ -0,0 +1,45 @@
#pragma once
#include "vm.h"
#include "Utilities/cond.h"
class notifier;
namespace vm
{
// Get reservation status for further atomic update: last update timestamp
inline atomic_t<u64>& reservation_acquire(u32 addr, u32 size)
{
// Access reservation info: stamp and the lock bit
return reinterpret_cast<atomic_t<u64>*>(g_reservations)[addr / 128];
}
// Update reservation status
inline void reservation_update(u32 addr, u32 size, bool lsb = false)
{
// Update reservation info with new timestamp
reservation_acquire(addr, size) += 128;
}
// Get reservation sync variable
inline shared_cond& reservation_notifier(u32 addr, u32 size)
{
return *reinterpret_cast<shared_cond*>(g_reservations2 + addr / 128 * 8);
}
void reservation_lock_internal(atomic_t<u64>&);
inline atomic_t<u64>& reservation_lock(u32 addr, u32 size)
{
auto& res = vm::reservation_acquire(addr, size);
if (UNLIKELY(atomic_storage<u64>::bts(res.raw(), 0)))
{
reservation_lock_internal(res);
}
return res;
}
} // namespace vm

View File

@ -1,6 +1,7 @@
#pragma once
#include "vm_ptr.h"
#include "Utilities/BEType.h"
namespace vm
{

View File

@ -1,6 +1,6 @@
#pragma once
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h"
#include "gcm_enums.h"
#include "gcm_printing.h"

View File

@ -1,7 +1,7 @@
#include "stdafx.h"
#include "stdafx.h"
#include "rsx_methods.h"
#include "RSXThread.h"
#include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_reservation.h"
#include "Emu/System.h"
#include "rsx_utils.h"
#include "rsx_decode.h"