Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12173 from AdmiralCurtiss/fixed-mapping-assert
Common/MemArena: LazyMemoryRegion fixes.
  • Loading branch information
JosJuice committed Sep 7, 2023
2 parents c0440df + 422bc7a commit cc01b4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Source/Core/Common/MemArenaAndroid.cpp
Expand Up @@ -155,8 +155,11 @@ void* LazyMemoryRegion::Create(size_t size)
{
ASSERT(!m_memory);

if (size == 0)
return nullptr;

void* memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (!memory)
if (memory == MAP_FAILED)
{
NOTICE_LOG_FMT(MEMMAP, "Memory allocation of {} bytes failed.", size);
return nullptr;
Expand All @@ -172,7 +175,9 @@ void LazyMemoryRegion::Clear()
{
ASSERT(m_memory);

mmap(m_memory, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
void* new_memory = mmap(m_memory, m_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
ASSERT(new_memory == m_memory);
}

void LazyMemoryRegion::Release()
Expand Down
9 changes: 7 additions & 2 deletions Source/Core/Common/MemArenaUnix.cpp
Expand Up @@ -121,8 +121,11 @@ void* LazyMemoryRegion::Create(size_t size)
{
ASSERT(!m_memory);

if (size == 0)
return nullptr;

void* memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (!memory)
if (memory == MAP_FAILED)
{
NOTICE_LOG_FMT(MEMMAP, "Memory allocation of {} bytes failed.", size);
return nullptr;
Expand All @@ -138,7 +141,9 @@ void LazyMemoryRegion::Clear()
{
ASSERT(m_memory);

mmap(m_memory, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
void* new_memory = mmap(m_memory, m_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
ASSERT(new_memory == m_memory);
}

void LazyMemoryRegion::Release()
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Common/MemArenaWin.cpp
Expand Up @@ -445,6 +445,9 @@ void* LazyMemoryRegion::Create(size_t size)
{
ASSERT(!m_memory);

if (size == 0)
return nullptr;

void* memory = VirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!memory)
{
Expand Down

0 comments on commit cc01b4b

Please sign in to comment.