vm_native.cpp: Fix possible weakness of map_self()

This commit is contained in:
elad335 2025-04-29 14:26:46 +03:00
parent e449227235
commit 09f71a8ecb

View file

@ -969,20 +969,24 @@ namespace utils
{ {
void* ptr = m_ptr; void* ptr = m_ptr;
while (!ptr) for (void* mapped = nullptr; !ptr;)
{ {
const auto mapped = this->map(nullptr, prot); if (!mapped)
{
mapped = this->map(nullptr, prot);
}
// Install mapped memory // Install mapped memory
if (!m_ptr.compare_exchange(ptr, mapped)) if (m_ptr.compare_exchange(ptr, mapped))
{
// Mapped already, nothing to do.
this->unmap(mapped);
}
else
{ {
ptr = mapped; ptr = mapped;
} }
else if (ptr)
{
// Mapped already, nothing to do.
ensure(ptr != mapped);
this->unmap(mapped);
}
} }
return static_cast<u8*>(ptr); return static_cast<u8*>(ptr);