]> git.ipfire.org Git - thirdparty/glibc.git/blob - hurd/hurd/threadvar.h
1998-10-19 Roland McGrath <roland@baalperazim.frob.com>
[thirdparty/glibc.git] / hurd / hurd / threadvar.h
1 /* Internal per-thread variables for the Hurd.
2 Copyright (C) 1994, 95, 97, 98 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #ifndef _HURD_THREADVAR_H
21 #define _HURD_THREADVAR_H
22
23 /* The per-thread variables are found by ANDing this mask
24 with the value of the stack pointer and then adding this offset.
25
26 In the multi-threaded case, cthreads initialization sets
27 __hurd_threadvar_stack_mask to ~(cthread_stack_size - 1), a mask which
28 finds the base of the fixed-size cthreads stack; and
29 __hurd_threadvar_stack_offset to a small offset that skips the data
30 cthreads itself maintains at the base of each thread's stack.
31
32 In the single-threaded case, __hurd_threadvar_stack_mask is zero, so the
33 stack pointer is ignored; and __hurd_threadvar_stack_offset gives the
34 address of a small allocated region which contains the variables for the
35 single thread. */
36
37 extern unsigned long int __hurd_threadvar_stack_mask;
38 extern unsigned long int __hurd_threadvar_stack_offset;
39
40 /* A special case must always be made for the signal thread. Even when there
41 is only one user thread and an allocated region can be used for the user
42 thread's variables, the signal thread needs to have its own location for
43 per-thread variables. The variables __hurd_sigthread_stack_base and
44 __hurd_sigthread_stack_end define the bounds of the stack used by the
45 signal thread, so that thread can always be specifically identified. */
46
47 extern unsigned long int __hurd_sigthread_stack_base;
48 extern unsigned long int __hurd_sigthread_stack_end;
49 extern unsigned long int *__hurd_sigthread_variables;
50
51
52 /* At the location described by the two variables above,
53 there are __hurd_threadvar_max `unsigned long int's of per-thread data. */
54 extern unsigned int __hurd_threadvar_max;
55
56 /* These values are the indices for the standard per-thread variables. */
57 enum __hurd_threadvar_index
58 {
59 _HURD_THREADVAR_MIG_REPLY, /* Reply port for MiG user stub functions. */
60 _HURD_THREADVAR_ERRNO, /* `errno' value for this thread. */
61 _HURD_THREADVAR_SIGSTATE, /* This thread's `struct hurd_sigstate'. */
62 _HURD_THREADVAR_DYNAMIC_USER, /* Dynamically-assigned user variables. */
63 _HURD_THREADVAR_MALLOC, /* For use of malloc. */
64 _HURD_THREADVAR_DL_ERROR, /* For use of -ldl and dynamic linker. */
65 _HURD_THREADVAR_MAX /* Default value for __hurd_threadvar_max. */
66 };
67
68
69 #ifndef _EXTERN_INLINE
70 #define _EXTERN_INLINE extern __inline
71 #endif
72
73 /* Return the location of the value for the per-thread variable with index
74 INDEX used by the thread whose stack pointer is SP. */
75
76 _EXTERN_INLINE unsigned long int *
77 __hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index,
78 void *__sp)
79 {
80 unsigned long int __stack = (unsigned long int) __sp;
81 return &((__stack >= __hurd_sigthread_stack_base &&
82 __stack < __hurd_sigthread_stack_end)
83 ? __hurd_sigthread_variables
84 : (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) +
85 __hurd_threadvar_stack_offset))[__index];
86 }
87
88 #include <machine-sp.h> /* Define __thread_stack_pointer. */
89
90 /* Return the location of the current thread's value for the
91 per-thread variable with index INDEX. */
92
93 extern unsigned long int *
94 __hurd_threadvar_location (enum __hurd_threadvar_index __index)
95 /* This declaration tells the compiler that the value is constant
96 given the same argument. We assume this won't be called twice from
97 the same stack frame by different threads. */
98 __attribute__ ((__const__));
99
100 _EXTERN_INLINE unsigned long int *
101 __hurd_threadvar_location (enum __hurd_threadvar_index __index)
102 {
103 return __hurd_threadvar_location_from_sp (__index,
104 __thread_stack_pointer ());
105 }
106
107 /* Return the current thread's location for `errno'.
108 The syntax of this function allows redeclarations like `int errno'. */
109 _EXTERN_INLINE int *
110 __hurd_errno_location (void)
111 {
112 return (int *) __hurd_threadvar_location (_HURD_THREADVAR_ERRNO);
113 }
114
115
116 #endif /* hurd/threadvar.h */