From 92cc8a47dd89f1993fffbe8aa3e6b78172e8f9dc Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 3 May 2021 01:30:19 +0200 Subject: [PATCH] UserspaceEmulator: Add missing argument for sys$allocate_tls --- Userland/DevTools/UserspaceEmulator/Emulator.h | 2 +- .../UserspaceEmulator/Emulator_syscalls.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h index 5cc02aaa30..19aa40ef5f 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.h +++ b/Userland/DevTools/UserspaceEmulator/Emulator.h @@ -160,7 +160,7 @@ private: pid_t virt$setsid(); int virt$watch_file(FlatPtr, size_t); int virt$readlink(FlatPtr); - u32 virt$allocate_tls(size_t); + u32 virt$allocate_tls(FlatPtr, size_t); int virt$ptsname(int fd, FlatPtr buffer, size_t buffer_size); int virt$beep(); int virt$ftruncate(int fd, FlatPtr length_addr); diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index 4eea04b2b2..993f6e17a2 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -231,7 +231,7 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3) case SC_ptsname: return virt$ptsname(arg1, arg2, arg3); case SC_allocate_tls: - return virt$allocate_tls(arg1); + return virt$allocate_tls(arg1, arg2); case SC_beep: return virt$beep(); case SC_ftruncate: @@ -1430,12 +1430,20 @@ int Emulator::virt$readlink(FlatPtr params_addr) return rc; } -u32 Emulator::virt$allocate_tls(size_t size) +u32 Emulator::virt$allocate_tls(FlatPtr initial_data, size_t size) { // TODO: Why is this needed? without this, the loader overflows the bounds of the TLS region. constexpr size_t TLS_SIZE_HACK = 8; auto tcb_region = make(0x20000000, size + TLS_SIZE_HACK); - bzero(tcb_region->data(), size); + + size_t offset = 0; + while (size - offset > 0) { + u8 buffer[512]; + size_t read_bytes = min(sizeof(buffer), size - offset); + mmu().copy_from_vm(buffer, initial_data + offset, read_bytes); + memcpy(tcb_region->data() + offset, buffer, read_bytes); + offset += read_bytes; + } memset(tcb_region->shadow_data(), 0x01, size); auto tls_region = make(0, 4);