1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:57:45 +00:00

UserspaceEmulator: Handle MAP_FIXED with invalid addresses better

Old behavior: Crash due to VERIFY, unless we're completely and entirely out of
memory (m_available_ranges being empty), in which case it would return -ENOMEM.

New behavior: Return ENOMEM (and don't crash). In the case of nullptr,
also emit a helpful diagnostic.

Note that MAP_FIXED with nullptr is technically okay, but tends to be a sign
that something went wrong.

Also, this should improve mmap performance marginally, as it pulls the check out
of a loop that does not modify any parts of the check.

UE is now self-hosting! Fixes #5709.

However, this still needs some love: "ue UserspaceEmulator true" spits out tons
of error messages, probably false-positives, and takes about 229 seconds to run.
Then again, true-in-ue-in-ue-in-Qemu is three levels of emulation, so no wonder
it takes a long time! :D
This commit is contained in:
Ben Wiederhake 2021-03-10 17:59:05 +01:00 committed by Andreas Kling
parent 22d9bd0c45
commit 292871c4bc
2 changed files with 12 additions and 2 deletions

View file

@ -737,7 +737,14 @@ u32 Emulator::virt$mmap(u32 params_addr)
if (params.flags & MAP_RANDOMIZED) {
result = m_range_allocator.allocate_randomized(requested_size, params.alignment);
} else if (params.flags & MAP_FIXED) {
result = m_range_allocator.allocate_specific(VirtualAddress { params.addr }, requested_size);
if (params.addr)
result = m_range_allocator.allocate_specific(VirtualAddress { params.addr }, requested_size);
else {
// mmap(nullptr, …, MAP_FIXED) is technically okay, but tends to be a bug.
// Therefore, refuse to be helpful.
reportln("\n=={}== \033[31;1mTried to mmap at nullptr with MAP_FIXED.\033[0m, 0x{:x} bytes.", params.size);
dump_backtrace();
}
} else {
result = m_range_allocator.allocate_anywhere(requested_size, params.alignment);
}