mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 05:38:49 +00:00
Core: Memory code cleanup and further direct memory fixes (#3655)
* Remove mapped dmem type Since physical addresses can be mapped multiple times, tracking mapped pages is not necessary. This also allows me to significantly simplify the MapMemory physical address validation logic. * Proper implementation for sceKernelMtypeprotect I've rewritten SetDirectMemoryType to use virtual addresses instead of physical addresses, allowing it to be used in sceKernelMtypeprotect. To accommodate this change, I've also moved address and size alignment out of MemoryManager::Protect * Apply memory type in sceKernelMemoryPoolCommit * Organization Some potentially important missing mutexes, removed some unnecessary mutexes, moved some mutexes after early error returns, and updated copyright dates * Iterator logic cleanup Missing end check in ClampRangeSize, and adjusted VirtualQuery and DirectMemoryQuery. * Clang * Adjustments * Properly account for behavior differences in MapDirectMemory2 Undid the changes to direct memory areas, added more robust logic for changing dma types, and fixed DirectMemoryQuery to return hardware-accurate direct memory information in cases where dmas split here, but not on real hardware. I've also changed MapMemory's is_exec flag to a validate_dmem flag, used to handle alternate behavior in MapDirectMemory2. is_exec is now determined by the use of MemoryProt::CpuExec instead. * Clang * Add execute permissions to physical backing Needed for executable mappings to work properly on Windows, fixes regression in RE2 with prior commit. * Minor variable cleanup * Update memory.h * Prohibit direct memory mappings with exec protections Did a quick hardware test to confirm, only seems to be prohibited for dmem mappings though. * Update memory.cpp
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
@@ -222,11 +222,11 @@ public:
|
||||
|
||||
void Free(PAddr phys_addr, u64 size);
|
||||
|
||||
s32 PoolCommit(VAddr virtual_addr, u64 size, MemoryProt prot);
|
||||
s32 PoolCommit(VAddr virtual_addr, u64 size, MemoryProt prot, s32 mtype);
|
||||
|
||||
s32 MapMemory(void** out_addr, VAddr virtual_addr, u64 size, MemoryProt prot,
|
||||
MemoryMapFlags flags, VMAType type, std::string_view name = "anon",
|
||||
bool is_exec = false, PAddr phys_addr = -1, u64 alignment = 0);
|
||||
bool validate_dmem = false, PAddr phys_addr = -1, u64 alignment = 0);
|
||||
|
||||
s32 MapFile(void** out_addr, VAddr virtual_addr, u64 size, MemoryProt prot,
|
||||
MemoryMapFlags flags, s32 fd, s64 phys_addr);
|
||||
@@ -254,7 +254,7 @@ public:
|
||||
|
||||
s32 IsStack(VAddr addr, void** start, void** end);
|
||||
|
||||
s32 SetDirectMemoryType(s64 phys_addr, s32 memory_type);
|
||||
s32 SetDirectMemoryType(VAddr addr, u64 size, s32 memory_type);
|
||||
|
||||
void NameVirtualRange(VAddr virtual_addr, u64 size, std::string_view name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user