From 67f1cd4e154c4204c7cd1d6a60c349a690649d5d Mon Sep 17 00:00:00 2001 From: Ganael Laplanche Date: Thu, 27 Oct 2022 16:51:37 +0200 Subject: [PATCH] Fix shm_open(3) call on FreeBSD On FreeBSD, shm_open(3) requires name to start with a '/', else EINVAL is returned. See: https://www.freebsd.org/cgi/man.cgi?shm_open --- common/Linux/LnxHostSys.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/Linux/LnxHostSys.cpp b/common/Linux/LnxHostSys.cpp index 0868364219..5f4d0d0abe 100644 --- a/common/Linux/LnxHostSys.cpp +++ b/common/Linux/LnxHostSys.cpp @@ -153,7 +153,12 @@ void HostSys::MemProtect(void* baseaddr, size_t size, const PageProtectionMode& std::string HostSys::GetFileMappingName(const char* prefix) { const unsigned pid = static_cast(getpid()); +#if defined(__FreeBSD__) + // FreeBSD's shm_open(3) requires name to be absolute + return fmt::format("/tmp/{}_{}", prefix, pid); +#else return fmt::format("{}_{}", prefix, pid); +#endif } void* HostSys::CreateSharedMemory(const char* name, size_t size)