mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 12:00:31 +00:00
Make _Thread_local work across platforms
We now rewrite the binary image at runtime on Windows and XNU to change mov %fs:0,%reg instructions to use %gs instead. There's also simpler threading API introduced by this change and it's called _spawn() and _join(), which has replaced most clone() usage.
This commit is contained in:
parent
e4d6e263d4
commit
5f4f6b0e69
51 changed files with 808 additions and 1043 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/gettls.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
|
||||
/**
|
||||
* Returns address of thread information block.
|
||||
|
|
|
@ -40,6 +40,7 @@ LIBC_SYSV_A_FILES := \
|
|||
libc/sysv/errno_location.greg.c \
|
||||
libc/sysv/errno.c \
|
||||
libc/sysv/gettls.greg.c \
|
||||
libc/sysv/tlspolyfill.S \
|
||||
libc/sysv/errfun.S \
|
||||
libc/sysv/strace.greg.c \
|
||||
libc/sysv/describeos.greg.c \
|
||||
|
|
90
libc/sysv/tlspolyfill.S
Normal file
90
libc/sysv/tlspolyfill.S
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
// Code morphing TLS polyfills for The New Technology.
|
||||
//
|
||||
// @note msvc generates this code so it's stable
|
||||
// @note func ordering follows x86 reg encoding
|
||||
// @note each function is exactly 18 bytes
|
||||
// @see __enable_threads()
|
||||
|
||||
__get_tls_nt_rax:
|
||||
push %rcx
|
||||
mov __tls_index(%rip),%ecx
|
||||
mov %gs:0x1480(,%rcx,8),%rax
|
||||
pop %rcx
|
||||
ret
|
||||
.endfn __get_tls_nt_rax,globl,hidden
|
||||
|
||||
__get_tls_nt_rcx:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rcx
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rcx
|
||||
|
||||
__get_tls_nt_rdx:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rdx
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rdx
|
||||
|
||||
__get_tls_nt_rbx:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rbx
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rbx
|
||||
|
||||
__get_tls_nt_rsp:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rsp
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rsp
|
||||
|
||||
__get_tls_nt_rbp:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rbp
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rbp
|
||||
|
||||
__get_tls_nt_rsi:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rsi
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rsi
|
||||
|
||||
__get_tls_nt_rdi:
|
||||
push %rax
|
||||
mov __tls_index(%rip),%eax
|
||||
mov %gs:0x1480(,%rax,8),%rdi
|
||||
pop %rax
|
||||
ret
|
||||
.endfn __get_tls_nt_rdi
|
Loading…
Add table
Add a link
Reference in a new issue