]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* Internal per-thread variables for the Hurd. |
c84142e8 UD |
2 | Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | |
28f540f4 | 4 | |
c84142e8 UD |
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. | |
28f540f4 | 9 | |
c84142e8 UD |
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. | |
28f540f4 | 14 | |
c84142e8 UD |
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. */ | |
28f540f4 RM |
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. */ | |
c84142e8 | 36 | |
28f540f4 RM |
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_MAX /* Default value for __hurd_threadvar_max. */ | |
64 | }; | |
65 | ||
66 | ||
67 | #ifndef _EXTERN_INLINE | |
68 | #define _EXTERN_INLINE extern __inline | |
69 | #endif | |
70 | ||
71 | /* Return the location of the value for the per-thread variable with index | |
72 | INDEX used by the thread whose stack pointer is SP. */ | |
73 | ||
74 | _EXTERN_INLINE unsigned long int * | |
75 | __hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index, | |
76 | void *__sp) | |
77 | { | |
78 | unsigned long int __stack = (unsigned long int) __sp; | |
79 | return &((__stack >= __hurd_sigthread_stack_base && | |
80 | __stack < __hurd_sigthread_stack_end) | |
81 | ? __hurd_sigthread_variables | |
82 | : (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) + | |
83 | __hurd_threadvar_stack_offset))[__index]; | |
84 | } | |
85 | ||
86 | #include <machine-sp.h> /* Define __thread_stack_pointer. */ | |
87 | ||
88 | /* Return the location of the current thread's value for the | |
89 | per-thread variable with index INDEX. */ | |
90 | ||
d6e2f671 RM |
91 | extern unsigned long int * |
92 | __hurd_threadvar_location (enum __hurd_threadvar_index __index) | |
93 | /* This declaration tells the compiler that the value is constant | |
94 | given the same argument. We assume this won't be called twice from | |
95 | the same stack frame by different threads. */ | |
96 | __attribute__ ((__const__)); | |
97 | ||
28f540f4 RM |
98 | _EXTERN_INLINE unsigned long int * |
99 | __hurd_threadvar_location (enum __hurd_threadvar_index __index) | |
100 | { | |
101 | return __hurd_threadvar_location_from_sp (__index, | |
102 | __thread_stack_pointer ()); | |
103 | } | |
104 | ||
105 | /* Return the current thread's location for `errno'. | |
106 | The syntax of this function allows redeclarations like `int errno'. */ | |
107 | _EXTERN_INLINE int * | |
108 | __hurd_errno_location (void) | |
109 | { | |
110 | return (int *) __hurd_threadvar_location (_HURD_THREADVAR_ERRNO); | |
111 | } | |
112 | ||
113 | ||
114 | #endif /* hurd/threadvar.h */ |