2022-09-10 09:56:25 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_THREAD_TLS_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_THREAD_TLS_H_
|
2022-09-10 18:49:13 +00:00
|
|
|
|
|
|
|
#define TLS_ALIGNMENT 64
|
|
|
|
|
2022-10-08 09:40:44 +00:00
|
|
|
#define TIB_FLAG_TIME_CRITICAL 1
|
2022-10-16 19:05:08 +00:00
|
|
|
#define TIB_FLAG_VFORKED 2
|
|
|
|
#define TIB_FLAG_WINCRASHING 4
|
2022-10-08 09:40:44 +00:00
|
|
|
|
2022-09-10 09:56:25 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
struct CosmoFtrace { /* 16 */
|
|
|
|
bool ft_once; /* 0 */
|
|
|
|
bool ft_noreentry; /* 1 */
|
|
|
|
int ft_skew; /* 4 */
|
|
|
|
int64_t ft_lastaddr; /* 8 */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CosmoTib {
|
2022-11-02 05:36:03 +00:00
|
|
|
struct CosmoTib *tib_self; /* 0x00 */
|
|
|
|
struct CosmoFtrace tib_ftracer; /* 0x08 */
|
|
|
|
void *tib_garbages; /* 0x18 */
|
|
|
|
intptr_t tib_locale; /* 0x20 */
|
|
|
|
intptr_t tib_pthread; /* 0x28 */
|
|
|
|
struct CosmoTib *tib_self2; /* 0x30 */
|
2022-11-08 18:09:47 +00:00
|
|
|
_Atomic(int32_t) tib_tid; /* 0x38 transitions -1 → tid → 0 */
|
2022-11-02 05:36:03 +00:00
|
|
|
int32_t tib_errno; /* 0x3c */
|
|
|
|
uint64_t tib_flags; /* 0x40 */
|
2022-09-13 21:57:38 +00:00
|
|
|
void *tib_nsync;
|
2022-11-02 05:36:03 +00:00
|
|
|
int tib_ftrace; /* inherited */
|
|
|
|
int tib_strace; /* inherited */
|
|
|
|
uint64_t tib_sigmask; /* inherited */
|
2022-09-13 21:57:38 +00:00
|
|
|
void *tib_reserved4;
|
|
|
|
void *tib_reserved5;
|
|
|
|
void *tib_reserved6;
|
|
|
|
void *tib_reserved7;
|
2022-10-09 06:54:05 +00:00
|
|
|
void *tib_keys[128];
|
2022-09-10 09:56:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int __threaded;
|
|
|
|
extern bool __tls_enabled;
|
|
|
|
extern unsigned __tls_index;
|
|
|
|
|
|
|
|
void __require_tls(void);
|
2022-11-02 05:36:03 +00:00
|
|
|
void __set_tls(struct CosmoTib *);
|
2022-09-10 09:56:25 +00:00
|
|
|
|
2023-05-02 02:43:59 +00:00
|
|
|
#ifdef __x86_64__
|
2022-09-10 09:56:25 +00:00
|
|
|
/**
|
|
|
|
* Returns location of thread information block.
|
|
|
|
*
|
|
|
|
* This can't be used in privileged functions.
|
|
|
|
*/
|
2022-11-09 11:58:57 +00:00
|
|
|
#define __get_tls() \
|
|
|
|
({ \
|
|
|
|
struct CosmoTib *_t; \
|
|
|
|
asm("mov\t%%fs:0,%0" : "=r"(_t) : /* no inputs */ : "memory"); \
|
|
|
|
_t; \
|
|
|
|
})
|
2023-05-02 02:43:59 +00:00
|
|
|
#else
|
|
|
|
#define __get_tls() ((struct CosmoTib *)__builtin_thread_pointer())
|
|
|
|
#endif
|
2022-09-10 09:56:25 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_THREAD_TLS_H_ */
|