Update copyright notices with scripts/update-copyrights
[glibc.git] / hurd / hurd / threadvar.h
blobb62f5a6d86d12baa0dbba65a55ff67941bd138f5
1 /* Internal per-thread variables for the Hurd.
2 Copyright (C) 1994-2014 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, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _HURD_THREADVAR_H
20 #define _HURD_THREADVAR_H
22 #include <features.h>
24 /* The per-thread variables are found by ANDing this mask
25 with the value of the stack pointer and then adding this offset.
27 In the multi-threaded case, cthreads initialization sets
28 __hurd_threadvar_stack_mask to ~(cthread_stack_size - 1), a mask which
29 finds the base of the fixed-size cthreads stack; and
30 __hurd_threadvar_stack_offset to a small offset that skips the data
31 cthreads itself maintains at the base of each thread's stack.
33 In the single-threaded case, __hurd_threadvar_stack_mask is zero, so the
34 stack pointer is ignored; and __hurd_threadvar_stack_offset gives the
35 address of a small allocated region which contains the variables for the
36 single thread. */
38 extern unsigned long int __hurd_threadvar_stack_mask;
39 extern unsigned long int __hurd_threadvar_stack_offset;
41 /* A special case must always be made for the signal thread. Even when there
42 is only one user thread and an allocated region can be used for the user
43 thread's variables, the signal thread needs to have its own location for
44 per-thread variables. The variables __hurd_sigthread_stack_base and
45 __hurd_sigthread_stack_end define the bounds of the stack used by the
46 signal thread, so that thread can always be specifically identified. */
48 extern unsigned long int __hurd_sigthread_stack_base;
49 extern unsigned long int __hurd_sigthread_stack_end;
50 extern unsigned long int *__hurd_sigthread_variables;
53 /* At the location described by the two variables above,
54 there are __hurd_threadvar_max `unsigned long int's of per-thread data. */
55 extern unsigned int __hurd_threadvar_max;
57 /* These values are the indices for the standard per-thread variables. */
58 enum __hurd_threadvar_index
60 _HURD_THREADVAR_MIG_REPLY, /* Reply port for MiG user stub functions. */
61 _HURD_THREADVAR_ERRNO, /* `errno' value for this thread. */
62 _HURD_THREADVAR_SIGSTATE, /* This thread's `struct hurd_sigstate'. */
63 _HURD_THREADVAR_DYNAMIC_USER, /* Dynamically-assigned user variables. */
64 _HURD_THREADVAR_MALLOC, /* For use of malloc. */
65 _HURD_THREADVAR_DL_ERROR, /* For use of -ldl and dynamic linker. */
66 _HURD_THREADVAR_RPC_VARS, /* For state of RPC functions. */
67 _HURD_THREADVAR_LOCALE, /* For thread-local locale setting. */
68 _HURD_THREADVAR_CTYPE_B, /* Cache of thread-local locale data. */
69 _HURD_THREADVAR_CTYPE_TOLOWER, /* Cache of thread-local locale data. */
70 _HURD_THREADVAR_CTYPE_TOUPPER, /* Cache of thread-local locale data. */
71 _HURD_THREADVAR_MAX /* Default value for __hurd_threadvar_max. */
75 #ifndef _HURD_THREADVAR_H_EXTERN_INLINE
76 #define _HURD_THREADVAR_H_EXTERN_INLINE __extern_inline
77 #endif
79 /* Return the location of the value for the per-thread variable with index
80 INDEX used by the thread whose stack pointer is SP. */
82 extern unsigned long int *__hurd_threadvar_location_from_sp
83 (enum __hurd_threadvar_index __index, void *__sp);
84 _HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
85 __hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index,
86 void *__sp)
88 unsigned long int __stack = (unsigned long int) __sp;
89 return &((__stack >= __hurd_sigthread_stack_base &&
90 __stack < __hurd_sigthread_stack_end)
91 ? __hurd_sigthread_variables
92 : (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) +
93 __hurd_threadvar_stack_offset))[__index];
96 #include <machine-sp.h> /* Define __thread_stack_pointer. */
98 /* Return the location of the current thread's value for the
99 per-thread variable with index INDEX. */
101 extern unsigned long int *
102 __hurd_threadvar_location (enum __hurd_threadvar_index __index) __THROW
103 /* This declaration tells the compiler that the value is constant
104 given the same argument. We assume this won't be called twice from
105 the same stack frame by different threads. */
106 __attribute__ ((__const__));
108 _HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
109 __hurd_threadvar_location (enum __hurd_threadvar_index __index)
111 return __hurd_threadvar_location_from_sp (__index,
112 __thread_stack_pointer ());
116 #endif /* hurd/threadvar.h */