pcsx2: Fix a few crashes in macOS. (#3424)

* Fix crash on shutdown in macOS

* Fix crashing in ISO list on macOS

* Use MAP_FIXED on linux too
It works as expected and has no race conditions.
This commit is contained in:
tellowkrinkle 2020-07-12 16:54:21 -05:00 committed by GitHub
parent c23f3be21f
commit f7d84c4637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 13 deletions

View File

@ -178,21 +178,12 @@ bool HostSys::MmapCommitPtr(void *base, size_t size, const PageProtectionMode &m
void HostSys::MmapResetPtr(void *base, size_t size)
{
// On linux the only way to reset the memory is to unmap and remap it as PROT_NONE.
// That forces linux to unload all committed pages and start from scratch.
PageSizeAssertionTest(size);
// FIXME: Ideally this code would have some threading lock on it to prevent any other
// malloc/free code in the current process from interfering with the operation, but I
// can't think of any good way to do that. (generally it shouldn't be a problem in
// PCSX2 anyway, since MmapReset is only called when the ps2vm is suspended; so that
// pretty well stops all PCSX2 threads anyway).
Munmap(base, size);
void *result = MmapReservePtr(base, size);
void *result = mmap(base, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
pxAssertRel((uptr)result == (uptr)base, pxsFmt(
"Virtual memory decommit failed: memory at 0x%08X -> 0x%08X could not be remapped. "
"This is likely caused by multi-thread memory contention.",
"Virtual memory decommit failed: memory at 0x%08X -> 0x%08X could not be remapped.",
base, (uptr)base + size));
}

View File

@ -89,7 +89,9 @@ void RecentIsoManager::RemoveAllFromMenu()
if( m_Menu == NULL ) return;
int cnt = m_Items.size();
for( int i=0; i<cnt; ++i )
// Note: Go backwards to work around https://trac.wxwidgets.org/ticket/18772
// Switch it back to forwards once that's fixed in a relased WX version
for( int i=cnt-1; i>=0; --i )
{
RecentItem& curitem( m_Items[i] );
if( curitem.ItemPtr == NULL ) continue;