1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:18:13 +00:00

UserspaceEmulator: Add missing argument for sys$allocate_tls

This commit is contained in:
Gunnar Beutner 2021-05-03 01:30:19 +02:00 committed by Andreas Kling
parent ce0c76dcb5
commit 92cc8a47dd
2 changed files with 12 additions and 4 deletions

View file

@ -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<SimpleRegion>(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<SimpleRegion>(0, 4);