OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libpthread / linuxthreads / sysdeps / alpha / tls.h
1 /* Definitions for thread-local data handling.  linuxthreads/Alpha version.
2    Copyright (C) 2002, 2003, 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, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _TLS_H
20 #define _TLS_H
21
22 #ifndef __ASSEMBLER__
23
24 # include <pt-machine.h>
25 # include <stdbool.h>
26 # include <stddef.h>
27
28 /* Type for the dtv.  */
29 typedef union dtv
30 {
31   size_t counter;
32   struct
33   {
34     void *val;
35     bool is_static;
36   } pointer;
37 } dtv_t;
38
39
40 typedef struct
41 {
42   dtv_t *dtv;
43
44   /* Reserved for the thread implementation.  Unused in LinuxThreads.  */
45   void *private;
46 } tcbhead_t;
47 #endif
48
49
50 #ifdef HAVE_TLS_SUPPORT
51
52 /* Signal that TLS support is available.  */
53 # define USE_TLS        1
54
55 # ifndef __ASSEMBLER__
56 /* Get system call information.  */
57 #  include <sysdep.h>
58
59 /* This is the size of the initial TCB.  */
60 #  define TLS_INIT_TCB_SIZE     sizeof (tcbhead_t)
61
62 /* Alignment requirements for the initial TCB.  */
63 #  define TLS_INIT_TCB_ALIGN    __alignof__ (tcbhead_t)
64
65 /* This is the size of the TCB.  */
66 #  define TLS_TCB_SIZE          sizeof (tcbhead_t)
67
68 /* Alignment requirements for the TCB.  */
69 #  define TLS_TCB_ALIGN         __alignof__ (tcbhead_t)
70
71 /* This is the size we need before TCB.  */
72 #  define TLS_PRE_TCB_SIZE      sizeof (struct _pthread_descr_struct)
73
74 /* The DTV is allocated at the TP; the TCB is placed elsewhere.  */
75 #  define TLS_DTV_AT_TP 1
76
77 /* Install the dtv pointer.  The pointer passed is to the element with
78    index -1 which contain the length.  */
79 #  define INSTALL_DTV(TCBP, DTVP) \
80   (((tcbhead_t *) (TCBP))->dtv = (DTVP) + 1)
81
82 /* Install new dtv for current thread.  */
83 #  define INSTALL_NEW_DTV(DTV) \
84   (((tcbhead_t *)__builtin_thread_pointer ())->dtv = (DTV))
85
86 /* Return dtv of given thread descriptor.  */
87 #  define GET_DTV(TCBP) \
88   (((tcbhead_t *) (TCBP))->dtv)
89
90 /* Code to initially initialize the thread pointer.  This might need
91    special attention since 'errno' is not yet available and if the
92    operation can cause a failure 'errno' must not be touched.  */
93 # define TLS_INIT_TP(TCBP, SECONDCALL) \
94   (__builtin_set_thread_pointer (TCBP), 0)
95
96 /* Return the address of the dtv for the current thread.  */
97 #  define THREAD_DTV() \
98   (((tcbhead_t *)__builtin_thread_pointer ())->dtv)
99
100 /* Return the thread descriptor for the current thread.  */
101 #  undef THREAD_SELF
102 #  define THREAD_SELF \
103   ((pthread_descr)__builtin_thread_pointer () - 1)
104
105 #  undef INIT_THREAD_SELF
106 #  define INIT_THREAD_SELF(DESCR, NR) \
107   __builtin_set_thread_pointer ((struct _pthread_descr_struct *)(DESCR) + 1)
108
109 /* Get the thread descriptor definition.  */
110 #  include <linuxthreads/descr.h>
111
112 /* ??? Generic bits of LinuxThreads may call these macros with
113    DESCR set to NULL.  We are expected to be able to reference
114    the "current" value.
115
116    In our case, we'd really prefer to use DESCR, since lots of
117    PAL_code calls would be expensive.  We can only trust that
118    the compiler does its job and unifies the multiple
119    __builtin_thread_pointer instances.  */
120
121 #define THREAD_GETMEM(descr, member) \
122   ((void) sizeof (descr), THREAD_SELF->member)
123 #define THREAD_GETMEM_NC(descr, member) \
124   ((void) sizeof (descr), THREAD_SELF->member)
125 #define THREAD_SETMEM(descr, member, value) \
126   ((void) sizeof (descr), THREAD_SELF->member = (value))
127 #define THREAD_SETMEM_NC(descr, member, value) \
128   ((void) sizeof (descr), THREAD_SELF->member = (value))
129
130 # endif /* HAVE_TLS_SUPPORT */
131 #endif /* __ASSEMBLER__ */
132
133 #endif  /* tls.h */