123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef _TLS_H
- #define _TLS_H
- #ifndef __ASSEMBLER__
- # include <stdbool.h>
- # include <pt-machine.h>
- # include <stddef.h>
- typedef union dtv
- {
- size_t counter;
- struct
- {
- void *val;
- bool is_static;
- } pointer;
- } dtv_t;
- # define READ_THREAD_POINTER() \
- ({ void *__result; \
- __asm__ __volatile__ (".set\tpush\n\t.set\tmips32r2\n\t" \
- "rdhwr\t%0, $29\n\t.set\tpop" : "=v" (__result)); \
- __result; })
- #else
- # include <tcb-offsets.h>
- # define READ_THREAD_POINTER(rd) \
- .set push; \
- .set mips32r2; \
- rdhwr rd, $29; \
- .set pop
- #endif
- #if defined HAVE_TLS_SUPPORT \
- && (defined FLOATING_STACKS || !defined IS_IN_libpthread)
- # define USE_TLS 1
- #ifndef FLOATING_STACKS
- # define INCLUDE_TLS_PADDING 1
- #endif
- # ifndef __ASSEMBLER__
- typedef struct
- {
- dtv_t *dtv;
- void *private;
- } tcbhead_t;
- # define TLS_INIT_TCB_SIZE 0
- # define TLS_INIT_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
- # define TLS_TCB_SIZE 0
- # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
- # define TLS_PRE_TCB_SIZE \
- (sizeof (struct _pthread_descr_struct) \
- + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
- #define TLS_TCB_OFFSET 0x7000
- # define TLS_DTV_AT_TP 1
- # 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) \
- ({ INTERNAL_SYSCALL_DECL (err); \
- long result_var; \
- result_var = INTERNAL_SYSCALL (set_thread_area, err, 1, \
- (char *) (tcbp) + TLS_TCB_OFFSET); \
- INTERNAL_SYSCALL_ERROR_P (result_var, err) \
- ? "unknown error" : NULL; })
- # define THREAD_DTV() \
- (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv)
- # undef THREAD_SELF
- # define THREAD_SELF \
- ((pthread_descr) (READ_THREAD_POINTER () \
- - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
- # include <linuxthreads/descr.h>
- # define NO_TLS_OFFSET -1
- # define TLS_INIT_TP_EXPENSIVE 1
- # endif
- #endif
- #endif
|