// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #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 = -1); /// 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; u8* backing_base{}; u8* virtual_base{}; }; } // namespace Core