Back to index

glibc  2.9
Classes | Defines | Typedefs
tls.h File Reference
#include <asm/prctl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sysdep.h>
#include <kernel-features.h>
#include <nptl/descr.h>

Go to the source code of this file.

Classes

union  dtv
struct  tcbhead_t
struct  dtv.pointer

Defines

#define STACK_ALIGN   16
#define LOCK_PREFIX   "lock;"
#define TLS_INIT_TCB_SIZE   sizeof (struct pthread)
#define TLS_INIT_TCB_ALIGN   __alignof__ (struct pthread)
#define TLS_TCB_SIZE   sizeof (struct pthread)
#define TLS_TCB_ALIGN   __alignof__ (struct pthread)
#define TLS_TCB_AT_TP   1
#define INSTALL_DTV(descr, dtvp)   ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
#define INSTALL_NEW_DTV(dtvp)
#define GET_DTV(descr)   (((tcbhead_t *) (descr))->dtv)
#define TLS_GET_FS()   ({ int __seg; __asm ("movl %%fs, %0" : "=q" (__seg)); __seg; })
#define TLS_SET_FS(val)   __asm ("movl %0, %%fs" :: "q" (val))
#define TLS_INIT_TP(thrdescr, secondcall)
#define THREAD_DTV()
#define THREAD_SELF
#define DB_THREAD_SELF_INCLUDE   <sys/reg.h> /* For the FS constant. */
#define DB_THREAD_SELF   CONST_THREAD_AREA (64, FS)
#define THREAD_GETMEM(descr, member)
#define THREAD_GETMEM_NC(descr, member, idx)
#define IMM_MODE   "ir"
#define THREAD_SETMEM(descr, member, value)
#define THREAD_SETMEM_NC(descr, member, idx, value)
#define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval)
#define THREAD_ATOMIC_BIT_SET(descr, member, bit)
#define CALL_THREAD_FCT(descr)
#define THREAD_SET_STACK_GUARD(value)   THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
#define THREAD_COPY_STACK_GUARD(descr)
#define THREAD_SET_POINTER_GUARD(value)   THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
#define THREAD_COPY_POINTER_GUARD(descr)
#define THREAD_GSCOPE_FLAG_UNUSED   0
#define THREAD_GSCOPE_FLAG_USED   1
#define THREAD_GSCOPE_FLAG_WAIT   2
#define THREAD_GSCOPE_RESET_FLAG()
#define THREAD_GSCOPE_SET_FLAG()   THREAD_SETMEM (THREAD_SELF, header.gscope_flag, THREAD_GSCOPE_FLAG_USED)
#define THREAD_GSCOPE_WAIT()   GL(dl_wait_lookup_done) ()

Typedefs

typedef union dtv dtv_t

Class Documentation

union dtv

Definition at line 30 of file tls.h.

Class Members
size_t counter
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct dtv pointer
struct tcbhead_t

Definition at line 41 of file tls.h.

Collaboration diagram for tcbhead_t:
Class Members
void * __private
dtv_t * dtv
int gscope_flag
int multiple_threads
uintptr_t pointer_guard
void * private
int private_futex
void * self
uintptr_t stack_guard
uintptr_t sysinfo
void * tcb
unsigned long int vgetcpu_cache
struct dtv.pointer

Definition at line 37 of file tls.h.

Class Members
bool is_static
void * val

Define Documentation

#define CALL_THREAD_FCT (   descr)
Value:
({ void *__res;                                                      \
     asm volatile ("movq %%fs:%P2, %%rdi\n\t"                               \
                 "callq *%%fs:%P1"                                   \
                 : "=a" (__res)                                      \
                 : "i" (offsetof (struct pthread, start_routine)),          \
                   "i" (offsetof (struct pthread, arg))              \
                 : "di", "si", "cx", "dx", "r8", "r9", "r10", "r11",        \
                   "memory", "cc");                                         \
     __res; })

Definition at line 314 of file tls.h.

#define DB_THREAD_SELF   CONST_THREAD_AREA (64, FS)

Definition at line 180 of file tls.h.

#define DB_THREAD_SELF_INCLUDE   <sys/reg.h> /* For the FS constant. */

Definition at line 179 of file tls.h.

#define GET_DTV (   descr)    (((tcbhead_t *) (descr))->dtv)

Definition at line 122 of file tls.h.

#define IMM_MODE   "ir"

Definition at line 237 of file tls.h.

#define INSTALL_DTV (   descr,
  dtvp 
)    ((tcbhead_t *) (descr))->dtv = (dtvp) + 1

Definition at line 113 of file tls.h.

#define INSTALL_NEW_DTV (   dtvp)
Value:
({ struct pthread *__pd;                                             \
     THREAD_SETMEM (__pd, header.dtv, (dtvp)); })

Definition at line 117 of file tls.h.

#define LOCK_PREFIX   "lock;"

Definition at line 88 of file tls.h.

#define STACK_ALIGN   16

Definition at line 73 of file tls.h.

#define THREAD_ATOMIC_BIT_SET (   descr,
  member,
  bit 
)
Value:
(void) ({ if (sizeof ((descr)->member) == 4)                                \
             asm volatile (LOCK_PREFIX "orl %1, %%fs:%P0"                   \
                         :: "i" (offsetof (struct pthread, member)),        \
                            "ir" (1 << (bit)));                      \
           else                                                      \
             /* Not necessary for other sizes in the moment.  */            \
             abort (); })

Definition at line 304 of file tls.h.

#define THREAD_ATOMIC_CMPXCHG_VAL (   descr,
  member,
  newval,
  oldval 
)
Value:
({ __typeof (descr->member) __ret;                                   \
     __typeof (oldval) __old = (oldval);                             \
     if (sizeof (descr->member) == 4)                                       \
       asm volatile (LOCK_PREFIX "cmpxchgl %2, %%fs:%P3"                    \
                   : "=a" (__ret)                                    \
                   : "0" (__old), "r" (newval),                      \
                     "i" (offsetof (struct pthread, member)));       \
     else                                                            \
       /* Not necessary for other sizes in the moment.  */                  \
       abort ();                                                     \
     __ret; })

Definition at line 289 of file tls.h.

#define THREAD_COPY_POINTER_GUARD (   descr)
Value:
((descr)->header.pointer_guard                                       \
   = THREAD_GETMEM (THREAD_SELF, header.pointer_guard))

Definition at line 337 of file tls.h.

#define THREAD_COPY_STACK_GUARD (   descr)
Value:
((descr)->header.stack_guard                                         \
     = THREAD_GETMEM (THREAD_SELF, header.stack_guard))

Definition at line 329 of file tls.h.

#define THREAD_DTV ( )
Value:
({ struct pthread *__pd;                                             \
     THREAD_GETMEM (__pd, header.dtv); })

Definition at line 161 of file tls.h.

#define THREAD_GETMEM (   descr,
  member 
)
Value:
({ __typeof (descr->member) __value;                                        \
     if (sizeof (__value) == 1)                                             \
       asm volatile ("movb %%fs:%P2,%b0"                             \
                   : "=q" (__value)                                         \
                   : "0" (0), "i" (offsetof (struct pthread, member)));     \
     else if (sizeof (__value) == 4)                                        \
       asm volatile ("movl %%fs:%P1,%0"                                     \
                   : "=r" (__value)                                         \
                   : "i" (offsetof (struct pthread, member)));       \
     else                                                            \
       {                                                             \
        if (sizeof (__value) != 8)                                   \
          /* There should not be any value with a size other than 1,        \
             4 or 8.  */                                             \
          abort ();                                                  \
                                                                     \
        asm volatile ("movq %%fs:%P1,%q0"                            \
                     : "=r" (__value)                                       \
                     : "i" (offsetof (struct pthread, member)));            \
       }                                                             \
     __value; })

Definition at line 183 of file tls.h.

#define THREAD_GETMEM_NC (   descr,
  member,
  idx 
)
Value:
({ __typeof (descr->member[0]) __value;                              \
     if (sizeof (__value) == 1)                                             \
       asm volatile ("movb %%fs:%P2(%q3),%b0"                               \
                   : "=q" (__value)                                         \
                   : "0" (0), "i" (offsetof (struct pthread, member[0])),   \
                     "r" (idx));                                     \
     else if (sizeof (__value) == 4)                                        \
       asm volatile ("movl %%fs:%P1(,%q2,4),%0"                             \
                   : "=r" (__value)                                         \
                   : "i" (offsetof (struct pthread, member[0])), "r" (idx));\
     else                                                            \
       {                                                             \
        if (sizeof (__value) != 8)                                   \
          /* There should not be any value with a size other than 1,        \
             4 or 8.  */                                             \
          abort ();                                                  \
                                                                     \
        asm volatile ("movq %%fs:%P1(,%q2,8),%q0"                           \
                     : "=r" (__value)                                       \
                     : "i" (offsetof (struct pthread, member[0])),          \
                      "r" (idx));                                    \
       }                                                             \
     __value; })

Definition at line 207 of file tls.h.

#define THREAD_GSCOPE_FLAG_UNUSED   0

Definition at line 343 of file tls.h.

#define THREAD_GSCOPE_FLAG_USED   1

Definition at line 344 of file tls.h.

#define THREAD_GSCOPE_FLAG_WAIT   2

Definition at line 345 of file tls.h.

Value:
do                                                                   \
    { int __res;                                                     \
      asm volatile ("xchgl %0, %%fs:%P1"                             \
                  : "=r" (__res)                                     \
                  : "i" (offsetof (struct pthread, header.gscope_flag)),    \
                    "0" (THREAD_GSCOPE_FLAG_UNUSED));                       \
      if (__res == THREAD_GSCOPE_FLAG_WAIT)                                 \
       lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE);    \
    }                                                                \
  while (0)

Definition at line 346 of file tls.h.

#define THREAD_GSCOPE_SET_FLAG ( )    THREAD_SETMEM (THREAD_SELF, header.gscope_flag, THREAD_GSCOPE_FLAG_USED)

Definition at line 357 of file tls.h.

#define THREAD_GSCOPE_WAIT ( )    GL(dl_wait_lookup_done) ()

Definition at line 359 of file tls.h.

#define THREAD_SELF
Value:
({ struct pthread *__self;                                           \
     asm ("movq %%fs:%c1,%q0" : "=r" (__self)                               \
         : "i" (offsetof (struct pthread, header.self)));                   \
     __self;})

Definition at line 172 of file tls.h.

#define THREAD_SET_POINTER_GUARD (   value)    THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)

Definition at line 335 of file tls.h.

#define THREAD_SET_STACK_GUARD (   value)    THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)

Definition at line 327 of file tls.h.

#define THREAD_SETMEM (   descr,
  member,
  value 
)
Value:
({ if (sizeof (descr->member) == 1)                                         \
       asm volatile ("movb %b0,%%fs:%P1" :                                  \
                   : "iq" (value),                                   \
                     "i" (offsetof (struct pthread, member)));       \
     else if (sizeof (descr->member) == 4)                                  \
       asm volatile ("movl %0,%%fs:%P1" :                            \
                   : IMM_MODE (value),                               \
                     "i" (offsetof (struct pthread, member)));       \
     else                                                            \
       {                                                             \
        if (sizeof (descr->member) != 8)                             \
          /* There should not be any value with a size other than 1,        \
             4 or 8.  */                                             \
          abort ();                                                  \
                                                                     \
        asm volatile ("movq %q0,%%fs:%P1" :                                 \
                     : IMM_MODE ((unsigned long int) value),                \
                      "i" (offsetof (struct pthread, member)));             \
       }})

Definition at line 242 of file tls.h.

#define THREAD_SETMEM_NC (   descr,
  member,
  idx,
  value 
)
Value:
({ if (sizeof (descr->member[0]) == 1)                               \
       asm volatile ("movb %b0,%%fs:%P1(%q2)" :                             \
                   : "iq" (value),                                   \
                     "i" (offsetof (struct pthread, member[0])),            \
                     "r" (idx));                                     \
     else if (sizeof (descr->member[0]) == 4)                               \
       asm volatile ("movl %0,%%fs:%P1(,%q2,4)" :                           \
                   : IMM_MODE (value),                               \
                     "i" (offsetof (struct pthread, member[0])),            \
                     "r" (idx));                                     \
     else                                                            \
       {                                                             \
        if (sizeof (descr->member[0]) != 8)                                 \
          /* There should not be any value with a size other than 1,        \
             4 or 8.  */                                             \
          abort ();                                                  \
                                                                     \
        asm volatile ("movq %q0,%%fs:%P1(,%q2,8)" :                         \
                     : IMM_MODE ((unsigned long int) value),                \
                      "i" (offsetof (struct pthread, member[0])),           \
                      "r" (idx));                                    \
       }})

Definition at line 264 of file tls.h.

#define TLS_GET_FS ( )    ({ int __seg; __asm ("movl %%fs, %0" : "=q" (__seg)); __seg; })

Definition at line 127 of file tls.h.

#define TLS_INIT_TCB_ALIGN   __alignof__ (struct pthread)

Definition at line 98 of file tls.h.

#define TLS_INIT_TCB_SIZE   sizeof (struct pthread)

Definition at line 95 of file tls.h.

#define TLS_INIT_TP (   thrdescr,
  secondcall 
)
Value:
({ void *_thrdescr = (thrdescr);                                     \
     tcbhead_t *_head = _thrdescr;                                   \
     int _result;                                                    \
                                                                     \
     _head->tcb = _thrdescr;                                                \
     /* For now the thread descriptor is at the same address.  */           \
     _head->self = _thrdescr;                                               \
                                                                     \
     /* It is a simple syscall to set the %fs value for the thread.  */            \
     asm volatile ("syscall"                                                \
                 : "=a" (_result)                                    \
                 : "0" ((unsigned long int) __NR_arch_prctl),               \
                   "D" ((unsigned long int) ARCH_SET_FS),                   \
                   "S" (_thrdescr)                                   \
                 : "memory", "cc", "r11", "cx");                     \
                                                                     \
    _result ? "cannot set %fs base address for thread-local storage" : 0;     \
  })

Definition at line 139 of file tls.h.

#define TLS_SET_FS (   val)    __asm ("movl %0, %%fs" :: "q" (val))

Definition at line 129 of file tls.h.

#define TLS_TCB_ALIGN   __alignof__ (struct pthread)

Definition at line 104 of file tls.h.

#define TLS_TCB_AT_TP   1

Definition at line 108 of file tls.h.

#define TLS_TCB_SIZE   sizeof (struct pthread)

Definition at line 101 of file tls.h.


Typedef Documentation

typedef union dtv dtv_t