]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/linuxthreads.old/sysdeps/x86_64/tls.h
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / linuxthreads.old / sysdeps / x86_64 / tls.h
1 /* Definitions for thread-local data handling.  linuxthreads/x86-64 version.
2    Copyright (C) 2002, 2005 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef _TLS_H
21 #define _TLS_H
22
23 #ifndef __ASSEMBLER__
24
25 # include <pt-machine.h>
26 # include <stdbool.h>
27 # include <stddef.h>
28
29 /* Type for the dtv.  */
30 typedef union dtv
31 {
32   size_t counter;
33   struct
34   {
35     void *val;
36     bool is_static;
37   } pointer;
38 } dtv_t;
39
40
41 typedef struct
42 {
43   void *tcb;            /* Pointer to the TCB.  Not necessary the
44                            thread descriptor used by libpthread.  */
45   dtv_t *dtv;
46   void *self;           /* Pointer to the thread descriptor.  */
47   int multiple_threads;
48 } tcbhead_t;
49
50 #else /* __ASSEMBLER__ */
51 # include <tcb-offsets.h>
52 #endif
53
54
55 #ifdef HAVE_TLS_SUPPORT
56
57 /* Signal that TLS support is available.  */
58 # define USE_TLS        1
59
60 # ifndef __ASSEMBLER__
61 /* Get system call information.  */
62 #  include <sysdep.h>
63
64 /* Get the thread descriptor definition.  */
65 #  include <linuxthreads/descr.h>
66
67 /* This is the size of the initial TCB.  */
68 #  define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
69
70 /* Alignment requirements for the initial TCB.  */
71 #  define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
72
73 /* This is the size of the TCB.  */
74 #  define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
75
76 /* Alignment requirements for the TCB.  */
77 #  define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
78
79 /* The TCB can have any size and the memory following the address the
80    thread pointer points to is unspecified.  Allocate the TCB there.  */
81 #  define TLS_TCB_AT_TP 1
82
83
84 /* Install the dtv pointer.  The pointer passed is to the element with
85    index -1 which contain the length.  */
86 #  define INSTALL_DTV(descr, dtvp) \
87   ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
88
89 /* Install new dtv for current thread.  */
90 #  define INSTALL_NEW_DTV(dtv) \
91   ({ struct _pthread_descr_struct *__descr;                                   \
92      THREAD_SETMEM (__descr, p_header.data.dtvp, (dtv)); })
93
94 /* Return dtv of given thread descriptor.  */
95 #  define GET_DTV(descr) \
96   (((tcbhead_t *) (descr))->dtv)
97
98 /* Code to initially initialize the thread pointer.  This might need
99    special attention since 'errno' is not yet available and if the
100    operation can cause a failure 'errno' must not be touched.  */
101 # define TLS_INIT_TP(descr, secondcall)                                       \
102   ({                                                                          \
103     void *_descr = (descr);                                                   \
104     tcbhead_t *head = _descr;                                                 \
105     long int _result;                                                         \
106                                                                               \
107     head->tcb = _descr;                                                       \
108     /* For now the thread descriptor is at the same address.  */              \
109     head->self = _descr;                                                      \
110                                                                               \
111     __asm__ __volatile__ ("syscall"                                                   \
112                   : "=a" (_result)                                            \
113                   : "0" ((unsigned long int) __NR_arch_prctl),                \
114                     "D" ((unsigned long int) ARCH_SET_FS),                    \
115                     "S" (_descr)                                              \
116                   : "memory", "cc", "r11", "cx");                             \
117                                                                               \
118     _result ? "cannot set %fs base address for thread-local storage" : 0;     \
119   })
120
121 /* Indicate that dynamic linker shouldn't try to initialize TLS even
122    when no PT_TLS segments are found in the program and libraries
123    it is linked against.  */
124 #  define TLS_INIT_TP_EXPENSIVE 1
125
126 /* Return the address of the dtv for the current thread.  */
127 #  define THREAD_DTV() \
128   ({ struct _pthread_descr_struct *__descr;                                   \
129      THREAD_GETMEM (__descr, p_header.data.dtvp); })
130
131 # endif /* HAVE_TLS_SUPPORT */
132 #endif /* __ASSEMBLER__ */
133
134 #endif  /* tls.h */