diff options
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.cpp | 20 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.h | 1 |
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(¶ms, 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(); |