1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Fix overlapping addresses returned by mmap

This commit is contained in:
kd-11 2024-08-29 02:55:10 +03:00 committed by kd-11
parent 23788b04c6
commit ce9024efc5
2 changed files with 8 additions and 2 deletions

View File

@ -9,7 +9,7 @@
#include "util/v128.hpp" #include "util/v128.hpp"
#include "util/simd.hpp" #include "util/simd.hpp"
#if defined(__linux__) || defined(__APPLE__) #ifdef __linux__
#include <unistd.h> #include <unistd.h>
#define CAN_OVERCOMMIT #define CAN_OVERCOMMIT
#endif #endif

View File

@ -260,7 +260,13 @@ namespace utils
#ifdef __APPLE__ #ifdef __APPLE__
#ifdef ARCH_ARM64 #ifdef ARCH_ARM64
auto ptr = ::mmap(use_addr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0); // NOTE: On MacOS, parallel calls to mmap can return the same address more than once. Trying to madvise the same address twice throws EPERM.
static std::mutex mmap_lock;
void* ptr;
{
std::lock_guard lock(mmap_lock);
ptr = ::mmap(use_addr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0);
}
#else #else
auto ptr = ::mmap(use_addr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0); auto ptr = ::mmap(use_addr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0);
#endif #endif