Update.
[platform/upstream/glibc.git] / linuxthreads / sysdeps / sh / tls.h
1 /* Definition for thread-local data handling.  linuxthreads/SH version.
2    Copyright (C) 2002 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 #include <stddef.h>
24
25 #include <pt-machine.h>
26
27 /* Type for the dtv.  */
28 typedef union dtv
29 {
30   size_t counter;
31   void *pointer;
32 } dtv_t;
33
34
35 typedef struct
36 {
37   void *tcb;            /* Pointer to the TCB.  Not necessary the
38                            thread descriptor used by libpthread.  */
39   dtv_t *dtv;
40   void *self;           /* Pointer to the thread descriptor.  */
41 } tcbhead_t;
42
43
44 /* We can support TLS only if the floating-stack support is available.  */
45 #if defined FLOATING_STACKS && defined HAVE_TLS_SUPPORT
46
47 /* Get system call information.  */
48 # include <sysdep.h>
49
50 /* Signal that TLS support is available.  */
51 # define USE_TLS        1
52
53
54 /* Get the thread descriptor definition.  */
55 # include <linuxthreads/descr.h>
56
57 /* This is the size of the initial TCB.  */
58 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
59
60 /* Alignment requirements for the initial TCB.  */
61 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
62
63 /* This is the size of the TCB.  */
64 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
65
66 /* Alignment requirements for the TCB.  */
67 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
68
69 /* The TLS blocks start right after the TCB.  */
70 # define TLS_DTV_AT_TP  1
71
72
73 /* Install the dtv pointer.  The pointer passed is to the element with
74    index -1 which contain the length.  */
75 # define INSTALL_DTV(descr, dtvp) \
76   ((tcbhead_t *) descr)->dtv = dtvp + 1
77
78 /* Install new dtv for current thread.  */
79 # define INSTALL_NEW_DTV(dtv) \
80   ({ struct _pthread_descr_struct *__descr;                                   \
81      THREAD_SETMEM (__descr, p_header.data.dtvp, dtv); })
82
83 /* Return dtv of given thread descriptor.  */
84 # define GET_DTV(descr) \
85   (((tcbhead_t *) descr)->dtv)
86
87 /* Code to initially initialize the thread pointer.  This might need
88    special attention since 'errno' is not yet available and if the
89    operation can cause a failure 'errno' must not be touched.  */
90 # define TLS_INIT_TP(descr) \
91   do {                                                                        \
92     void *_descr = (descr);                                                   \
93     int result;                                                               \
94     tcbhead_t *head = _descr;                                                 \
95                                                                               \
96     head->tcb = _descr;                                                       \
97     /* For now the thread descriptor is at the same address.  */                      \
98     head->self = _descr;                                                      \
99                                                                               \
100     asm ("ldc %0,gbr" : : "r" (_descr));                                      \
101   } while (0)
102
103
104 /* Return the address of the dtv for the current thread.  */
105 # define THREAD_DTV() \
106   ({ struct _pthread_descr_struct *__descr;                                   \
107      THREAD_GETMEM (__descr, p_header.data.dtvp); })
108
109 #endif  /* FLOATING_STACKS && HAVE_TLS_SUPPORT */
110
111 #endif  /* tls.h */