void MemArena::GrabSHMSegment(size_t size) { #ifdef _WIN32 const std::string name = "dolphin-emu." + std::to_string(GetCurrentProcessId()); hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, static_cast<DWORD>(size), UTF8ToTStr(name).c_str()); #elif defined(ANDROID) fd = AshmemCreateFileMapping(("dolphin-emu." + std::to_string(getpid())).c_str(), size); if (fd < 0) { NOTICE_LOG(MEMMAP, "Ashmem allocation failed"); return; } #else 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) { ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno)); return; } shm_unlink(file_name.c_str()); if (ftruncate(fd, size) < 0) ERROR_LOG(MEMMAP, "Failed to allocate low memory space"); #endif }
void MemArena::GrabLowMemSpace(size_t size) { #ifdef _WIN32 hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, (DWORD)(size), nullptr); #elif defined(ANDROID) fd = AshmemCreateFileMapping("Dolphin-emu", size); if (fd < 0) { NOTICE_LOG(MEMMAP, "Ashmem allocation failed"); return; } #else for (int i = 0; i < 10000; i++) { std::string file_name = StringFromFormat("dolphinmem.%d", i); fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); if (fd != -1) { shm_unlink(file_name.c_str()); break; } else if (errno != EEXIST) { ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno)); return; } } if (ftruncate(fd, size) < 0) ERROR_LOG(MEMMAP, "Failed to allocate low memory space"); #endif }
void MemArena::GrabLowMemSpace(size_t size) { #ifdef _WIN32 hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(size), NULL); #elif defined(ANDROID) fd = AshmemCreateFileMapping("Dolphin-emu", size); if (fd < 0) { NOTICE_LOG(MEMMAP, "Ashmem allocation failed"); return; } #else mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; fd = open(ram_temp_file, O_RDWR | O_CREAT, mode); unlink(ram_temp_file); if (ftruncate(fd, size) < 0) ERROR_LOG(MEMMAP, "Failed to allocate low memory space"); return; #endif }