summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-31 14:22:56 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-31 14:22:56 +0100
commite27d281bf1115400bbd74ffa58ec54ea7ceef095 (patch)
tree2223649937e9ae38b1eb15845b9cd70d599393c0
parentfbf8751485ffb587eed672250396e9e1ce8875bb (diff)
downloadserenity-e27d281bf1115400bbd74ffa58ec54ea7ceef095.zip
UserspaceEmulator: Support sys$mremap()
This makes UE able to run dynamically linked executables once again.
-rw-r--r--DevTools/UserspaceEmulator/Emulator.cpp20
-rw-r--r--DevTools/UserspaceEmulator/Emulator.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp
index 26b98d8756..0f7b9948cb 100644
--- a/DevTools/UserspaceEmulator/Emulator.cpp
+++ b/DevTools/UserspaceEmulator/Emulator.cpp
@@ -410,6 +410,8 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
return virt$mount(arg1);
case SC_munmap:
return virt$munmap(arg1, arg2);
+ case SC_mremap:
+ return virt$mremap(arg1);
case SC_gettid:
return virt$gettid();
case SC_getpid:
@@ -1037,6 +1039,24 @@ u32 Emulator::virt$mmap(u32 params_addr)
return final_address;
}
+FlatPtr Emulator::virt$mremap(FlatPtr params_addr)
+{
+ Syscall::SC_mremap_params params;
+ mmu().copy_from_vm(&params, params_addr, sizeof(params));
+
+ if (auto* region = mmu().find_region({ m_cpu.ds(), params.old_address })) {
+ if (!region->is_mmap())
+ return -EINVAL;
+ ASSERT(region->size() == params.old_size);
+ auto& mmap_region = *(MmapRegion*)region;
+ auto* ptr = mremap(mmap_region.data(), mmap_region.size(), mmap_region.size(), params.flags);
+ if (ptr == MAP_FAILED)
+ return -errno;
+ return (FlatPtr)ptr;
+ }
+ return -EINVAL;
+}
+
u32 Emulator::virt$mount(u32 params_addr)
{
Syscall::SC_mount_params params;
diff --git a/DevTools/UserspaceEmulator/Emulator.h b/DevTools/UserspaceEmulator/Emulator.h
index 94d6224e13..61191265c1 100644
--- a/DevTools/UserspaceEmulator/Emulator.h
+++ b/DevTools/UserspaceEmulator/Emulator.h
@@ -103,6 +103,7 @@ private:
int virt$disown(pid_t);
int virt$purge(int mode);
u32 virt$mmap(u32);
+ FlatPtr virt$mremap(FlatPtr);
u32 virt$mount(u32);
u32 virt$munmap(FlatPtr address, u32 size);
u32 virt$gettid();