mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-19 04:58:27 +00:00
94caa0336e
* core: Implement new memory manager * ci: Attempt to fix linux build * code: Fix a few build errors
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include "common/enum.h"
|
|
#include "common/types.h"
|
|
|
|
namespace Core {
|
|
|
|
enum class MemoryPermission : u32 {
|
|
Read = 1 << 0,
|
|
Write = 1 << 1,
|
|
ReadWrite = Read | Write,
|
|
Execute = 1 << 2,
|
|
};
|
|
DECLARE_ENUM_FLAG_OPERATORS(MemoryPermission)
|
|
|
|
/**
|
|
* Represents the user virtual address space backed by a dmem memory block
|
|
*/
|
|
class AddressSpace {
|
|
public:
|
|
explicit AddressSpace();
|
|
~AddressSpace();
|
|
|
|
[[nodiscard]] u8* VirtualBase() noexcept {
|
|
return virtual_base;
|
|
}
|
|
[[nodiscard]] const u8* VirtualBase() const noexcept {
|
|
return virtual_base;
|
|
}
|
|
|
|
/**
|
|
* @brief Maps memory to the specified virtual address.
|
|
* @param virtual_addr The base address to place the mapping.
|
|
* If zero is provided an address in system managed area is picked.
|
|
* @param size The size of the area to map.
|
|
* @param phys_addr The offset of the backing file handle to map.
|
|
* The same backing region may be aliased into different virtual regions.
|
|
* If zero is provided the mapping is considered as private.
|
|
* @return A pointer to the mapped memory.
|
|
*/
|
|
void* Map(VAddr virtual_addr, size_t size, u64 alignment = 0, PAddr phys_addr = 0);
|
|
|
|
/// Unmaps specified virtual memory area.
|
|
void Unmap(VAddr virtual_addr, size_t size);
|
|
|
|
void Protect(VAddr virtual_addr, size_t size, MemoryPermission perms);
|
|
|
|
private:
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl;
|
|
u8* backing_base{};
|
|
u8* virtual_base{};
|
|
};
|
|
|
|
} // namespace Core
|