From e468bf08b1cfce618bf010c5b444606928357228 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 3 May 2021 01:30:53 +0200 Subject: [PATCH] UserspaceEmulator: Make sure TLS allocation behavior matches kernel --- Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index 993f6e17a2..3cae18b05b 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -1432,9 +1432,10 @@ int Emulator::virt$readlink(FlatPtr params_addr) 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); + // TODO: This matches what Thread::make_thread_specific_region does. The kernel + // ends up allocating one more page. Figure out if this is intentional. + auto region_size = align_up_to(size, PAGE_SIZE) + PAGE_SIZE; + auto tcb_region = make(0x20000000, region_size); size_t offset = 0; while (size - offset > 0) {