diff --git a/Common/MemArena.h b/Common/MemArena.h index 85112e9129..9a905b1344 100644 --- a/Common/MemArena.h +++ b/Common/MemArena.h @@ -39,7 +39,7 @@ public: bool GrabMemSpace(size_t size); void ReleaseSpace(); void *CreateView(s64 offset, size_t size, void *base = 0); - void ReleaseView(void *view, size_t size); + void ReleaseView(s64 offset, void *view, size_t size); // This only finds 1 GB in 32-bit u8 *Find4GBBase(); diff --git a/Common/MemArenaAndroid.cpp b/Common/MemArenaAndroid.cpp index f7ea90cfec..73dd4e7cc6 100644 --- a/Common/MemArenaAndroid.cpp +++ b/Common/MemArenaAndroid.cpp @@ -129,7 +129,7 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base) { return retval; } -void MemArena::ReleaseView(void* view, size_t size) { +void MemArena::ReleaseView(s64 offset, void* view, size_t size) { munmap(view, size); } diff --git a/Common/MemArenaDarwin.cpp b/Common/MemArenaDarwin.cpp index d13e37a8a7..0b1abd16b8 100644 --- a/Common/MemArenaDarwin.cpp +++ b/Common/MemArenaDarwin.cpp @@ -79,7 +79,7 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base) { return (void *)target; } -void MemArena::ReleaseView(void* view, size_t size) { +void MemArena::ReleaseView(s64 offset, void* view, size_t size) { vm_address_t addr = (vm_address_t)view; vm_deallocate(mach_task_self(), addr, size); } diff --git a/Common/MemArenaPosix.cpp b/Common/MemArenaPosix.cpp index 5016cd429f..d35433bd57 100644 --- a/Common/MemArenaPosix.cpp +++ b/Common/MemArenaPosix.cpp @@ -121,7 +121,7 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base) return retval; } -void MemArena::ReleaseView(void* view, size_t size) { +void MemArena::ReleaseView(s64 offset, void* view, size_t size) { munmap(view, size); } diff --git a/Common/MemArenaWin32.cpp b/Common/MemArenaWin32.cpp index 39d0d6de70..85ee094ca9 100644 --- a/Common/MemArenaWin32.cpp +++ b/Common/MemArenaWin32.cpp @@ -54,7 +54,7 @@ void *MemArena::CreateView(s64 offset, size_t size, void *viewbase) { return ptr; } -void MemArena::ReleaseView(void* view, size_t size) { +void MemArena::ReleaseView(s64 offset, void* view, size_t size) { #if PPSSPP_PLATFORM(UWP) #else UnmapViewOfFile(view); diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 95e86aafc7..ced14a3538 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -187,7 +187,7 @@ bail: SKIP(flags, views[i].flags); if (*views[j].out_ptr) { if (!CanIgnoreView(views[j])) { - g_arena.ReleaseView(*views[j].out_ptr, views[j].size); + g_arena.ReleaseView(0, *views[j].out_ptr, views[j].size); } *views[j].out_ptr = NULL; } @@ -265,13 +265,24 @@ bool MemoryMap_Setup(u32 flags) { } void MemoryMap_Shutdown(u32 flags) { + size_t position = 0; + size_t last_position = 0; + for (int i = 0; i < num_views; i++) { if (views[i].size == 0) continue; SKIP(flags, views[i].flags); + + if (views[i].flags & MV_MIRROR_PREVIOUS) { + position = last_position; + } + if (*views[i].out_ptr) - g_arena.ReleaseView(*views[i].out_ptr, views[i].size); + g_arena.ReleaseView(position, *views[i].out_ptr, views[i].size); *views[i].out_ptr = nullptr; + + last_position = position; + position += g_arena.roundup(views[i].size); } g_arena.ReleaseSpace();