]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/syscall_sw.c
xnu-3789.1.32.tar.gz
[apple/xnu.git] / osfmk / kern / syscall_sw.c
CommitLineData
1c79356b 1/*
0c530ab8 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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#include <mach/mach_types.h>
91447636 60#include <mach/mach_traps.h>
1c79356b
A
61
62#include <kern/syscall_sw.h>
3e170ce0 63#if CONFIG_REQUIRES_U32_MUNGING || (__arm__ && (__BIGGEST_ALIGNMENT__ > 4))
316670eb 64#include <sys/munge.h>
fe8ab488 65#endif
1c79356b
A
66
67/* Forwards */
91447636 68
1c79356b
A
69
70/*
71 * To add a new entry:
39236c6e
A
72 * Add an "MACH_TRAP(routine, arg_count, num_32_bit_words, munge_routine)" to the table below.
73 * where,
74 * - routine: The trap handling routine in the kernel
75 * - arg_count: The number of arguments for the mach trap (independant of arch/arg size).
76 * This value also defines the number of 64-bit words copied in for a U64 process.
77 * - num_32_bit_words: The number of 32-bit words to be copied in for a U32 process.
78 * - munge_routine: The argument munging routine to align input args correctly.
1c79356b 79 *
39236c6e 80 * Also, add trap definition to mach/syscall_sw.h and
1c79356b
A
81 * recompile user library.
82 *
39236c6e 83 *
1c79356b
A
84 * WARNING: If you add a trap which requires more than 7
85 * parameters, mach/{machine}/syscall_sw.h and {machine}/trap.c
86 * and/or {machine}/locore.s may need to be modified for it
87 * to work successfully.
88 *
89 * WARNING: Don't use numbers 0 through -9. They (along with
90 * the positive numbers) are reserved for Unix.
91 */
92
93int kern_invalid_debug = 0;
94
95/* Include declarations of the trap functions. */
96
97#include <mach/mach_traps.h>
98#include <mach/mach_syscalls.h>
99#include <kern/syscall_subr.h>
100
101#include <kern/clock.h>
102#include <mach/mk_timer.h>
103
316670eb 104const mach_trap_t mach_trap_table[MACH_TRAP_TABLE_COUNT] = {
39236c6e
A
105/* 0 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
106/* 1 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
107/* 2 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
108/* 3 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
109/* 4 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
110/* 5 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
111/* 6 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
112/* 7 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
113/* 8 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
114/* 9 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
115/* 10 */ MACH_TRAP(_kernelrpc_mach_vm_allocate_trap, 4, 5, munge_wwlw),
39037602 116/* 11 */ MACH_TRAP(_kernelrpc_mach_vm_purgable_control_trap, 4, 5, munge_wlww),
39236c6e
A
117/* 12 */ MACH_TRAP(_kernelrpc_mach_vm_deallocate_trap, 3, 5, munge_wll),
118/* 13 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
119/* 14 */ MACH_TRAP(_kernelrpc_mach_vm_protect_trap, 5, 7, munge_wllww),
120/* 15 */ MACH_TRAP(_kernelrpc_mach_vm_map_trap, 6, 8, munge_wwllww),
121/* 16 */ MACH_TRAP(_kernelrpc_mach_port_allocate_trap, 3, 3, munge_www),
122/* 17 */ MACH_TRAP(_kernelrpc_mach_port_destroy_trap, 2, 2, munge_ww),
123/* 18 */ MACH_TRAP(_kernelrpc_mach_port_deallocate_trap, 2, 2, munge_ww),
124/* 19 */ MACH_TRAP(_kernelrpc_mach_port_mod_refs_trap, 4, 4, munge_wwww),
125/* 20 */ MACH_TRAP(_kernelrpc_mach_port_move_member_trap, 3, 3, munge_www),
126/* 21 */ MACH_TRAP(_kernelrpc_mach_port_insert_right_trap, 4, 4, munge_wwww),
127/* 22 */ MACH_TRAP(_kernelrpc_mach_port_insert_member_trap, 3, 3, munge_www),
128/* 23 */ MACH_TRAP(_kernelrpc_mach_port_extract_member_trap, 3, 3, munge_www),
129/* 24 */ MACH_TRAP(_kernelrpc_mach_port_construct_trap, 4, 5, munge_wwlw),
130/* 25 */ MACH_TRAP(_kernelrpc_mach_port_destruct_trap, 4, 5, munge_wwwl),
131/* 26 */ MACH_TRAP(mach_reply_port, 0, 0, NULL),
132/* 27 */ MACH_TRAP(thread_self_trap, 0, 0, NULL),
133/* 28 */ MACH_TRAP(task_self_trap, 0, 0, NULL),
134/* 29 */ MACH_TRAP(host_self_trap, 0, 0, NULL),
135/* 30 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
136/* 31 */ MACH_TRAP(mach_msg_trap, 7, 7, munge_wwwwwww),
137/* 32 */ MACH_TRAP(mach_msg_overwrite_trap, 8, 8, munge_wwwwwwww),
138/* 33 */ MACH_TRAP(semaphore_signal_trap, 1, 1, munge_w),
139/* 34 */ MACH_TRAP(semaphore_signal_all_trap, 1, 1, munge_w),
140/* 35 */ MACH_TRAP(semaphore_signal_thread_trap, 2, 2, munge_ww),
141/* 36 */ MACH_TRAP(semaphore_wait_trap, 1, 1, munge_w),
142/* 37 */ MACH_TRAP(semaphore_wait_signal_trap, 2, 2, munge_ww),
143/* 38 */ MACH_TRAP(semaphore_timedwait_trap, 3, 3, munge_www),
144/* 39 */ MACH_TRAP(semaphore_timedwait_signal_trap, 4, 4, munge_wwww),
145/* 40 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
146/* 41 */ MACH_TRAP(_kernelrpc_mach_port_guard_trap, 4, 5, munge_wwlw),
147/* 42 */ MACH_TRAP(_kernelrpc_mach_port_unguard_trap, 3, 4, munge_wwl),
39037602 148/* 43 */ MACH_TRAP(mach_generate_activity_id, 3, 3, munge_www),
39236c6e
A
149/* 44 */ MACH_TRAP(task_name_for_pid, 3, 3, munge_www),
150/* 45 */ MACH_TRAP(task_for_pid, 3, 3, munge_www),
151/* 46 */ MACH_TRAP(pid_for_task, 2, 2, munge_ww),
152/* 47 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
153/* 48 */ MACH_TRAP(macx_swapon, 4, 5, munge_lwww),
154/* 49 */ MACH_TRAP(macx_swapoff, 2, 3, munge_lw),
155/* 50 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
156/* 51 */ MACH_TRAP(macx_triggers, 4, 4, munge_wwww),
157/* 52 */ MACH_TRAP(macx_backing_store_suspend, 1, 1, munge_w),
158/* 53 */ MACH_TRAP(macx_backing_store_recovery, 1, 1, munge_w),
159/* 54 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
160/* 55 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
161/* 56 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
162/* 57 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
163/* 58 */ MACH_TRAP(pfz_exit, 0, 0, NULL),
164/* 59 */ MACH_TRAP(swtch_pri, 0, 0, NULL),
165/* 60 */ MACH_TRAP(swtch, 0, 0, NULL),
166/* 61 */ MACH_TRAP(thread_switch, 3, 3, munge_www),
167/* 62 */ MACH_TRAP(clock_sleep_trap, 5, 5, munge_wwwww),
168/* 63 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
1c79356b 169/* traps 64 - 95 reserved (debo) */
39236c6e
A
170/* 64 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
171/* 65 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
172/* 66 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
173/* 67 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
174/* 68 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
175/* 69 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
39037602 176/* 70 */ MACH_TRAP(host_create_mach_voucher_trap, 4, 4, munge_wwww),
39236c6e 177/* 71 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
39037602 178/* 72 */ MACH_TRAP(mach_voucher_extract_attr_recipe_trap, 4, 4, munge_wwww),
39236c6e
A
179/* 73 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
180/* 74 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
181/* 75 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
182/* 76 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
183/* 77 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
184/* 78 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
185/* 79 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
186/* 80 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
187/* 81 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
188/* 82 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
189/* 83 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
190/* 84 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
191/* 85 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
192/* 86 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
193/* 87 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
194/* 88 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
195/* 89 */ MACH_TRAP(mach_timebase_info_trap, 1, 1, munge_w),
196/* 90 */ MACH_TRAP(mach_wait_until_trap, 1, 2, munge_l),
197/* 91 */ MACH_TRAP(mk_timer_create_trap, 0, 0, NULL),
198/* 92 */ MACH_TRAP(mk_timer_destroy_trap, 1, 1, munge_w),
199/* 93 */ MACH_TRAP(mk_timer_arm_trap, 2, 3, munge_wl),
200/* 94 */ MACH_TRAP(mk_timer_cancel_trap, 2, 2, munge_ww),
201/* 95 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
1c79356b 202/* traps 64 - 95 reserved (debo) */
39236c6e
A
203/* 96 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
204/* 97 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
205/* 98 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
206/* 99 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
1c79356b 207/* traps 100-107 reserved for iokit (esb) */
39236c6e
A
208/* 100 */ MACH_TRAP(iokit_user_client_trap, 8, 8, munge_wwwwwwww),
209/* 101 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
210/* 102 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
211/* 103 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
212/* 104 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
213/* 105 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
214/* 106 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
215/* 107 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
91447636 216/* traps 108-127 unused */
39236c6e
A
217/* 108 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
218/* 109 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
219/* 110 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
220/* 111 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
221/* 112 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
222/* 113 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
223/* 114 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
224/* 115 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
225/* 116 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
226/* 117 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
227/* 118 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
228/* 119 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
229/* 120 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
230/* 121 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
231/* 122 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
232/* 123 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
233/* 124 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
234/* 125 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
235/* 126 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
236/* 127 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
1c79356b
A
237};
238
b0d623f7
A
239const char * mach_syscall_name_table[MACH_TRAP_TABLE_COUNT] = {
240/* 0 */ "kern_invalid",
241/* 1 */ "kern_invalid",
242/* 2 */ "kern_invalid",
243/* 3 */ "kern_invalid",
244/* 4 */ "kern_invalid",
245/* 5 */ "kern_invalid",
246/* 6 */ "kern_invalid",
247/* 7 */ "kern_invalid",
248/* 8 */ "kern_invalid",
249/* 9 */ "kern_invalid",
316670eb 250/* 10 */ "_kernelrpc_mach_vm_allocate_trap",
b0d623f7 251/* 11 */ "kern_invalid",
316670eb 252/* 12 */ "_kernelrpc_mach_vm_deallocate_trap",
b0d623f7 253/* 13 */ "kern_invalid",
316670eb 254/* 14 */ "_kernelrpc_mach_vm_protect_trap",
39236c6e 255/* 15 */ "_kernelrpc_mach_vm_map_trap",
316670eb
A
256/* 16 */ "_kernelrpc_mach_port_allocate_trap",
257/* 17 */ "_kernelrpc_mach_port_destroy_trap",
258/* 18 */ "_kernelrpc_mach_port_deallocate_trap",
259/* 19 */ "_kernelrpc_mach_port_mod_refs_trap",
260/* 20 */ "_kernelrpc_mach_port_move_member_trap",
261/* 21 */ "_kernelrpc_mach_port_insert_right_trap",
262/* 22 */ "_kernelrpc_mach_port_insert_member_trap",
263/* 23 */ "_kernelrpc_mach_port_extract_member_trap",
39236c6e
A
264/* 24 */ "_kernelrpc_mach_port_construct_trap",
265/* 25 */ "_kernelrpc_mach_port_destruct_trap",
b0d623f7
A
266/* 26 */ "mach_reply_port",
267/* 27 */ "thread_self_trap",
268/* 28 */ "task_self_trap",
269/* 29 */ "host_self_trap",
270/* 30 */ "kern_invalid",
271/* 31 */ "mach_msg_trap",
272/* 32 */ "mach_msg_overwrite_trap",
273/* 33 */ "semaphore_signal_trap",
274/* 34 */ "semaphore_signal_all_trap",
275/* 35 */ "semaphore_signal_thread_trap",
276/* 36 */ "semaphore_wait_trap",
277/* 37 */ "semaphore_wait_signal_trap",
278/* 38 */ "semaphore_timedwait_trap",
279/* 39 */ "semaphore_timedwait_signal_trap",
280/* 40 */ "kern_invalid",
39236c6e
A
281/* 41 */ "_kernelrpc_mach_port_guard_trap",
282/* 42 */ "_kernelrpc_mach_port_unguard_trap",
39037602 283/* 43 */ "mach_generate_activity_id",
b0d623f7
A
284/* 44 */ "task_name_for_pid",
285/* 45 */ "task_for_pid",
286/* 46 */ "pid_for_task",
287/* 47 */ "kern_invalid",
288/* 48 */ "macx_swapon",
289/* 49 */ "macx_swapoff",
290/* 50 */ "kern_invalid",
291/* 51 */ "macx_triggers",
292/* 52 */ "macx_backing_store_suspend",
293/* 53 */ "macx_backing_store_recovery",
294/* 54 */ "kern_invalid",
295/* 55 */ "kern_invalid",
296/* 56 */ "kern_invalid",
297/* 57 */ "kern_invalid",
298/* 58 */ "pfz_exit",
299/* 59 */ "swtch_pri",
300/* 60 */ "swtch",
301/* 61 */ "thread_switch",
302/* 62 */ "clock_sleep_trap",
303/* 63 */ "kern_invalid",
304/* traps 64 - 95 reserved (debo) */
305/* 64 */ "kern_invalid",
306/* 65 */ "kern_invalid",
307/* 66 */ "kern_invalid",
308/* 67 */ "kern_invalid",
309/* 68 */ "kern_invalid",
310/* 69 */ "kern_invalid",
39037602 311/* 70 */ "host_create_mach_voucher_trap",
b0d623f7 312/* 71 */ "kern_invalid",
39037602 313/* 72 */ "mach_voucher_extract_attr_recipe_trap",
b0d623f7
A
314/* 73 */ "kern_invalid",
315/* 74 */ "kern_invalid",
316/* 75 */ "kern_invalid",
317/* 76 */ "kern_invalid",
318/* 77 */ "kern_invalid",
319/* 78 */ "kern_invalid",
320/* 79 */ "kern_invalid",
321/* 80 */ "kern_invalid",
322/* 81 */ "kern_invalid",
323/* 82 */ "kern_invalid",
324/* 83 */ "kern_invalid",
325/* 84 */ "kern_invalid",
326/* 85 */ "kern_invalid",
327/* 86 */ "kern_invalid",
328/* 87 */ "kern_invalid",
329/* 88 */ "kern_invalid",
330/* 89 */ "mach_timebase_info_trap",
331/* 90 */ "mach_wait_until_trap",
332/* 91 */ "mk_timer_create_trap",
333/* 92 */ "mk_timer_destroy_trap",
334/* 93 */ "mk_timer_arm_trap",
335/* 94 */ "mk_timer_cancel_trap",
336/* 95 */ "kern_invalid",
337/* traps 64 - 95 reserved (debo) */
338/* 96 */ "kern_invalid",
339/* 97 */ "kern_invalid",
340/* 98 */ "kern_invalid",
341/* 99 */ "kern_invalid",
342/* traps 100-107 reserved for iokit (esb) */
fe8ab488 343/* 100 */ "iokit_user_client_trap",
b0d623f7
A
344/* 101 */ "kern_invalid",
345/* 102 */ "kern_invalid",
346/* 103 */ "kern_invalid",
347/* 104 */ "kern_invalid",
348/* 105 */ "kern_invalid",
349/* 106 */ "kern_invalid",
350/* 107 */ "kern_invalid",
351/* traps 108-127 unused */
352/* 108 */ "kern_invalid",
353/* 109 */ "kern_invalid",
354/* 110 */ "kern_invalid",
355/* 111 */ "kern_invalid",
356/* 112 */ "kern_invalid",
357/* 113 */ "kern_invalid",
358/* 114 */ "kern_invalid",
359/* 115 */ "kern_invalid",
360/* 116 */ "kern_invalid",
361/* 117 */ "kern_invalid",
362/* 118 */ "kern_invalid",
363/* 119 */ "kern_invalid",
364/* 120 */ "kern_invalid",
365/* 121 */ "kern_invalid",
366/* 122 */ "kern_invalid",
367/* 123 */ "kern_invalid",
368/* 124 */ "kern_invalid",
369/* 125 */ "kern_invalid",
370/* 126 */ "kern_invalid",
371/* 127 */ "kern_invalid",
372};
373
1c79356b
A
374int mach_trap_count = (sizeof(mach_trap_table) / sizeof(mach_trap_table[0]));
375
1c79356b 376kern_return_t
91447636
A
377kern_invalid(
378 __unused struct kern_invalid_args *args)
1c79356b
A
379{
380 if (kern_invalid_debug) Debugger("kern_invalid mach trap");
381 return(KERN_INVALID_ARGUMENT);
382}
383