123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- #ifndef _TLS_H
- #define _TLS_H 1
- #ifndef __ASSEMBLER__
- # include <stdbool.h>
- # include <stddef.h>
- # include <stdint.h>
- typedef union dtv
- {
- size_t counter;
- struct
- {
- void *val;
- bool is_static;
- } pointer;
- } dtv_t;
- #else
- # include <tcb-offsets.h>
- #endif
- #define HAVE_TLS_SUPPORT 1
- #define HAVE_TLS_MODEL_ATTRIBUTE 1
- #define HAVE___THREAD 1
- #define USE_TLS 1
- #ifndef HAVE_TLS_SUPPORT
- # error "TLS support is required."
- #endif
- # define USE_TLS 1
- #ifndef __ASSEMBLER__
- # include <sysdep.h>
- # define TLS_DTV_AT_TP 1
- #define TLS_MULTIPLE_THREADS_IN_TCB 1
- # include <../../descr.h>
- typedef struct
- {
- uintptr_t pointer_guard;
- uintptr_t stack_guard;
- dtv_t *dtv;
- } tcbhead_t;
- # define TLS_INIT_TCB_SIZE 0
- # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
- # define TLS_TCB_SIZE 0
- # define TLS_TCB_ALIGN __alignof__ (struct pthread)
- # define TLS_PRE_TCB_SIZE \
- (sizeof (struct pthread) \
- + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
- # ifndef __powerpc64__
- register void *__thread_register __asm__ ("r2");
- # define PT_THREAD_POINTER PT_R2
- # else
- register void *__thread_register __asm__ ("r13");
- # define PT_THREAD_POINTER PT_R13
- # endif
- # define TLS_TCB_OFFSET 0x7000
- # define INSTALL_DTV(tcbp, dtvp) \
- ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
- # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
- # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
- # define TLS_INIT_TP(tcbp, secondcall) \
- (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
- # define THREAD_DTV() \
- (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
- # define THREAD_SELF \
- ((struct pthread *) (__thread_register \
- - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
- # define DB_THREAD_SELF \
- REGISTER (32, 32, PT_THREAD_POINTER * 4, \
- - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
- REGISTER (64, 64, PT_THREAD_POINTER * 8, \
- - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
- # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
- # define THREAD_GETMEM_NC(descr, member, idx) \
- ((void)(descr), (THREAD_SELF)->member[idx])
- # define THREAD_SETMEM(descr, member, value) \
- ((void)(descr), (THREAD_SELF)->member = (value))
- # define THREAD_SETMEM_NC(descr, member, idx, value) \
- ((void)(descr), (THREAD_SELF)->member[idx] = (value))
- # define THREAD_SET_STACK_GUARD(value) \
- (((tcbhead_t *) ((char *) __thread_register \
- - TLS_TCB_OFFSET))[-1].stack_guard = (value))
- # define THREAD_COPY_STACK_GUARD(descr) \
- (((tcbhead_t *) ((char *) (descr) \
- + TLS_PRE_TCB_SIZE))[-1].stack_guard \
- = ((tcbhead_t *) ((char *) __thread_register \
- - TLS_TCB_OFFSET))[-1].stack_guard)
- # define THREAD_GET_POINTER_GUARD() \
- (((tcbhead_t *) ((char *) __thread_register \
- - TLS_TCB_OFFSET))[-1].pointer_guard)
- # define THREAD_SET_POINTER_GUARD(value) \
- (THREAD_GET_POINTER_GUARD () = (value))
- # define THREAD_COPY_POINTER_GUARD(descr) \
- (((tcbhead_t *) ((char *) (descr) \
- + TLS_PRE_TCB_SIZE))[-1].pointer_guard \
- = THREAD_GET_POINTER_GUARD())
- # define NO_TLS_OFFSET -1
- #define THREAD_GSCOPE_FLAG_UNUSED 0
- #define THREAD_GSCOPE_FLAG_USED 1
- #define THREAD_GSCOPE_FLAG_WAIT 2
- #define THREAD_GSCOPE_RESET_FLAG() \
- do \
- { int __res \
- = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
- THREAD_GSCOPE_FLAG_UNUSED); \
- if (__res == THREAD_GSCOPE_FLAG_WAIT) \
- lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
- } \
- while (0)
- #define THREAD_GSCOPE_SET_FLAG() \
- do \
- { \
- THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
- atomic_write_barrier (); \
- } \
- while (0)
- #define THREAD_GSCOPE_WAIT() \
- GL(dl_wait_lookup_done) ()
- #endif
- #endif
|