UserspaceEmulator: Prefix MmapRegions' name with '(UE)'

When printing a backtrace, each library's base address is found by
walking through all memory regions in the coredump, and selecting the
address of the first region whose name begins with the library's soname.
This is done to support the Clang toolchain, where .text is not at
offset 0.

However, because the libraries loaded by the emulated process used the
same names, we could not distinguish those with the ones used by
UserspaceEmulator, so the backtrace ended up being garbage.

Using the libraries mapped by UE would not be a sufficient, as the
running application could ask for other libraries too, and doing away
with setting names would make debugging issues within UE code more
difficult.
This commit is contained in:
Daniel Bertalan 2021-08-14 10:56:40 +02:00 committed by Andreas Kling
parent 0847ad9ca0
commit bfe5509a28
Notes: sideshowbarker 2024-07-18 06:55:09 +09:00
2 changed files with 9 additions and 3 deletions

View file

@ -27,7 +27,7 @@ static void free_pages(void* ptr, size_t bytes)
NonnullOwnPtr<MmapRegion> MmapRegion::create_anonymous(u32 base, u32 size, u32 prot, String name)
{
auto data = (u8*)mmap_initialized(size, 0, nullptr);
auto data = (u8*)mmap_initialized(size, 0, String::formatted("(UE) {}", name).characters());
auto shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
region->m_name = move(name);
@ -38,7 +38,7 @@ NonnullOwnPtr<MmapRegion> MmapRegion::create_file_backed(u32 base, u32 size, u32
{
// Since we put the memory to an arbitrary location, do not pass MAP_FIXED to the Kernel.
auto real_flags = flags & ~MAP_FIXED;
auto data = (u8*)mmap_with_name(nullptr, size, prot, real_flags, fd, offset, name.is_empty() ? nullptr : name.characters());
auto data = (u8*)mmap_with_name(nullptr, size, prot, real_flags, fd, offset, name.is_empty() ? nullptr : String::formatted("(UE) {}", name).characters());
VERIFY(data != MAP_FAILED);
auto shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
@ -317,4 +317,10 @@ void MmapRegion::set_prot(int prot)
}
}
void MmapRegion::set_name(String name)
{
m_name = move(name);
set_mmap_name(range().base().as_ptr(), range().size(), String::formatted("(UE) {}", m_name).characters());
}
}

View file

@ -61,7 +61,7 @@ public:
return {};
return m_name.substring(0, *maybe_separator);
}
void set_name(String name) { m_name = move(name); }
void set_name(String name);
private:
MmapRegion(u32 base, u32 size, int prot, u8* data, u8* shadow_data);