]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/_structs.h
xnu-1699.26.8.tar.gz
[apple/xnu.git] / bsd / sys / _structs.h
1 /*
2 * Copyright (c) 2004-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <sys/cdefs.h>
30 #include <sys/_types.h>
31
32 #ifdef __need_ucontext_t
33 #ifndef __need_struct_ucontext
34 #define __need_struct_ucontext
35 #endif /* __need_struct_ucontext */
36 #endif /* __need_ucontext_t */
37
38 #ifdef __need_ucontext64_t
39 #ifndef __need_struct_ucontext64
40 #define __need_struct_ucontext64
41 #endif /* __need_struct_ucontext64 */
42 #endif /* __need_ucontext64_t */
43
44 #ifdef __need_struct_ucontext
45 #ifndef __need_struct_mcontext
46 #define __need_struct_mcontext
47 #endif /* __need_struct_mcontext */
48 #endif /* __need_struct_ucontext */
49
50 #ifdef __need_struct_ucontext64
51 #ifndef __need_struct_mcontext64
52 #define __need_struct_mcontext64
53 #endif /* __need_struct_mcontext64 */
54 #endif /* __need_struct_ucontext64 */
55
56 #if defined(__need_struct_mcontext) || defined(__need_struct_mcontext64)
57 #include <machine/_structs.h>
58 #endif /* __need_struct_mcontext || __need_struct_mcontext64 */
59
60 #if defined(__need_stack_t) || defined(__need_struct_ucontext) || defined(__need_struct_ucontext64)
61 #ifndef __need_struct_sigaltstack
62 #define __need_struct_sigaltstack
63 #endif /* __need_struct_sigaltstack */
64 #endif /* __need_stack_t || __need_struct_ucontext || __need_struct_ucontext64 */
65
66 #ifdef __need_struct_sigaltstack
67 #undef __need_struct_sigaltstack
68 /* Structure used in sigaltstack call. */
69 #ifndef _STRUCT_SIGALTSTACK
70 #if __DARWIN_UNIX03
71 #define _STRUCT_SIGALTSTACK struct __darwin_sigaltstack
72 #else /* !__DARWIN_UNIX03 */
73 #define _STRUCT_SIGALTSTACK struct sigaltstack
74 #endif /* __DARWIN_UNIX03 */
75 _STRUCT_SIGALTSTACK
76 {
77 void *ss_sp; /* signal stack base */
78 __darwin_size_t ss_size; /* signal stack length */
79 int ss_flags; /* SA_DISABLE and/or SA_ONSTACK */
80 };
81 #endif /* _STRUCT_SIGALTSTACK */
82 #endif /* __need_struct_sigaltstack */
83
84 #ifdef __need_struct_timespec
85 #undef __need_struct_timespec
86 #ifndef _STRUCT_TIMESPEC
87 #define _STRUCT_TIMESPEC struct timespec
88 _STRUCT_TIMESPEC
89 {
90 __darwin_time_t tv_sec;
91 long tv_nsec;
92 };
93 #endif /* _STRUCT_TIMESPEC */
94 #endif /* __need_struct_timespec */
95
96 #ifdef __need_struct_timeval
97 #undef __need_struct_timeval
98 #ifndef _STRUCT_TIMEVAL
99 #define _STRUCT_TIMEVAL struct timeval
100 _STRUCT_TIMEVAL
101 {
102 __darwin_time_t tv_sec; /* seconds */
103 __darwin_suseconds_t tv_usec; /* and microseconds */
104 };
105 #endif /* _STRUCT_TIMEVAL */
106 #endif /* __need_struct_timeval */
107
108 #ifdef __need_struct_timeval32
109 #undef __need_struct_timeval32
110 #ifndef _STRUCT_TIMEVAL32
111 #define _STRUCT_TIMEVAL32 struct timeval32
112 _STRUCT_TIMEVAL32
113 {
114 __int32_t tv_sec; /* seconds */
115 __int32_t tv_usec; /* and microseconds */
116 };
117 #endif /* _STRUCT_TIMEVAL32 */
118 #endif /* __need_struct_timeval32 */
119
120 #ifdef __need_struct_ucontext
121 #undef __need_struct_ucontext
122 #ifndef _STRUCT_UCONTEXT
123 #if __DARWIN_UNIX03
124 #define _STRUCT_UCONTEXT struct __darwin_ucontext
125 #else /* !__DARWIN_UNIX03 */
126 #define _STRUCT_UCONTEXT struct ucontext
127 #endif /* __DARWIN_UNIX03 */
128 _STRUCT_UCONTEXT
129 {
130 int uc_onstack;
131 __darwin_sigset_t uc_sigmask; /* signal mask used by this context */
132 _STRUCT_SIGALTSTACK uc_stack; /* stack used by this context */
133 _STRUCT_UCONTEXT *uc_link; /* pointer to resuming context */
134 __darwin_size_t uc_mcsize; /* size of the machine context passed in */
135 _STRUCT_MCONTEXT *uc_mcontext; /* pointer to machine specific context */
136 #ifdef _XOPEN_SOURCE
137 _STRUCT_MCONTEXT __mcontext_data;
138 #endif /* _XOPEN_SOURCE */
139 };
140 #endif /* _STRUCT_UCONTEXT */
141 #endif /* __need_struct_ucontext */
142
143 #ifdef __need_struct_ucontext64
144 #undef __need_struct_ucontext64
145 #ifndef _STRUCT_UCONTEXT64
146 #if __DARWIN_UNIX03
147 #define _STRUCT_UCONTEXT64 struct __darwin_ucontext64
148 #else /* !__DARWIN_UNIX03 */
149 #define _STRUCT_UCONTEXT64 struct ucontext64
150 #endif /* __DARWIN_UNIX03 */
151 _STRUCT_UCONTEXT64
152 {
153 int uc_onstack;
154 __darwin_sigset_t uc_sigmask; /* signal mask used by this context */
155 _STRUCT_SIGALTSTACK uc_stack; /* stack used by this context */
156 _STRUCT_UCONTEXT64 *uc_link; /* pointer to resuming context */
157 __darwin_size_t uc_mcsize; /* size of the machine context passed in */
158 _STRUCT_MCONTEXT64 *uc_mcontext64; /* pointer to machine specific context */
159 };
160 #endif /* _STRUCT_UCONTEXT64 */
161 #endif /* __need_struct_ucontext64 */
162
163 #ifdef KERNEL
164 /* LP64 version of struct timespec. time_t is a long and must grow when
165 * we're dealing with a 64-bit process.
166 * WARNING - keep in sync with struct timespec
167 */
168 #ifdef __need_struct_user_timespec
169 #undef __need_struct_user_timespec
170 #ifndef _STRUCT_USER_TIMESPEC
171 #define _STRUCT_USER_TIMESPEC struct user_timespec
172 _STRUCT_USER_TIMESPEC
173 {
174 user_time_t tv_sec; /* seconds */
175 user_long_t tv_nsec; /* and nanoseconds */
176 };
177 #endif /* _STRUCT_USER_TIMESPEC */
178 #endif /* __need_struct_user_timespec */
179
180 #ifdef __need_struct_user64_timespec
181 #undef __need_struct_user64_timespec
182 #ifndef _STRUCT_USER64_TIMESPEC
183 #define _STRUCT_USER64_TIMESPEC struct user64_timespec
184 _STRUCT_USER64_TIMESPEC
185 {
186 user64_time_t tv_sec; /* seconds */
187 user64_long_t tv_nsec; /* and nanoseconds */
188 };
189 #endif /* _STRUCT_USER64_TIMESPEC */
190 #endif /* __need_struct_user64_timespec */
191
192 #ifdef __need_struct_user32_timespec
193 #undef __need_struct_user32_timespec
194 #ifndef _STRUCT_USER32_TIMESPEC
195 #define _STRUCT_USER32_TIMESPEC struct user32_timespec
196 _STRUCT_USER32_TIMESPEC
197 {
198 user32_time_t tv_sec; /* seconds */
199 user32_long_t tv_nsec; /* and nanoseconds */
200 };
201 #endif /* _STRUCT_USER32_TIMESPEC */
202 #endif /* __need_struct_user32_timespec */
203
204 #ifdef __need_struct_user_timeval
205 #undef __need_struct_user_timeval
206 #ifndef _STRUCT_USER_TIMEVAL
207 #define _STRUCT_USER_TIMEVAL struct user_timeval
208 _STRUCT_USER_TIMEVAL
209 {
210 user_time_t tv_sec; /* seconds */
211 __int32_t tv_usec; /* and microseconds */
212 };
213 #endif /* _STRUCT_USER_TIMEVAL */
214 #endif /* __need_struct_user_timeval */
215
216 #ifdef __need_struct_user64_timeval
217 #undef __need_struct_user64_timeval
218 #ifndef _STRUCT_USER64_TIMEVAL
219 #define _STRUCT_USER64_TIMEVAL struct user64_timeval
220 _STRUCT_USER64_TIMEVAL
221 {
222 user64_time_t tv_sec; /* seconds */
223 __int32_t tv_usec; /* and microseconds */
224 };
225 #endif /* _STRUCT_USER64_TIMEVAL */
226 #endif /* __need_struct_user64_timeval */
227
228 #ifdef __need_struct_user32_timeval
229 #undef __need_struct_user32_timeval
230 #ifndef _STRUCT_USER32_TIMEVAL
231 #define _STRUCT_USER32_TIMEVAL struct user32_timeval
232 _STRUCT_USER32_TIMEVAL
233 {
234 user32_time_t tv_sec; /* seconds */
235 __int32_t tv_usec; /* and microseconds */
236 };
237 #endif /* _STRUCT_USER32_TIMEVAL */
238 #endif /* __need_struct_user32_timeval */
239
240 #ifdef __need_struct_user64_itimerval
241 #undef __need_struct_user64_itimerval
242 #ifndef _STRUCT_USER64_ITIMERVAL
243 #define _STRUCT_USER64_ITIMERVAL struct user64_itimerval
244 _STRUCT_USER64_ITIMERVAL
245 {
246 _STRUCT_USER64_TIMEVAL it_interval; /* timer interval */
247 _STRUCT_USER64_TIMEVAL it_value; /* current value */
248 };
249 #endif /* _STRUCT_USER64_TIMEVAL */
250 #endif /* __need_struct_user64_itimerval */
251
252 #ifdef __need_struct_user32_itimerval
253 #undef __need_struct_user32_itimerval
254 #ifndef _STRUCT_USER32_ITIMERVAL
255 #define _STRUCT_USER32_ITIMERVAL struct user32_itimerval
256 _STRUCT_USER32_ITIMERVAL
257 {
258 _STRUCT_USER32_TIMEVAL it_interval; /* timer interval */
259 _STRUCT_USER32_TIMEVAL it_value; /* current value */
260 };
261 #endif /* _STRUCT_USER32_TIMEVAL */
262 #endif /* __need_struct_user32_itimerval */
263
264 #endif /* KERNEL */
265
266 #ifdef __need_fd_set
267 #undef __need_fd_set
268 #ifndef _FD_SET
269 #define _FD_SET
270 /*
271 * Select uses bit masks of file descriptors in longs. These macros
272 * manipulate such bit fields (the filesystem macros use chars). The
273 * extra protection here is to permit application redefinition above
274 * the default size.
275 */
276 #ifdef FD_SETSIZE
277 #define __DARWIN_FD_SETSIZE FD_SETSIZE
278 #else /* !FD_SETSIZE */
279 #define __DARWIN_FD_SETSIZE 1024
280 #endif /* FD_SETSIZE */
281 #define __DARWIN_NBBY 8 /* bits in a byte */
282 #define __DARWIN_NFDBITS (sizeof(__int32_t) * __DARWIN_NBBY) /* bits per mask */
283 #define __DARWIN_howmany(x, y) ((((x) % (y)) == 0) ? ((x) / (y)) : (((x) / (y)) + 1)) /* # y's == x bits? */
284
285 __BEGIN_DECLS
286 typedef struct fd_set {
287 __int32_t fds_bits[__DARWIN_howmany(__DARWIN_FD_SETSIZE, __DARWIN_NFDBITS)];
288 } fd_set;
289 __END_DECLS
290
291 /* This inline avoids argument side-effect issues with FD_ISSET() */
292 static __inline int
293 __darwin_fd_isset(int _n, const struct fd_set *_p)
294 {
295 return (_p->fds_bits[_n/__DARWIN_NFDBITS] & (1<<(_n % __DARWIN_NFDBITS)));
296 }
297
298 #define __DARWIN_FD_SET(n, p) do { int __fd = (n); ((p)->fds_bits[__fd/__DARWIN_NFDBITS] |= (1<<(__fd % __DARWIN_NFDBITS))); } while(0)
299 #define __DARWIN_FD_CLR(n, p) do { int __fd = (n); ((p)->fds_bits[__fd/__DARWIN_NFDBITS] &= ~(1<<(__fd % __DARWIN_NFDBITS))); } while(0)
300 #define __DARWIN_FD_ISSET(n, p) __darwin_fd_isset((n), (p))
301
302 #if __GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3
303 /*
304 * Use the built-in bzero function instead of the library version so that
305 * we do not pollute the namespace or introduce prototype warnings.
306 */
307 #define __DARWIN_FD_ZERO(p) __builtin_bzero(p, sizeof(*(p)))
308 #else
309 #define __DARWIN_FD_ZERO(p) bzero(p, sizeof(*(p)))
310 #endif
311
312 #define __DARWIN_FD_COPY(f, t) bcopy(f, t, sizeof(*(f)))
313 #endif /* _FD_SET */
314 #endif /* __need_fd_set */
315
316 #ifdef __need_stack_t
317 #undef __need_stack_t
318 #ifndef _STACK_T
319 #define _STACK_T
320 typedef _STRUCT_SIGALTSTACK stack_t; /* [???] signal stack */
321 #endif /* _STACK_T */
322 #endif /* __need_stack_t */
323
324 #ifdef __need_ucontext_t
325 #undef __need_ucontext_t
326 /* user context */
327 #ifndef _UCONTEXT_T
328 #define _UCONTEXT_T
329 typedef _STRUCT_UCONTEXT ucontext_t; /* [???] user context */
330 #endif /* _UCONTEXT_T */
331 #endif /* __need_ucontext_t */
332
333 #ifdef __need_ucontext64_t
334 #undef __need_ucontext64_t
335 #ifndef _UCONTEXT64_T
336 #define _UCONTEXT64_T
337 typedef _STRUCT_UCONTEXT64 ucontext64_t; /* [???] user context */
338 #endif /* _UCONTEXT64_T */
339 #endif /* __need_ucontext64_t */