diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index ab0d24673e..b5fe073dab 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -695,21 +695,10 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) backing_base = fallback_buffer->data(); virtual_base = nullptr; #else - bool has_memfd = true; // all platforms support it -#ifdef _WIN32 - // EXCEPT WINDOWS who may not (Windows 8.1, 7, Vista, etc) - DynamicLibrary kernelbase_dll("KernelBase"); - has_memfd = kernelbase_dll.IsOpen(); - if (has_memfd) { - PFN_CreateFileMapping2 p{}; - GetFuncAddress(kernelbase_dll, "CreateFileMapping2", p); - has_memfd = p != nullptr; - } -#endif // Try to allocate a fastmem arena. // The implementation will fail with std::bad_alloc on errors. impl = std::make_unique(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize); - if (has_memfd && impl->Init()) { + if (impl->Init()) { backing_base = impl->backing_base; virtual_base = impl->virtual_base; if (virtual_base) { @@ -719,8 +708,7 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) } } else { impl.reset(); - LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); -#ifdef _WIN32 + LOG_WARNING(HW_Memory, "Platform can support fastmem, but can't create it"); fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); virtual_base = nullptr; @@ -734,13 +722,8 @@ HostMemory::HostMemory(HostMemory&&) noexcept = default; HostMemory& HostMemory::operator=(HostMemory&&) noexcept = default; -#if defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__) -void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) {} -void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) {} -void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) {} -void HostMemory::EnableDirectMappedAddress() {} -#else void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(host_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); @@ -750,9 +733,11 @@ void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, M return; } impl->Map(virtual_offset + virtual_base_offset, host_offset, length, perms); +#endif } void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -760,9 +745,11 @@ void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) return; } impl->Unmap(virtual_offset + virtual_base_offset, length); +#endif } void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -773,18 +760,20 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission const bool write = True(perm & MemoryPermission::Write); const bool execute = True(perm & MemoryPermission::Execute); impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute); -} - -void HostMemory::EnableDirectMappedAddress() { - if (impl) { - impl->EnableDirectMappedAddress(); - virtual_size += reinterpret_cast(virtual_base); - } -} #endif +} void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) { std::memset(backing_base + physical_offset, fill_value, length); } +void HostMemory::EnableDirectMappedAddress() { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) + if (impl) { + impl->EnableDirectMappedAddress(); + virtual_size += reinterpret_cast(virtual_base); + } +#endif +} + } // namespace Common diff --git a/src/common/host_memory.h b/src/common/host_memory.h index 34e6726f11..00aa75a371 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -86,9 +86,7 @@ private: u8* virtual_base{}; size_t virtual_base_offset{}; // Windows requires it for kernels whom lack proper support for some functions! -#if defined(__OPENORBIS__) || defined(__managarm__) || defined(_WIN32) || defined(__EMSCRIPTEN__) std::optional> fallback_buffer; -#endif }; } // namespace Common