yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 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, 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 | dtv_t *dtv; |
| 44 | |
| 45 | /* Reserved for the thread implementation. Unused in LinuxThreads. */ |
| 46 | void *private; |
| 47 | } tcbhead_t; |
| 48 | #endif |
| 49 | |
| 50 | |
| 51 | #ifdef HAVE_TLS_SUPPORT |
| 52 | |
| 53 | /* Signal that TLS support is available. */ |
| 54 | # define USE_TLS 1 |
| 55 | |
| 56 | # ifndef __ASSEMBLER__ |
| 57 | /* Get system call information. */ |
| 58 | # include <sysdep.h> |
| 59 | |
| 60 | /* This is the size of the initial TCB. */ |
| 61 | # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) |
| 62 | |
| 63 | /* Alignment requirements for the initial TCB. */ |
| 64 | # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t) |
| 65 | |
| 66 | /* This is the size of the TCB. */ |
| 67 | # define TLS_TCB_SIZE sizeof (tcbhead_t) |
| 68 | |
| 69 | /* Alignment requirements for the TCB. */ |
| 70 | # define TLS_TCB_ALIGN __alignof__ (tcbhead_t) |
| 71 | |
| 72 | /* This is the size we need before TCB. */ |
| 73 | # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct) |
| 74 | |
| 75 | /* The DTV is allocated at the TP; the TCB is placed elsewhere. */ |
| 76 | # define TLS_DTV_AT_TP 1 |
| 77 | |
| 78 | /* Install the dtv pointer. The pointer passed is to the element with |
| 79 | index -1 which contain the length. */ |
| 80 | # define INSTALL_DTV(TCBP, DTVP) \ |
| 81 | (((tcbhead_t *) (TCBP))->dtv = (DTVP) + 1) |
| 82 | |
| 83 | /* Install new dtv for current thread. */ |
| 84 | # define INSTALL_NEW_DTV(DTV) \ |
| 85 | (((tcbhead_t *)__builtin_thread_pointer ())->dtv = (DTV)) |
| 86 | |
| 87 | /* Return dtv of given thread descriptor. */ |
| 88 | # define GET_DTV(TCBP) \ |
| 89 | (((tcbhead_t *) (TCBP))->dtv) |
| 90 | |
| 91 | /* Code to initially initialize the thread pointer. This might need |
| 92 | special attention since 'errno' is not yet available and if the |
| 93 | operation can cause a failure 'errno' must not be touched. */ |
| 94 | # define TLS_INIT_TP(TCBP, SECONDCALL) \ |
| 95 | (__builtin_set_thread_pointer (TCBP), 0) |
| 96 | |
| 97 | /* Return the address of the dtv for the current thread. */ |
| 98 | # define THREAD_DTV() \ |
| 99 | (((tcbhead_t *)__builtin_thread_pointer ())->dtv) |
| 100 | |
| 101 | /* Return the thread descriptor for the current thread. */ |
| 102 | # undef THREAD_SELF |
| 103 | # define THREAD_SELF \ |
| 104 | ((pthread_descr)__builtin_thread_pointer () - 1) |
| 105 | |
| 106 | # undef INIT_THREAD_SELF |
| 107 | # define INIT_THREAD_SELF(DESCR, NR) \ |
| 108 | __builtin_set_thread_pointer ((struct _pthread_descr_struct *)(DESCR) + 1) |
| 109 | |
| 110 | /* Get the thread descriptor definition. */ |
| 111 | # include <linuxthreads/descr.h> |
| 112 | |
| 113 | /* ??? Generic bits of LinuxThreads may call these macros with |
| 114 | DESCR set to NULL. We are expected to be able to reference |
| 115 | the "current" value. |
| 116 | |
| 117 | In our case, we'd really prefer to use DESCR, since lots of |
| 118 | PAL_code calls would be expensive. We can only trust that |
| 119 | the compiler does its job and unifies the multiple |
| 120 | __builtin_thread_pointer instances. */ |
| 121 | |
| 122 | #define THREAD_GETMEM(descr, member) \ |
| 123 | ((void) sizeof (descr), THREAD_SELF->member) |
| 124 | #define THREAD_GETMEM_NC(descr, member) \ |
| 125 | ((void) sizeof (descr), THREAD_SELF->member) |
| 126 | #define THREAD_SETMEM(descr, member, value) \ |
| 127 | ((void) sizeof (descr), THREAD_SELF->member = (value)) |
| 128 | #define THREAD_SETMEM_NC(descr, member, value) \ |
| 129 | ((void) sizeof (descr), THREAD_SELF->member = (value)) |
| 130 | |
| 131 | # endif /* HAVE_TLS_SUPPORT */ |
| 132 | #endif /* __ASSEMBLER__ */ |
| 133 | |
| 134 | #endif /* tls.h */ |