diff --git a/Source/Core/Common/Src/MemArena.cpp b/Source/Core/Common/Src/MemArena.cpp index 6e37021989..782e124e07 100644 --- a/Source/Core/Common/Src/MemArena.cpp +++ b/Source/Core/Common/Src/MemArena.cpp @@ -58,22 +58,26 @@ void MemArena::ReleaseSpace() } -void* MemArena::CreateView(s64 offset, size_t size) -{ -#ifdef _WIN32 - return MapViewOfFile(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size); -#else - return mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); -#endif -} - - -void* MemArena::CreateViewAt(s64 offset, size_t size, void* base) +void *MemArena::CreateView(s64 offset, size_t size, void *base) { #ifdef _WIN32 return MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base); #else - return mmap(base, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, offset); + void *retval = mmap( + base, size, + PROT_READ | PROT_WRITE, + MAP_SHARED | ((base == nullptr) ? 0 : MAP_FIXED), + fd, offset); + + if (retval == MAP_FAILED) + { + NOTICE_LOG(MEMMAP, "mmap on %s failed", ram_temp_file); + return nullptr; + } + else + { + return retval; + } #endif } @@ -160,14 +164,14 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32 goto bail; } #ifdef _M_X64 - *views[i].out_ptr = (u8*)arena->CreateViewAt( + *views[i].out_ptr = (u8*)arena->CreateView( position, views[i].size, base + views[i].virtual_address); #else if (views[i].flags & MV_MIRROR_PREVIOUS) { // No need to create multiple identical views. *views[i].out_ptr = *views[i - 1].out_ptr; } else { - *views[i].out_ptr = (u8*)arena->CreateViewAt( + *views[i].out_ptr = (u8*)arena->CreateView( position, views[i].size, base + (views[i].virtual_address & 0x3FFFFFFF)); if (!*views[i].out_ptr) goto bail; diff --git a/Source/Core/Common/Src/MemArena.h b/Source/Core/Common/Src/MemArena.h index 4c4acbc2f8..6951082723 100644 --- a/Source/Core/Common/Src/MemArena.h +++ b/Source/Core/Common/Src/MemArena.h @@ -33,12 +33,11 @@ class MemArena public: void GrabLowMemSpace(size_t size); void ReleaseSpace(); - void* CreateView(s64 offset, size_t size); - void* CreateViewAt(s64 offset, size_t size, void* base); - void ReleaseView(void* view, size_t size); + void *CreateView(s64 offset, size_t size, void *base = nullptr); + void ReleaseView(void *view, size_t size); // This only finds 1 GB in 32-bit - static u8* Find4GBBase(); + static u8 *Find4GBBase(); private: #ifdef _WIN32