(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / x86_64 / tls.h
blob63feebdb2c64bdc593c2e686958d87e810683be8
1 /* Definitions for thread-local data handling. linuxthreads/x86-64 version.
2 Copyright (C) 2002 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
18 02111-1307 USA. */
20 #ifndef _TLS_H
21 #define _TLS_H
23 #ifndef __ASSEMBLER__
25 # include <pt-machine.h>
26 # include <stddef.h>
28 /* Type for the dtv. */
29 typedef union dtv
31 size_t counter;
32 void *pointer;
33 } dtv_t;
36 typedef struct
38 void *tcb; /* Pointer to the TCB. Not necessary the
39 thread descriptor used by libpthread. */
40 dtv_t *dtv;
41 void *self; /* Pointer to the thread descriptor. */
42 int multiple_threads;
43 } tcbhead_t;
45 #else /* __ASSEMBLER__ */
46 # include <tcb-offsets.h>
47 #endif
50 #ifdef HAVE_TLS_SUPPORT
52 /* Signal that TLS support is available. */
53 # define USE_TLS 1
55 # ifndef __ASSEMBLER__
56 /* Get system call information. */
57 # include <sysdep.h>
59 /* Get the thread descriptor definition. */
60 # include <linuxthreads/descr.h>
62 /* This is the size of the initial TCB. */
63 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
65 /* Alignment requirements for the initial TCB. */
66 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
68 /* This is the size of the TCB. */
69 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
71 /* Alignment requirements for the TCB. */
72 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
74 /* The TCB can have any size and the memory following the address the
75 thread pointer points to is unspecified. Allocate the TCB there. */
76 # define TLS_TCB_AT_TP 1
79 /* Install the dtv pointer. The pointer passed is to the element with
80 index -1 which contain the length. */
81 # define INSTALL_DTV(descr, dtvp) \
82 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
84 /* Install new dtv for current thread. */
85 # define INSTALL_NEW_DTV(dtv) \
86 ({ struct _pthread_descr_struct *__descr; \
87 THREAD_SETMEM (__descr, p_header.data.dtvp, (dtv)); })
89 /* Return dtv of given thread descriptor. */
90 # define GET_DTV(descr) \
91 (((tcbhead_t *) (descr))->dtv)
93 /* Code to initially initialize the thread pointer. This might need
94 special attention since 'errno' is not yet available and if the
95 operation can cause a failure 'errno' must not be touched. */
96 # define TLS_INIT_TP(descr, secondcall) \
97 ({ \
98 void *_descr = (descr); \
99 tcbhead_t *head = _descr; \
100 long int _result; \
102 head->tcb = _descr; \
103 /* For now the thread descriptor is at the same address. */ \
104 head->self = _descr; \
106 asm volatile ("syscall" \
107 : "=a" (_result) \
108 : "0" ((unsigned long int) __NR_arch_prctl), \
109 "D" ((unsigned long int) ARCH_SET_FS), \
110 "S" (_descr) \
111 : "memory", "cc", "r11", "cx"); \
113 _result ? "cannot set %fs base address for thread-local storage" : 0; \
116 /* Indicate that dynamic linker shouldn't try to initialize TLS even
117 when no PT_TLS segments are found in the program and libraries
118 it is linked against. */
119 # define TLS_INIT_TP_EXPENSIVE 1
121 /* Return the address of the dtv for the current thread. */
122 # define THREAD_DTV() \
123 ({ struct _pthread_descr_struct *__descr; \
124 THREAD_GETMEM (__descr, p_header.data.dtvp); })
126 # endif /* HAVE_TLS_SUPPORT */
127 #endif /* __ASSEMBLER__ */
129 #endif /* tls.h */