mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-25 23:39:04 +00:00
Add back missing TlsAlloc() call
Cosmopolitan Libc once called this important function although somewhere along the way, possibly in a refactoring, it got removed and __tls_alloc has always been zero ever since.
This commit is contained in:
parent
e08a4cd99e
commit
5d2d9e9640
5 changed files with 12 additions and 9 deletions
|
@ -65,6 +65,7 @@
|
||||||
#include "libc/thread/itimer.internal.h"
|
#include "libc/thread/itimer.internal.h"
|
||||||
#include "libc/thread/posixthread.internal.h"
|
#include "libc/thread/posixthread.internal.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
|
#include "libc/thread/tls2.internal.h"
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
extern long __klog_handle;
|
extern long __klog_handle;
|
||||||
|
@ -112,7 +113,8 @@ static dontinline textwindows ssize_t ForkIo2(
|
||||||
ssize_t rc = ForkIo(h, buf, n, fn);
|
ssize_t rc = ForkIo(h, buf, n, fn);
|
||||||
if (ischild) {
|
if (ischild) {
|
||||||
// prevent crashes
|
// prevent crashes
|
||||||
__tls_enabled_set(false);
|
__threaded = false;
|
||||||
|
__tls_enabled = false;
|
||||||
__pid = __imp_GetCurrentProcessId();
|
__pid = __imp_GetCurrentProcessId();
|
||||||
__klog_handle = 0;
|
__klog_handle = 0;
|
||||||
__maps.maps = 0;
|
__maps.maps = 0;
|
||||||
|
@ -265,9 +267,8 @@ textwindows void WinMainForked(void) {
|
||||||
ReadOrDie(reader, __data_start, __data_end - __data_start);
|
ReadOrDie(reader, __data_start, __data_end - __data_start);
|
||||||
ReadOrDie(reader, __bss_start, __bss_end - __bss_start);
|
ReadOrDie(reader, __bss_start, __bss_end - __bss_start);
|
||||||
kStartTsc = savetsc;
|
kStartTsc = savetsc;
|
||||||
|
__tls_enabled = false;
|
||||||
__threaded = false;
|
__threaded = false;
|
||||||
__tls_index = 0;
|
|
||||||
__tls_enabled_set(false);
|
|
||||||
|
|
||||||
// fixup memory manager
|
// fixup memory manager
|
||||||
__maps.free = 0;
|
__maps.free = 0;
|
||||||
|
@ -456,9 +457,10 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
||||||
} else {
|
} else {
|
||||||
rc = 0;
|
rc = 0;
|
||||||
// re-apply code morphing for thread-local storage
|
// re-apply code morphing for thread-local storage
|
||||||
__set_tls(tib);
|
__tls_index = TlsAlloc();
|
||||||
|
__set_tls_win32(tib);
|
||||||
__morph_tls();
|
__morph_tls();
|
||||||
__tls_enabled_set(true);
|
__tls_enabled = true;
|
||||||
// the child's pending signals is initially empty
|
// the child's pending signals is initially empty
|
||||||
atomic_store_explicit(&__sig.pending, 0, memory_order_relaxed);
|
atomic_store_explicit(&__sig.pending, 0, memory_order_relaxed);
|
||||||
atomic_store_explicit(&tib->tib_sigpending, 0, memory_order_relaxed);
|
atomic_store_explicit(&tib->tib_sigpending, 0, memory_order_relaxed);
|
||||||
|
|
|
@ -45,7 +45,7 @@ cosmo: push %rbp
|
||||||
#endif /* SYSDEBUG */
|
#endif /* SYSDEBUG */
|
||||||
|
|
||||||
#ifndef NOX87
|
#ifndef NOX87
|
||||||
// Windows always initializes FPU to douuble precision.
|
// Windows always initializes FPU to double precision.
|
||||||
// WSL breaks Linux ABI by initializing FPU to double precision.
|
// WSL breaks Linux ABI by initializing FPU to double precision.
|
||||||
// This code makes long double long again.
|
// This code makes long double long again.
|
||||||
//
|
//
|
||||||
|
|
|
@ -251,6 +251,8 @@ textstartup void __enable_tls(void) {
|
||||||
atomic_store_explicit(&_pthread_static.ptid, tid, memory_order_release);
|
atomic_store_explicit(&_pthread_static.ptid, tid, memory_order_release);
|
||||||
|
|
||||||
// ask the operating system to change the x86 segment register
|
// ask the operating system to change the x86 segment register
|
||||||
|
if (IsWindows())
|
||||||
|
__tls_index = TlsAlloc();
|
||||||
__set_tls(tib);
|
__set_tls(tib);
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
|
@ -38,7 +38,7 @@ dontinstrument textstartup void __set_tls(struct CosmoTib *tib) {
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
// ask the operating system to change the x86 segment register
|
// ask the operating system to change the x86 segment register
|
||||||
if (IsWindows()) {
|
if (IsWindows()) {
|
||||||
asm("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tib));
|
__set_tls_win32(tib);
|
||||||
} else if (IsLinux()) {
|
} else if (IsLinux()) {
|
||||||
sys_set_tls(ARCH_SET_GS, tib);
|
sys_set_tls(ARCH_SET_GS, tib);
|
||||||
} else if (IsFreebsd()) {
|
} else if (IsFreebsd()) {
|
||||||
|
|
|
@ -17,9 +17,8 @@ forceinline struct CosmoTib *__get_tls_privileged(void) {
|
||||||
__asm__("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
__asm__("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||||
} else {
|
} else {
|
||||||
__asm__("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
__asm__("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||||
if (IsWindows()) {
|
if (IsWindows())
|
||||||
tib = *(char **)(tib + 0x1480 + __tls_index * 8);
|
tib = *(char **)(tib + 0x1480 + __tls_index * 8);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (struct CosmoTib *)tib;
|
return (struct CosmoTib *)tib;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue