mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
UserspaceEmulator: Remember VM region names for MAP_ANONYMOUS
For some reason we only remembered the names of MAP_FILE mmap regions.
This commit is contained in:
parent
735a6482ac
commit
728d947601
3 changed files with 17 additions and 18 deletions
|
@ -1042,17 +1042,18 @@ u32 Emulator::virt$mmap(u32 params_addr)
|
||||||
final_address = result.value().base().get();
|
final_address = result.value().base().get();
|
||||||
auto final_size = result.value().size();
|
auto final_size = result.value().size();
|
||||||
|
|
||||||
if (params.flags & MAP_ANONYMOUS)
|
|
||||||
mmu().add_region(MmapRegion::create_anonymous(final_address, final_size, params.prot));
|
|
||||||
else {
|
|
||||||
String name_str;
|
String name_str;
|
||||||
if (params.name.characters) {
|
if (params.name.characters) {
|
||||||
auto name = ByteBuffer::create_uninitialized(params.name.length);
|
auto name = ByteBuffer::create_uninitialized(params.name.length);
|
||||||
mmu().copy_from_vm(name.data(), (FlatPtr)params.name.characters, params.name.length);
|
mmu().copy_from_vm(name.data(), (FlatPtr)params.name.characters, params.name.length);
|
||||||
name_str = { name.data(), name.size() };
|
name_str = { name.data(), name.size() };
|
||||||
}
|
}
|
||||||
auto region = MmapRegion::create_file_backed(final_address, final_size, params.prot, params.flags, params.fd, params.offset, name_str);
|
|
||||||
if (region->name() == "libc.so: .text (Emulated)") {
|
if (params.flags & MAP_ANONYMOUS) {
|
||||||
|
mmu().add_region(MmapRegion::create_anonymous(final_address, final_size, params.prot, move(name_str)));
|
||||||
|
} else {
|
||||||
|
auto region = MmapRegion::create_file_backed(final_address, final_size, params.prot, params.flags, params.fd, params.offset, move(name_str));
|
||||||
|
if (region->name() == "libc.so: .text") {
|
||||||
bool rc = find_malloc_symbols(*region);
|
bool rc = find_malloc_symbols(*region);
|
||||||
VERIFY(rc);
|
VERIFY(rc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,12 @@ static void free_pages(void* ptr, size_t bytes)
|
||||||
VERIFY(rc == 0);
|
VERIFY(rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<MmapRegion> MmapRegion::create_anonymous(u32 base, u32 size, u32 prot)
|
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, nullptr);
|
||||||
auto shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
|
auto shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
|
||||||
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
|
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
|
||||||
|
region->m_name = move(name);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +61,7 @@ NonnullOwnPtr<MmapRegion> MmapRegion::create_file_backed(u32 base, u32 size, u32
|
||||||
auto shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
|
auto shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
|
||||||
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
|
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
|
||||||
region->m_file_backed = true;
|
region->m_file_backed = true;
|
||||||
if (!name.is_empty()) {
|
region->m_name = move(name);
|
||||||
name = String::formatted("{} (Emulated)", name);
|
|
||||||
region->m_name = name;
|
|
||||||
}
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ class MallocTracer;
|
||||||
|
|
||||||
class MmapRegion final : public Region {
|
class MmapRegion final : public Region {
|
||||||
public:
|
public:
|
||||||
static NonnullOwnPtr<MmapRegion> create_anonymous(u32 base, u32 size, u32 prot);
|
static NonnullOwnPtr<MmapRegion> create_anonymous(u32 base, u32 size, u32 prot, String name);
|
||||||
static NonnullOwnPtr<MmapRegion> create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset, String name = {});
|
static NonnullOwnPtr<MmapRegion> create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset, String name);
|
||||||
virtual ~MmapRegion() override;
|
virtual ~MmapRegion() override;
|
||||||
|
|
||||||
virtual ValueWithShadow<u8> read8(u32 offset) override;
|
virtual ValueWithShadow<u8> read8(u32 offset) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue