From a049bd3135c1886eebede6ca32f4072960137d87 Mon Sep 17 00:00:00 2001 From: "Daniel R." <47796739+polybiusproxy@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:16:50 +0200 Subject: [PATCH] Fix Linux builds --- src/common/ntapi.cpp | 4 ++++ src/core/address_space.cpp | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/common/ntapi.cpp b/src/common/ntapi.cpp index f596aa4f..0fe797e0 100644 --- a/src/common/ntapi.cpp +++ b/src/common/ntapi.cpp @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#ifdef _WIN32 + #include "ntapi.h" NtDelayExecution_t NtDelayExecution = nullptr; @@ -18,3 +20,5 @@ void Initialize() { } } // namespace Common::NtApi + +#endif diff --git a/src/core/address_space.cpp b/src/core/address_space.cpp index 8cd8cec4..03c755e0 100644 --- a/src/core/address_space.cpp +++ b/src/core/address_space.cpp @@ -19,6 +19,8 @@ namespace Core { static constexpr size_t BackingSize = SCE_KERNEL_MAIN_DMEM_SIZE; +#ifdef _WIN32 + [[nodiscard]] constexpr u64 ToWindowsProt(Core::MemoryProt prot) { switch (prot) { case Core::MemoryProt::NoAccess: @@ -31,7 +33,6 @@ static constexpr size_t BackingSize = SCE_KERNEL_MAIN_DMEM_SIZE; } } -#ifdef _WIN32 struct AddressSpace::Impl { Impl() : process{GetCurrentProcess()} { // Allocate virtual address placeholder for our address space. @@ -228,6 +229,18 @@ enum PosixPageProtection { PAGE_EXECUTE_READWRITE = PROT_EXEC | PROT_READ | PROT_WRITE }; +[[nodiscard]] constexpr PosixPageProtection ToPosixProt(Core::MemoryProt prot) { + switch (prot) { + case Core::MemoryProt::NoAccess: + default: + return PAGE_NOACCESS; + case Core::MemoryProt::CpuRead: + return PAGE_READONLY; + case Core::MemoryProt::CpuReadWrite: + return PAGE_READWRITE; + } +} + struct AddressSpace::Impl { Impl() { // Allocate virtual address placeholder for our address space. @@ -340,8 +353,13 @@ void* AddressSpace::Map(VAddr virtual_addr, size_t size, u64 alignment, PAddr ph void* AddressSpace::MapFile(VAddr virtual_addr, size_t size, size_t offset, u32 prot, uintptr_t fd) { +#ifdef _WIN32 return impl->Map(virtual_addr, offset, size, ToWindowsProt(std::bit_cast(prot)), fd); +#else + return impl->Map(virtual_addr, offset, size, ToPosixProt(std::bit_cast(prot)), + fd); +#endif } void AddressSpace::Unmap(VAddr virtual_addr, size_t size, bool has_backing) {