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) { diff --git a/src/emulator.cpp b/src/emulator.cpp index 8d5378fd..a60aea1b 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -40,7 +40,9 @@ Emulator::Emulator() Config::load(config_dir / "config.toml"); // Initialize NT API functions +#ifdef _WIN32 Common::NtApi::Initialize(); +#endif // Start logger. Common::Log::Initialize();