[MemArena] Honor MV_MIRROR_PREVIOUS on ReleaseView

Allows for clean teardown of the Memory Map for Switch
This commit is contained in:
M4xw 2023-06-22 00:01:38 +02:00
parent 14586d6125
commit 5b6bc0cea7
6 changed files with 18 additions and 7 deletions

View File

@ -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();

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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();