Merge pull request #6114 from leoetlino/fix

MemArena: Use names that are based on the PID
This commit is contained in:
Markus Wick 2017-10-26 20:56:22 +02:00 committed by GitHub
commit 3f6017343b

View File

@ -55,31 +55,25 @@ static int AshmemCreateFileMapping(const char* name, size_t size)
void MemArena::GrabSHMSegment(size_t size) void MemArena::GrabSHMSegment(size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
const std::string name = "dolphin-emu." + std::to_string(GetCurrentProcessId());
hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0,
static_cast<DWORD>(size), L"Dolphin-emu"); static_cast<DWORD>(size), UTF8ToTStr(name).c_str());
#elif defined(ANDROID) #elif defined(ANDROID)
fd = AshmemCreateFileMapping("Dolphin-emu", size); fd = AshmemCreateFileMapping(("dolphin-emu." + std::to_string(getpid())).c_str(), size);
if (fd < 0) if (fd < 0)
{ {
NOTICE_LOG(MEMMAP, "Ashmem allocation failed"); NOTICE_LOG(MEMMAP, "Ashmem allocation failed");
return; return;
} }
#else #else
for (int i = 0; i < 10000; i++) const std::string file_name = "/dolphin-emu." + std::to_string(getpid());
fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd == -1)
{ {
std::string file_name = StringFromFormat("/dolphinmem.%d", i); ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno));
fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); return;
if (fd != -1)
{
shm_unlink(file_name.c_str());
break;
}
else if (errno != EEXIST)
{
ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno));
return;
}
} }
shm_unlink(file_name.c_str());
if (ftruncate(fd, size) < 0) if (ftruncate(fd, size) < 0)
ERROR_LOG(MEMMAP, "Failed to allocate low memory space"); ERROR_LOG(MEMMAP, "Failed to allocate low memory space");
#endif #endif