diff --git a/CMakeLists.txt b/CMakeLists.txt index 478d5901..34b07450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,8 @@ add_executable(shadps4 src/GUI/ElfViewer.h src/Util/Log.h src/Util/Log.cpp - src/Core/Memory.cpp - src/Core/Memory.h + "src/Core/virtual_memory.cpp" + "src/Core/virtual_memory.h" src/Core/PS4/Linker.cpp src/Core/PS4/Linker.h src/Lib/Threads.cpp diff --git a/src/Core/Memory.h b/src/Core/Memory.h deleted file mode 100644 index 00b9d2ba..00000000 --- a/src/Core/Memory.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "../types.h" - -constexpr u64 SYSTEM_RESERVED = 0x800000000u; -constexpr u64 CODE_BASE_OFFSET = 0x100000000u; - -namespace Memory -{ - enum class MemoryMode : u32 - { - NoAccess = 0, - Read = 1, - Write = 2, - ReadWrite =3, - Execute = 4, - ExecuteRead = 5, - ExecuteWrite = 6, - ExecuteReadWrite = 7, - }; - - namespace VirtualMemory { - u64 memory_alloc(u64 address, u64 size, MemoryMode mode); - bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode); - bool memory_flush(u64 address, u64 size); - bool memory_patch(u64 vaddr, u64 value); - } -} \ No newline at end of file diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index 1de6c619..cdb1febf 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -1,5 +1,5 @@ #include "Linker.h" -#include "../Memory.h" +#include "../virtual_memory.h" #include "../../Util/Log.h" #include "../../Util/Disassembler.h" #include @@ -112,7 +112,7 @@ void Linker::LoadModuleToMemory(Module* m) u64 base_size = calculate_base_size(elf_header, elf_pheader); m->aligned_base_size = (base_size & ~(static_cast(0x1000) - 1)) + 0x1000;//align base size to 0x1000 block size (TODO is that the default block size or it can be changed? - m->base_virtual_addr = Memory::VirtualMemory::memory_alloc(g_load_addr, m->aligned_base_size, Memory::MemoryMode::ExecuteReadWrite); + m->base_virtual_addr = VirtualMemory::memory_alloc(g_load_addr, m->aligned_base_size, VirtualMemory::MemoryMode::ExecuteReadWrite); LOG_INFO_IF(debug_loader, "====Load Module to Memory ========\n"); LOG_INFO_IF(debug_loader, "base_virtual_addr ......: {:#018x}\n", m->base_virtual_addr); @@ -566,7 +566,7 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { } if (rel_isResolved) { - Memory::VirtualMemory::memory_patch(rel_virtual_addr, rel_value); + VirtualMemory::memory_patch(rel_virtual_addr, rel_value); } else { diff --git a/src/Core/Memory.cpp b/src/Core/virtual_memory.cpp similarity index 97% rename from src/Core/Memory.cpp rename to src/Core/virtual_memory.cpp index 2386dc7e..a8857057 100644 --- a/src/Core/Memory.cpp +++ b/src/Core/virtual_memory.cpp @@ -1,6 +1,6 @@ -#include "Memory.h" +#include "virtual_memory.h" -#include "../Core/PS4/Loader/Elf.h" +#include "Core/PS4/Loader/Elf.h" #ifdef _WIN64 #include @@ -21,7 +21,6 @@ enum PosixPageProtection { #include "../Util/Log.h" -namespace Memory { namespace VirtualMemory { static u32 convertMemoryMode(MemoryMode mode) { switch (mode) { @@ -119,4 +118,3 @@ bool memory_patch(u64 vaddr, u64 value) { return ret; } } // namespace VirtualMemory -} // namespace Memory diff --git a/src/Core/virtual_memory.h b/src/Core/virtual_memory.h new file mode 100644 index 00000000..25a9dc68 --- /dev/null +++ b/src/Core/virtual_memory.h @@ -0,0 +1,23 @@ +#pragma once +#include + +constexpr u64 SYSTEM_RESERVED = 0x800000000u; +constexpr u64 CODE_BASE_OFFSET = 0x100000000u; + +namespace VirtualMemory { +enum class MemoryMode : u32 { + NoAccess = 0, + Read = 1, + Write = 2, + ReadWrite = 3, + Execute = 4, + ExecuteRead = 5, + ExecuteWrite = 6, + ExecuteReadWrite = 7, +}; +u64 memory_alloc(u64 address, u64 size, MemoryMode mode); +bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode); +bool memory_flush(u64 address, u64 size); +bool memory_patch(u64 vaddr, u64 value); + +} // namespace VirtualMemory \ No newline at end of file