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
This commit is contained in:
Ganael Laplanche 2022-10-27 16:51:37 +02:00 committed by lightningterror
parent 6ad98e2c70
commit 67f1cd4e15
1 changed files with 5 additions and 0 deletions

View File

@ -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<unsigned>(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)