From 8237e50ebda460ffdd78b5d04f580a3825b8cc44 Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 20 May 2026 19:29:21 +0000 Subject: [PATCH] Use managarm special fastmem fallback --- src/common/host_memory.cpp | 17 +++++++++++++++-- src/common/host_memory.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 445d34c444..914f22bbc1 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -695,10 +695,21 @@ 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 (impl->Init()) { + if (has_memfd && impl->Init()) { backing_base = impl->backing_base; virtual_base = impl->virtual_base; if (virtual_base) { @@ -708,10 +719,12 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) } } else { impl.reset(); - LOG_WARNING(HW_Memory, "Platform can support fastmem, but can't create it"); + LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); +#ifdef _WIN32 fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); virtual_base = nullptr; +#endif } #endif } diff --git a/src/common/host_memory.h b/src/common/host_memory.h index 24f4670732..e003429baf 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -86,7 +86,9 @@ 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