Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for shm->map_self() #9230

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions rpcs3/util/vm_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,32 @@ namespace utils

return nullptr;
#else
const u64 ptr64 = reinterpret_cast<u64>(ptr);
return static_cast<u8*>(::mmap(reinterpret_cast<void*>(ptr64 & -0x10000), m_size, +prot, MAP_SHARED | (ptr ? MAP_FIXED : 0), m_file, 0));
const u64 ptr64 = reinterpret_cast<u64>(ptr) & -0x10000;

if (ptr64)
{
return reinterpret_cast<u8*>(reinterpret_cast<u64>(::mmap(reinterpret_cast<void*>(ptr64), m_size, +prot, MAP_SHARED | MAP_FIXED, m_file, 0)));
}
else
{
const u64 res64 = reinterpret_cast<u64>(::mmap(reinterpret_cast<void*>(ptr64), m_size + 0xe000, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0));

const u64 aligned = ::align(res64, 0x10000);
const auto result = ::mmap(reinterpret_cast<void*>(aligned), m_size, +prot, MAP_SHARED | MAP_FIXED, m_file, 0);
Copy link
Contributor

@elad335 elad335 Nov 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt this run in a loop? for cases where other thread just mmap on the same range inbetween. until second mmap call succeeds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah nvm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmap with MAP_FIXED flag just overwrites previous mapping, fully or partially.


// Now cleanup remnants
if (aligned > res64)
{
verify(HERE), ::munmap(reinterpret_cast<void*>(res64), aligned - res64) == 0;
}

if (aligned < res64 + 0xe000)
{
verify(HERE), ::munmap(reinterpret_cast<void*>(aligned + m_size), (res64 + 0xe000) - (aligned)) == 0;
}

return reinterpret_cast<u8*>(result);
}
#endif
}

Expand Down