mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-12 04:35:56 +00:00
mmap executable memory (#3201)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
This commit is contained in:
parent
d1f5a7e8fb
commit
5eef2fd28a
4 changed files with 19 additions and 6 deletions
|
@ -358,9 +358,17 @@ enum PosixPageProtection {
|
||||||
[[nodiscard]] constexpr PosixPageProtection ToPosixProt(Core::MemoryProt prot) {
|
[[nodiscard]] constexpr PosixPageProtection ToPosixProt(Core::MemoryProt prot) {
|
||||||
if (True(prot & Core::MemoryProt::CpuReadWrite) ||
|
if (True(prot & Core::MemoryProt::CpuReadWrite) ||
|
||||||
True(prot & Core::MemoryProt::GpuReadWrite)) {
|
True(prot & Core::MemoryProt::GpuReadWrite)) {
|
||||||
|
if (True(prot & Core::MemoryProt::CpuExec)) {
|
||||||
|
return PAGE_EXECUTE_READWRITE;
|
||||||
|
} else {
|
||||||
return PAGE_READWRITE;
|
return PAGE_READWRITE;
|
||||||
|
}
|
||||||
} else if (True(prot & Core::MemoryProt::CpuRead) || True(prot & Core::MemoryProt::GpuRead)) {
|
} else if (True(prot & Core::MemoryProt::CpuRead) || True(prot & Core::MemoryProt::GpuRead)) {
|
||||||
|
if (True(prot & Core::MemoryProt::CpuExec)) {
|
||||||
|
return PAGE_EXECUTE_READ;
|
||||||
|
} else {
|
||||||
return PAGE_READONLY;
|
return PAGE_READONLY;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return PAGE_NOACCESS;
|
return PAGE_NOACCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,11 +573,12 @@ void* PS4_SYSV_ABI posix_mmap(void* addr, u64 len, s32 prot, s32 flags, s32 fd,
|
||||||
auto* memory = Core::Memory::Instance();
|
auto* memory = Core::Memory::Instance();
|
||||||
const auto mem_prot = static_cast<Core::MemoryProt>(prot);
|
const auto mem_prot = static_cast<Core::MemoryProt>(prot);
|
||||||
const auto mem_flags = static_cast<Core::MemoryMapFlags>(flags);
|
const auto mem_flags = static_cast<Core::MemoryMapFlags>(flags);
|
||||||
|
const auto is_exec = True(mem_prot & Core::MemoryProt::CpuExec);
|
||||||
|
|
||||||
s32 result = ORBIS_OK;
|
s32 result = ORBIS_OK;
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
result = memory->MapMemory(&addr_out, std::bit_cast<VAddr>(addr), len, mem_prot, mem_flags,
|
result = memory->MapMemory(&addr_out, std::bit_cast<VAddr>(addr), len, mem_prot, mem_flags,
|
||||||
Core::VMAType::Flexible);
|
Core::VMAType::Flexible, "anon", is_exec);
|
||||||
} else {
|
} else {
|
||||||
result = memory->MapFile(&addr_out, std::bit_cast<VAddr>(addr), len, mem_prot, mem_flags,
|
result = memory->MapFile(&addr_out, std::bit_cast<VAddr>(addr), len, mem_prot, mem_flags,
|
||||||
fd, phys_addr);
|
fd, phys_addr);
|
||||||
|
|
|
@ -631,6 +631,9 @@ s64 MemoryManager::ProtectBytes(VAddr addr, VirtualMemoryArea vma_base, u64 size
|
||||||
if (True(prot & MemoryProt::CpuReadWrite)) {
|
if (True(prot & MemoryProt::CpuReadWrite)) {
|
||||||
perms |= Core::MemoryPermission::ReadWrite;
|
perms |= Core::MemoryPermission::ReadWrite;
|
||||||
}
|
}
|
||||||
|
if (True(prot & MemoryProt::CpuExec)) {
|
||||||
|
perms |= Core::MemoryPermission::Execute;
|
||||||
|
}
|
||||||
if (True(prot & MemoryProt::GpuRead)) {
|
if (True(prot & MemoryProt::GpuRead)) {
|
||||||
perms |= Core::MemoryPermission::Read;
|
perms |= Core::MemoryPermission::Read;
|
||||||
}
|
}
|
||||||
|
@ -650,9 +653,9 @@ s32 MemoryManager::Protect(VAddr addr, u64 size, MemoryProt prot) {
|
||||||
std::scoped_lock lk{mutex};
|
std::scoped_lock lk{mutex};
|
||||||
|
|
||||||
// Validate protection flags
|
// Validate protection flags
|
||||||
constexpr static MemoryProt valid_flags = MemoryProt::NoAccess | MemoryProt::CpuRead |
|
constexpr static MemoryProt valid_flags =
|
||||||
MemoryProt::CpuReadWrite | MemoryProt::GpuRead |
|
MemoryProt::NoAccess | MemoryProt::CpuRead | MemoryProt::CpuReadWrite |
|
||||||
MemoryProt::GpuWrite | MemoryProt::GpuReadWrite;
|
MemoryProt::CpuExec | MemoryProt::GpuRead | MemoryProt::GpuWrite | MemoryProt::GpuReadWrite;
|
||||||
|
|
||||||
MemoryProt invalid_flags = prot & ~valid_flags;
|
MemoryProt invalid_flags = prot & ~valid_flags;
|
||||||
if (invalid_flags != MemoryProt::NoAccess) {
|
if (invalid_flags != MemoryProt::NoAccess) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ enum class MemoryProt : u32 {
|
||||||
NoAccess = 0,
|
NoAccess = 0,
|
||||||
CpuRead = 1,
|
CpuRead = 1,
|
||||||
CpuReadWrite = 2,
|
CpuReadWrite = 2,
|
||||||
|
CpuExec = 4,
|
||||||
GpuRead = 16,
|
GpuRead = 16,
|
||||||
GpuWrite = 32,
|
GpuWrite = 32,
|
||||||
GpuReadWrite = 48,
|
GpuReadWrite = 48,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue