feat(thread): futex + TLS + pthread_self substrate
This commit is contained in:
@@ -76,6 +76,17 @@ struct elf64_phdr
|
||||
uint64_t p_align;
|
||||
};
|
||||
|
||||
/*
|
||||
* New-thread TLS geometry, consumed by src/thread/tls.c (todo 44) — see
|
||||
* tcb.h for the full contract. __vlibc_static_tls_size is the EXPORTED
|
||||
* default-visibility object (no attribute!); the other three are internal
|
||||
* and hidden.
|
||||
*/
|
||||
size_t __vlibc_static_tls_size = 0;
|
||||
hidden uintptr_t __vlibc_static_tls_template = 0;
|
||||
hidden size_t __vlibc_static_tls_filesz = 0;
|
||||
hidden size_t __vlibc_static_tls_align = 16;
|
||||
|
||||
/*
|
||||
* Round v up to a multiple of a. a must be a power of two, which ELF
|
||||
* p_align of a PT_TLS segment always is.
|
||||
@@ -253,6 +264,13 @@ init_main_tls(char **envp)
|
||||
align = 16;
|
||||
}
|
||||
|
||||
/* Record the geometry for new-thread TLS blocks (#44/#45) BEFORE the
|
||||
* template address is known: size/filesz/align are PT_TLS facts, the
|
||||
* template address depends on the mmap below. */
|
||||
__vlibc_static_tls_size = memsz;
|
||||
__vlibc_static_tls_filesz = filesz;
|
||||
__vlibc_static_tls_align = align;
|
||||
|
||||
/*
|
||||
* Single allocation: TLS image at the base, TCB at tp. tp uses exactly
|
||||
* p_align (never bumped): the linker bakes tpoff against
|
||||
@@ -273,6 +291,12 @@ init_main_tls(char **envp)
|
||||
tp = base + block;
|
||||
image = (char *)base;
|
||||
|
||||
/* The PRIMAL image is the new-thread template: the still-pristine
|
||||
* .tdata at p_vaddr when mapped, else this block (the file-fallback
|
||||
* path leaves no other copy). Never the main thread's live TLS — its
|
||||
* mutations must not leak into threads created later. */
|
||||
__vlibc_static_tls_template = mapped ? vaddr : base;
|
||||
|
||||
if (filesz > 0)
|
||||
{
|
||||
copy_tls_image(image, offset, vaddr, filesz, mapped);
|
||||
|
||||
Reference in New Issue
Block a user