Skip to content

Commit

Permalink
pcsx2: Fix a few crashes in macOS. (PCSX2#3424)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
TellowKrinkle authored Jul 12, 2020
1 parent c23f3be commit f7d84c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 3 additions & 12 deletions common/src/Utilities/Linux/LnxHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

// 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).
PageSizeAssertionTest(size);

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

Expand Down
4 changes: 3 additions & 1 deletion pcsx2/gui/RecentIsoList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f7d84c4

Please sign in to comment.