2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-08-06 21:52:20 +02:00
|
|
|
#pragma once
|
2024-02-23 22:32:32 +01:00
|
|
|
|
2023-11-05 12:41:10 +01:00
|
|
|
#include "common/types.h"
|
2023-08-06 21:52:20 +02:00
|
|
|
|
|
|
|
constexpr u64 SYSTEM_RESERVED = 0x800000000u;
|
|
|
|
constexpr u64 CODE_BASE_OFFSET = 0x100000000u;
|
2023-08-07 17:16:26 +02:00
|
|
|
constexpr u64 SYSTEM_MANAGED_MIN = 0x0000040000u;
|
|
|
|
constexpr u64 SYSTEM_MANAGED_MAX = 0x07FFFFBFFFu;
|
|
|
|
constexpr u64 USER_MIN = 0x1000000000u;
|
|
|
|
constexpr u64 USER_MAX = 0xFBFFFFFFFFu;
|
2023-08-06 21:52:20 +02:00
|
|
|
|
|
|
|
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);
|
2023-08-07 17:16:26 +02:00
|
|
|
u64 memory_alloc_aligned(u64 address, u64 size, MemoryMode mode, u64 alignment);
|
2023-08-06 21:52:20 +02:00
|
|
|
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);
|
|
|
|
|
2023-11-21 15:54:10 +01:00
|
|
|
inline bool containsExecuteMode(MemoryMode mode) {
|
|
|
|
switch (mode) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case MemoryMode::Execute:
|
|
|
|
return true;
|
|
|
|
case MemoryMode::ExecuteRead:
|
|
|
|
return true;
|
|
|
|
case MemoryMode::ExecuteWrite:
|
|
|
|
return true;
|
|
|
|
case MemoryMode::ExecuteReadWrite:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
2023-11-21 15:54:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-23 22:32:32 +01:00
|
|
|
} // namespace VirtualMemory
|