diff options
| author | lizzie <lizzie@eden-emu.dev> | 2025-11-07 16:50:03 +0100 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2025-11-07 16:50:03 +0100 |
| commit | 48843306e2ea51b95525a0a5f04d2afac3193176 (patch) | |
| tree | a66f98a62f8d7d4472e823aa29de0cdb06dc4115 /src/common | |
| parent | 159482a7a99330d2b6d3b9a28a22316e0d8b6ca7 (diff) | |
[compat] Fix other DragonFlyBSD/NixOS issues (#2860)
Uh - the other pr that had "Fix dragonfly" got commits lost and I didn't notice... oops; cherry picked them back through :)
Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2860
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/host_memory.cpp | 55 | ||||
| -rw-r--r-- | src/common/settings.cpp | 2 | ||||
| -rw-r--r-- | src/common/settings.h | 2 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 6e47fa286d..5400b97018 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -521,14 +521,29 @@ public: #else fd = memfd_create("HostMemory", 0); #endif - ASSERT_MSG(fd >= 0, "memfd_create failed: {}", strerror(errno)); - - // Defined to extend the file with zeros - int ret = ftruncate(fd, backing_size); - ASSERT_MSG(ret == 0, "ftruncate failed with {}, are you out-of-memory?", strerror(errno)); - - backing_base = static_cast<u8*>( - mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); + bool use_anon = false; + if (fd <= 0) { + LOG_WARNING(Common_Memory, "memfd_create: {}", strerror(errno)); + use_anon = true; + } + if (!use_anon) { + // Defined to extend the file with zeros + int ret = ftruncate(fd, backing_size); + if (ret != 0) { + LOG_WARNING(Common_Memory, "ftruncate: {} (likely out-of-emory)", strerror(errno)); + use_anon = true; + } + } + if (use_anon) { + LOG_WARNING(Common_Memory, "Using private mappings instead of shared ones"); + backing_base = static_cast<u8*>(mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)); + if (fd > 0) { + fd = -1; + close(fd); + } + } else { + backing_base = static_cast<u8*>(mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); + } ASSERT_MSG(backing_base != MAP_FAILED, "mmap failed: {}", strerror(errno)); // Virtual memory initialization @@ -552,22 +567,18 @@ public: free_manager.AllocateBlock(virtual_base + virtual_offset, length); // Deduce mapping protection flags. - int flags = PROT_NONE; - if (True(perms & MemoryPermission::Read)) { - flags |= PROT_READ; - } - if (True(perms & MemoryPermission::Write)) { - flags |= PROT_WRITE; - } + int prot_flags = PROT_NONE; + if (True(perms & MemoryPermission::Read)) + prot_flags |= PROT_READ; + if (True(perms & MemoryPermission::Write)) + prot_flags |= PROT_WRITE; #ifdef ARCHITECTURE_arm64 - if (True(perms & MemoryPermission::Execute)) { - flags |= PROT_EXEC; - } + if (True(perms & MemoryPermission::Execute)) + prot_flags |= PROT_EXEC; #endif - - void* ret = mmap(virtual_base + virtual_offset, length, flags, MAP_SHARED | MAP_FIXED, fd, - host_offset); - ASSERT_MSG(ret != MAP_FAILED, "mmap failed: {}", strerror(errno)); + int flags = (fd > 0 ? MAP_SHARED : MAP_PRIVATE) | MAP_FIXED; + void* ret = mmap(virtual_base + virtual_offset, length, prot_flags, flags, fd, host_offset); + ASSERT_MSG(ret != MAP_FAILED, "mmap: {}", strerror(errno)); } void Unmap(size_t virtual_offset, size_t length) { diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 0022d242c3..6800c20f69 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -169,7 +169,7 @@ bool IsFastmemEnabled() { if (values.cpu_accuracy.GetValue() == CpuAccuracy::Unsafe) { return bool(values.cpuopt_unsafe_host_mmu); } -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun__) || defined(__HAIKU__) +#if !defined(__APPLE__) && !defined(__linux__) && !defined(__ANDROID__) && !defined(_WIN32) return false; #else return true; diff --git a/src/common/settings.h b/src/common/settings.h index 2aef8ba85a..360a49c6c6 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -296,7 +296,7 @@ struct Values { Category::CpuDebug}; SwitchableSetting<bool> cpuopt_unsafe_host_mmu{linkage, -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun__) || defined(__HAIKU__) +#if !defined(__APPLE__) && !defined(__linux__) && !defined(__ANDROID__) && !defined(_WIN32) false, #else true, |
