]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/mach_traps.h
xnu-1699.26.8.tar.gz
[apple/xnu.git] / osfmk / mach / mach_traps.h
1 /*
2 * Copyright (c) 2000-2007 Apple 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 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56 /*
57 */
58 /*
59 * Definitions of general Mach system traps.
60 *
61 * These are the definitions as seen from user-space.
62 * The kernel definitions are in <mach/syscall_sw.h>.
63 * Kernel RPC functions are defined in <mach/mach_interface.h>.
64 */
65
66 #ifndef _MACH_MACH_TRAPS_H_
67 #define _MACH_MACH_TRAPS_H_
68
69 #include <stdint.h>
70
71 #include <mach/std_types.h>
72 #include <mach/mach_types.h>
73 #include <mach/kern_return.h>
74 #include <mach/port.h>
75 #include <mach/vm_types.h>
76 #include <mach/clock_types.h>
77
78 #include <machine/endian.h>
79
80 #include <sys/cdefs.h>
81
82 __BEGIN_DECLS
83
84 #ifndef KERNEL
85
86 #ifdef PRIVATE
87
88 extern mach_port_name_t mach_reply_port(void);
89
90 extern mach_port_name_t thread_self_trap(void);
91
92 extern mach_port_name_t host_self_trap(void);
93
94 extern mach_msg_return_t mach_msg_trap(
95 mach_msg_header_t *msg,
96 mach_msg_option_t option,
97 mach_msg_size_t send_size,
98 mach_msg_size_t rcv_size,
99 mach_port_name_t rcv_name,
100 mach_msg_timeout_t timeout,
101 mach_port_name_t notify);
102
103 extern mach_msg_return_t mach_msg_overwrite_trap(
104 mach_msg_header_t *msg,
105 mach_msg_option_t option,
106 mach_msg_size_t send_size,
107 mach_msg_size_t rcv_size,
108 mach_port_name_t rcv_name,
109 mach_msg_timeout_t timeout,
110 mach_port_name_t notify,
111 mach_msg_header_t *rcv_msg,
112 mach_msg_size_t rcv_limit);
113
114 extern kern_return_t semaphore_signal_trap(
115 mach_port_name_t signal_name);
116
117 extern kern_return_t semaphore_signal_all_trap(
118 mach_port_name_t signal_name);
119
120 extern kern_return_t semaphore_signal_thread_trap(
121 mach_port_name_t signal_name,
122 mach_port_name_t thread_name);
123
124 extern kern_return_t semaphore_wait_trap(
125 mach_port_name_t wait_name);
126
127 extern kern_return_t semaphore_wait_signal_trap(
128 mach_port_name_t wait_name,
129 mach_port_name_t signal_name);
130
131 extern kern_return_t semaphore_timedwait_trap(
132 mach_port_name_t wait_name,
133 unsigned int sec,
134 clock_res_t nsec);
135
136 extern kern_return_t semaphore_timedwait_signal_trap(
137 mach_port_name_t wait_name,
138 mach_port_name_t signal_name,
139 unsigned int sec,
140 clock_res_t nsec);
141
142 extern kern_return_t clock_sleep_trap(
143 mach_port_name_t clock_name,
144 sleep_type_t sleep_type,
145 int sleep_sec,
146 int sleep_nsec,
147 mach_timespec_t *wakeup_time);
148
149 #endif /* PRIVATE */
150
151 extern kern_return_t macx_swapon(
152 uint64_t filename,
153 int flags,
154 int size,
155 int priority);
156
157 extern kern_return_t macx_swapoff(
158 uint64_t filename,
159 int flags);
160
161 extern kern_return_t macx_triggers(
162 int hi_water,
163 int low_water,
164 int flags,
165 mach_port_t alert_port);
166
167 extern kern_return_t macx_backing_store_suspend(
168 boolean_t suspend);
169
170 extern kern_return_t macx_backing_store_recovery(
171 int pid);
172
173 extern boolean_t swtch_pri(int pri);
174
175 extern boolean_t swtch(void);
176
177 extern kern_return_t thread_switch(
178 mach_port_name_t thread_name,
179 int option,
180 mach_msg_timeout_t option_time);
181
182 extern mach_port_name_t task_self_trap(void);
183
184 /*
185 * Obsolete interfaces.
186 */
187
188 extern kern_return_t task_for_pid(
189 mach_port_name_t target_tport,
190 int pid,
191 mach_port_name_t *t);
192
193 extern kern_return_t task_name_for_pid(
194 mach_port_name_t target_tport,
195 int pid,
196 mach_port_name_t *tn);
197
198 extern kern_return_t pid_for_task(
199 mach_port_name_t t,
200 int *x);
201
202 #if !defined(__LP64__) && !defined(__arm__)
203 /* these should go away altogether - so no 64 legacy please */
204
205 extern kern_return_t map_fd(
206 int fd,
207 vm_offset_t offset,
208 vm_offset_t *va,
209 boolean_t findspace,
210 vm_size_t size);
211
212 #endif /* !defined(__LP64__) && !defined(__arm__) */
213
214 #else /* KERNEL */
215
216 #ifdef XNU_KERNEL_PRIVATE
217
218 /* Syscall data translations routines
219 *
220 * The kernel may support multiple userspace ABIs, and must use
221 * argument structures with elements large enough for any of them.
222 */
223 #define PAD_(t) (sizeof(uint64_t) <= sizeof(t) \
224 ? 0 : sizeof(uint64_t) - sizeof(t))
225 #define PAD_ARG_8
226
227 #if BYTE_ORDER == LITTLE_ENDIAN
228 #define PADL_(t) 0
229 #define PADR_(t) PAD_(t)
230 #else
231 #define PADL_(t) PAD_(t)
232 #define PADR_(t) 0
233 #endif
234
235 #define PAD_ARG_(arg_type, arg_name) \
236 char arg_name##_l_[PADL_(arg_type)]; arg_type arg_name; char arg_name##_r_[PADR_(arg_type)];
237
238 /*
239 * To support 32-bit clients as well as 64-bit clients, argument
240 * structures may need to be munged to repack the arguments. All
241 * active architectures do this inline in the code to dispatch Mach
242 * traps, without calling out to the BSD system call mungers.
243 */
244
245 #if 0 /* no active architectures use this */
246 void munge_w(const void *, void *);
247 void munge_ww(const void *, void *);
248 void munge_www(const void *, void *);
249 void munge_wwww(const void *, void *);
250 void munge_wwwww(const void *, void *);
251 void munge_wwwwww(const void *, void *);
252 void munge_wwwwwww(const void *, void *);
253 void munge_wwwwwwww(const void *, void *);
254 void munge_d(const void *, void *);
255 void munge_dd(const void *, void *);
256 void munge_ddd(const void *, void *);
257 void munge_dddd(const void *, void *);
258 void munge_ddddd(const void *, void *);
259 void munge_dddddd(const void *, void *);
260 void munge_ddddddd(const void *, void *);
261 void munge_dddddddd(const void *, void *);
262 void munge_l(const void *, void *);
263 void munge_lw(const void *, void *);
264 void munge_lwww(const void *, void *);
265 void munge_wl(const void *, void *);
266 void munge_wlw(const void *, void *);
267 void munge_wwwl(const void *, void *);
268 void munge_wwwwl(const void *, void *);
269 void munge_wwwwwl(const void *, void *);
270 #endif /* 0 */
271
272 struct kern_invalid_args {
273 int32_t dummy;
274 };
275 extern kern_return_t kern_invalid(
276 struct kern_invalid_args *args);
277
278 struct mach_reply_port_args {
279 int32_t dummy;
280 };
281 extern mach_port_name_t mach_reply_port(
282 struct mach_reply_port_args *args);
283
284 struct thread_self_trap_args {
285 int32_t dummy;
286 };
287 extern mach_port_name_t thread_self_trap(
288 struct thread_self_trap_args *args);
289
290 struct task_self_trap_args {
291 int32_t dummy;
292 };
293 extern mach_port_name_t task_self_trap(
294 struct task_self_trap_args *args);
295
296 struct host_self_trap_args {
297 int32_t dummy;
298 };
299 extern mach_port_name_t host_self_trap(
300 struct host_self_trap_args *args);
301
302 struct mach_msg_overwrite_trap_args {
303 PAD_ARG_(mach_vm_address_t, msg);
304 PAD_ARG_(mach_msg_option_t, option);
305 PAD_ARG_(mach_msg_size_t, send_size);
306 PAD_ARG_(mach_msg_size_t, rcv_size);
307 PAD_ARG_(mach_port_name_t, rcv_name);
308 PAD_ARG_(mach_msg_timeout_t, timeout);
309 PAD_ARG_(mach_port_name_t, notify);
310 PAD_ARG_8
311 PAD_ARG_(mach_vm_address_t, rcv_msg); /* Unused on mach_msg_trap */
312 };
313 extern mach_msg_return_t mach_msg_trap(
314 struct mach_msg_overwrite_trap_args *args);
315 extern mach_msg_return_t mach_msg_overwrite_trap(
316 struct mach_msg_overwrite_trap_args *args);
317
318 struct semaphore_signal_trap_args {
319 PAD_ARG_(mach_port_name_t, signal_name);
320 };
321 extern kern_return_t semaphore_signal_trap(
322 struct semaphore_signal_trap_args *args);
323
324 struct semaphore_signal_all_trap_args {
325 PAD_ARG_(mach_port_name_t, signal_name);
326 };
327 extern kern_return_t semaphore_signal_all_trap(
328 struct semaphore_signal_all_trap_args *args);
329
330 struct semaphore_signal_thread_trap_args {
331 PAD_ARG_(mach_port_name_t, signal_name);
332 PAD_ARG_(mach_port_name_t, thread_name);
333 };
334 extern kern_return_t semaphore_signal_thread_trap(
335 struct semaphore_signal_thread_trap_args *args);
336
337 struct semaphore_wait_trap_args {
338 PAD_ARG_(mach_port_name_t, wait_name);
339 };
340 extern kern_return_t semaphore_wait_trap(
341 struct semaphore_wait_trap_args *args);
342
343 struct semaphore_wait_signal_trap_args {
344 PAD_ARG_(mach_port_name_t, wait_name);
345 PAD_ARG_(mach_port_name_t, signal_name);
346 };
347 extern kern_return_t semaphore_wait_signal_trap(
348 struct semaphore_wait_signal_trap_args *args);
349
350 struct semaphore_timedwait_trap_args {
351 PAD_ARG_(mach_port_name_t, wait_name);
352 PAD_ARG_(unsigned int, sec);
353 PAD_ARG_(clock_res_t, nsec);
354 };
355 extern kern_return_t semaphore_timedwait_trap(
356 struct semaphore_timedwait_trap_args *args);
357
358 struct semaphore_timedwait_signal_trap_args {
359 PAD_ARG_(mach_port_name_t, wait_name);
360 PAD_ARG_(mach_port_name_t, signal_name);
361 PAD_ARG_(unsigned int, sec);
362 PAD_ARG_(clock_res_t, nsec);
363 };
364 extern kern_return_t semaphore_timedwait_signal_trap(
365 struct semaphore_timedwait_signal_trap_args *args);
366
367 #if !defined(CONFIG_EMBEDDED)
368 struct map_fd_args {
369 PAD_ARG_(int, fd);
370 PAD_ARG_(vm_offset_t, offset);
371 PAD_ARG_(vm_offset_t *, va);
372 PAD_ARG_(boolean_t, findspace);
373 PAD_ARG_(vm_size_t, size);
374 };
375 extern kern_return_t map_fd(
376 struct map_fd_args *args);
377 #endif /* !defined(CONFIG_EMBEDDED) */
378
379 struct task_for_pid_args {
380 PAD_ARG_(mach_port_name_t, target_tport);
381 PAD_ARG_(int, pid);
382 PAD_ARG_(user_addr_t, t);
383 };
384 extern kern_return_t task_for_pid(
385 struct task_for_pid_args *args);
386
387 struct task_name_for_pid_args {
388 PAD_ARG_(mach_port_name_t, target_tport);
389 PAD_ARG_(int, pid);
390 PAD_ARG_(user_addr_t, t);
391 };
392 extern kern_return_t task_name_for_pid(
393 struct task_name_for_pid_args *args);
394
395 struct pid_for_task_args {
396 PAD_ARG_(mach_port_name_t, t);
397 PAD_ARG_(user_addr_t, pid);
398 };
399 extern kern_return_t pid_for_task(
400 struct pid_for_task_args *args);
401
402 struct macx_swapon_args {
403 PAD_ARG_(uint64_t, filename);
404 PAD_ARG_(int, flags);
405 PAD_ARG_(int, size);
406 PAD_ARG_(int, priority);
407 };
408 extern kern_return_t macx_swapon(
409 struct macx_swapon_args *args);
410
411 struct macx_swapoff_args {
412 PAD_ARG_(uint64_t, filename);
413 PAD_ARG_(int, flags);
414 };
415 extern kern_return_t macx_swapoff(
416 struct macx_swapoff_args *args);
417
418 struct macx_triggers_args {
419 PAD_ARG_(int, hi_water);
420 PAD_ARG_(int, low_water);
421 PAD_ARG_(int, flags);
422 PAD_ARG_(mach_port_t, alert_port);
423 };
424 extern kern_return_t macx_triggers(
425 struct macx_triggers_args *args);
426
427 struct macx_backing_store_suspend_args {
428 PAD_ARG_(boolean_t, suspend);
429 };
430 extern kern_return_t macx_backing_store_suspend(
431 struct macx_backing_store_suspend_args *args);
432
433 struct macx_backing_store_recovery_args {
434 PAD_ARG_(int, pid);
435 };
436 extern kern_return_t macx_backing_store_recovery(
437 struct macx_backing_store_recovery_args *args);
438
439 struct swtch_pri_args {
440 PAD_ARG_(int, pri);
441 };
442 extern boolean_t swtch_pri(
443 struct swtch_pri_args *args);
444
445 struct pfz_exit_args {
446 int32_t dummy;
447 };
448 extern kern_return_t pfz_exit(
449 struct pfz_exit_args *args);
450
451 struct swtch_args {
452 int32_t dummy;
453 };
454 extern boolean_t swtch(
455 struct swtch_args *args);
456
457 struct clock_sleep_trap_args{
458 PAD_ARG_(mach_port_name_t, clock_name);
459 PAD_ARG_(sleep_type_t, sleep_type);
460 PAD_ARG_(int, sleep_sec);
461 PAD_ARG_(int, sleep_nsec);
462 PAD_ARG_(mach_vm_address_t, wakeup_time);
463 };
464 extern kern_return_t clock_sleep_trap(
465 struct clock_sleep_trap_args *args);
466
467 struct thread_switch_args {
468 PAD_ARG_(mach_port_name_t, thread_name);
469 PAD_ARG_(int, option);
470 PAD_ARG_(mach_msg_timeout_t, option_time);
471 };
472 extern kern_return_t thread_switch(
473 struct thread_switch_args *args);
474
475 struct mach_timebase_info_trap_args {
476 PAD_ARG_(mach_vm_address_t, info);
477 };
478 extern kern_return_t mach_timebase_info_trap(
479 struct mach_timebase_info_trap_args *args);
480
481 struct mach_wait_until_trap_args {
482 PAD_ARG_(uint64_t, deadline);
483 };
484 extern kern_return_t mach_wait_until_trap(
485 struct mach_wait_until_trap_args *args);
486
487 struct mk_timer_create_trap_args {
488 int32_t dummy;
489 };
490 extern mach_port_name_t mk_timer_create_trap(
491 struct mk_timer_create_trap_args *args);
492
493 struct mk_timer_destroy_trap_args {
494 PAD_ARG_(mach_port_name_t, name);
495 };
496 extern kern_return_t mk_timer_destroy_trap(
497 struct mk_timer_destroy_trap_args *args);
498
499 struct mk_timer_arm_trap_args {
500 PAD_ARG_(mach_port_name_t, name);
501 PAD_ARG_(uint64_t, expire_time);
502 };
503 extern kern_return_t mk_timer_arm_trap(
504 struct mk_timer_arm_trap_args *args);
505
506 struct mk_timer_cancel_trap_args {
507 PAD_ARG_(mach_port_name_t, name);
508 PAD_ARG_(mach_vm_address_t, result_time);
509 };
510 extern kern_return_t mk_timer_cancel_trap(
511 struct mk_timer_cancel_trap_args *args);
512
513 /* not published to LP64 clients yet */
514 struct iokit_user_client_trap_args {
515 PAD_ARG_(void *, userClientRef);
516 PAD_ARG_(uint32_t, index);
517 PAD_ARG_(void *, p1);
518 PAD_ARG_(void *, p2);
519 PAD_ARG_(void *, p3);
520 PAD_ARG_(void *, p4);
521 PAD_ARG_(void *, p5);
522 PAD_ARG_8
523 PAD_ARG_(void *, p6);
524 };
525 kern_return_t iokit_user_client_trap(
526 struct iokit_user_client_trap_args *args);
527
528 #undef PAD_
529 #undef PADL_
530 #undef PADR_
531 #undef PAD_ARG_
532 #undef PAD_ARG_8
533
534 #endif /* XNU_KERNEL_PRIVATE */
535
536 #endif /* KERNEL */
537
538 __END_DECLS
539
540 #endif /* _MACH_MACH_TRAPS_H_ */