linux: Make fdopendir fail with O_PATH (BZ 30373)
[glibc.git] / sysdeps / nptl / internaltypes.h
blob9d35052c81a4ae19a1ebf0e61d64cc8ec3f95628
1 /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _INTERNALTYPES_H
19 #define _INTERNALTYPES_H 1
21 #include <stdint.h>
22 #include <atomic.h>
23 #include <endian.h>
26 struct pthread_attr
28 /* Scheduler parameters and priority. */
29 struct sched_param schedparam;
30 int schedpolicy;
31 /* Various flags like detachstate, scope, etc. */
32 int flags;
33 /* Size of guard area. */
34 size_t guardsize;
35 /* Stack handling. */
36 void *stackaddr;
37 size_t stacksize;
39 /* Allocated via a call to __pthread_attr_extension once needed. */
40 struct pthread_attr_extension *extension;
41 void *unused;
44 #define ATTR_FLAG_DETACHSTATE 0x0001
45 #define ATTR_FLAG_NOTINHERITSCHED 0x0002
46 #define ATTR_FLAG_SCOPEPROCESS 0x0004
47 #define ATTR_FLAG_STACKADDR 0x0008
48 #define ATTR_FLAG_OLDATTR 0x0010
49 #define ATTR_FLAG_SCHED_SET 0x0020
50 #define ATTR_FLAG_POLICY_SET 0x0040
51 #define ATTR_FLAG_DO_RSEQ 0x0080
53 /* Used to allocate a pthread_attr_t object which is also accessed
54 internally. */
55 union pthread_attr_transparent
57 pthread_attr_t external;
58 struct pthread_attr internal;
61 /* Extension space for pthread attributes. Referenced by the
62 extension member of struct pthread_attr. */
63 struct pthread_attr_extension
65 /* Affinity map. */
66 cpu_set_t *cpuset;
67 size_t cpusetsize;
69 sigset_t sigmask;
70 bool sigmask_set;
73 /* Mutex attribute data structure. */
74 struct pthread_mutexattr
76 /* Identifier for the kind of mutex.
78 Bit 31 is set if the mutex is to be shared between processes.
80 Bit 0 to 30 contain one of the PTHREAD_MUTEX_ values to identify
81 the type of the mutex. */
82 int mutexkind;
86 /* Conditional variable attribute data structure. */
87 struct pthread_condattr
89 /* Combination of values:
91 Bit 0 : flag whether conditional variable will be
92 sharable between processes.
93 Bit 1-COND_CLOCK_BITS: Clock ID. COND_CLOCK_BITS is the number of bits
94 needed to represent the ID of the clock. */
95 int value;
97 #define COND_CLOCK_BITS 1
100 /* Read-write lock variable attribute data structure. */
101 struct pthread_rwlockattr
103 int lockkind;
104 int pshared;
108 /* Barrier data structure. See pthread_barrier_wait for a description
109 of how these fields are used. */
110 struct pthread_barrier
112 unsigned int in;
113 unsigned int current_round;
114 unsigned int count;
115 int shared;
116 unsigned int out;
118 /* See pthread_barrier_wait for a description. */
119 #define BARRIER_IN_THRESHOLD (UINT_MAX/2)
122 /* Barrier variable attribute data structure. */
123 struct pthread_barrierattr
125 int pshared;
129 /* Thread-local data handling. */
130 struct pthread_key_struct
132 /* Sequence numbers. Even numbers indicated vacant entries. Note
133 that zero is even. We use uintptr_t to not require padding on
134 32- and 64-bit machines. On 64-bit machines it helps to avoid
135 wrapping, too. */
136 uintptr_t seq;
138 /* Destructor for the data. */
139 void (*destr) (void *);
142 /* Check whether an entry is unused. */
143 #define KEY_UNUSED(p) (((p) & 1) == 0)
144 /* Check whether a key is usable. We cannot reuse an allocated key if
145 the sequence counter would overflow after the next destroy call.
146 This would mean that we potentially free memory for a key with the
147 same sequence. This is *very* unlikely to happen, A program would
148 have to create and destroy a key 2^31 times (on 32-bit platforms,
149 on 64-bit platforms that would be 2^63). If it should happen we
150 simply don't use this specific key anymore. */
151 #define KEY_USABLE(p) (((uintptr_t) (p)) < ((uintptr_t) ((p) + 2)))
154 /* Handling of read-write lock data. */
155 // XXX For now there is only one flag. Maybe more in future.
156 #define RWLOCK_RECURSIVE(rwlock) ((rwlock)->__data.__flags != 0)
159 /* Semaphore variable structure. */
160 struct new_sem
162 #if __HAVE_64B_ATOMICS
163 /* The data field holds both value (in the least-significant 32 bits) and
164 nwaiters. */
165 # if __BYTE_ORDER == __LITTLE_ENDIAN
166 # define SEM_VALUE_OFFSET 0
167 # elif __BYTE_ORDER == __BIG_ENDIAN
168 # define SEM_VALUE_OFFSET 1
169 # else
170 # error Unsupported byte order.
171 # endif
172 # define SEM_NWAITERS_SHIFT 32
173 # define SEM_VALUE_MASK (~(unsigned int)0)
174 uint64_t data;
175 int private;
176 int pad;
177 #else
178 # define SEM_VALUE_SHIFT 1
179 # define SEM_NWAITERS_MASK ((unsigned int)1)
180 unsigned int value;
181 int private;
182 int pad;
183 unsigned int nwaiters;
184 #endif
187 struct old_sem
189 unsigned int value;
193 /* Compatibility type for old conditional variable interfaces. */
194 typedef struct
196 pthread_cond_t *cond;
197 } pthread_cond_2_0_t;
199 #endif /* internaltypes.h */