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.
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.
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.
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
25 # include <pt-machine.h>
29 /* Type for the dtv. */
43 void *tcb; /* Pointer to the TCB. Not necessary the
44 thread descriptor used by libpthread. */
46 void *self; /* Pointer to the thread descriptor. */
50 #else /* __ASSEMBLER__ */
51 # include <tcb-offsets.h>
55 #ifdef HAVE_TLS_SUPPORT
57 /* Signal that TLS support is available. */
60 # ifndef __ASSEMBLER__
61 /* Get system call information. */
64 /* Get the thread descriptor definition. */
65 # include <linuxthreads/descr.h>
67 /* This is the size of the initial TCB. */
68 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
70 /* Alignment requirements for the initial TCB. */
71 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
73 /* This is the size of the TCB. */
74 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
76 /* Alignment requirements for the TCB. */
77 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
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
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
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)); })
94 /* Return dtv of given thread descriptor. */
95 # define GET_DTV(descr) \
96 (((tcbhead_t *) (descr))->dtv)
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) \
103 void *_descr = (descr); \
104 tcbhead_t *head = _descr; \
107 head->tcb = _descr; \
108 /* For now the thread descriptor is at the same address. */ \
109 head->self = _descr; \
111 __asm__ __volatile__ ("syscall" \
113 : "0" ((unsigned long int) __NR_arch_prctl), \
114 "D" ((unsigned long int) ARCH_SET_FS), \
116 : "memory", "cc", "r11", "cx"); \
118 _result ? "cannot set %fs base address for thread-local storage" : 0; \
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
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); })
131 # endif /* HAVE_TLS_SUPPORT */
132 #endif /* __ASSEMBLER__ */