2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 #include <mach/mach_types.h>
60 #include <mach/mach_traps.h>
62 #include <kern/syscall_sw.h>
63 #include <sys/munge.h>
70 * Add an "MACH_TRAP(routine, arg count)" to the table below.
72 * Add trap definition to mach/syscall_sw.h and
73 * recompile user library.
75 * WARNING: If you add a trap which requires more than 7
76 * parameters, mach/{machine}/syscall_sw.h and {machine}/trap.c
77 * and/or {machine}/locore.s may need to be modified for it
78 * to work successfully.
80 * WARNING: Don't use numbers 0 through -9. They (along with
81 * the positive numbers) are reserved for Unix.
83 * WARNING: The 'arg_count' parameter in the list below is poorly named.
84 * It doesn't refer to the number of arguments the trap takes -
85 * it actually refers to the number of 32-bit words that need
86 * to be copied in from userspace. The munging of words to trap
87 * arguments is done in mach_call_munger().
90 int kern_invalid_debug
= 0;
92 /* Include declarations of the trap functions. */
94 #include <mach/mach_traps.h>
95 #include <mach/mach_syscalls.h>
96 #include <kern/syscall_subr.h>
98 #include <kern/clock.h>
99 #include <mach/mk_timer.h>
101 const mach_trap_t mach_trap_table
[MACH_TRAP_TABLE_COUNT
] = {
102 /* 0 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
103 /* 1 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
104 /* 2 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
105 /* 3 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
106 /* 4 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
107 /* 5 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
108 /* 6 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
109 /* 7 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
110 /* 8 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
111 /* 9 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
112 /* 10 */ MACH_TRAP(_kernelrpc_mach_vm_allocate_trap
, 5, munge_wwlw
, munge_dddd
),
113 /* 11 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
114 /* 12 */ MACH_TRAP(_kernelrpc_mach_vm_deallocate_trap
, 5, munge_wll
, munge_ddd
),
115 /* 13 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
116 /* 14 */ MACH_TRAP(_kernelrpc_mach_vm_protect_trap
, 7, munge_wllww
, munge_ddddd
),
117 /* 15 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
118 /* 16 */ MACH_TRAP(_kernelrpc_mach_port_allocate_trap
, 3, munge_www
, munge_ddd
),
119 /* 17 */ MACH_TRAP(_kernelrpc_mach_port_destroy_trap
, 2, munge_ww
, munge_dd
),
120 /* 18 */ MACH_TRAP(_kernelrpc_mach_port_deallocate_trap
, 2, munge_ww
, munge_dd
),
121 /* 19 */ MACH_TRAP(_kernelrpc_mach_port_mod_refs_trap
, 4, munge_wwww
, munge_dddd
),
122 /* 20 */ MACH_TRAP(_kernelrpc_mach_port_move_member_trap
, 3, munge_www
, munge_ddd
),
123 /* 21 */ MACH_TRAP(_kernelrpc_mach_port_insert_right_trap
, 4, munge_wwww
, munge_dddd
),
124 /* 22 */ MACH_TRAP(_kernelrpc_mach_port_insert_member_trap
, 3, munge_www
, munge_ddd
),
125 /* 23 */ MACH_TRAP(_kernelrpc_mach_port_extract_member_trap
, 3, munge_www
, munge_ddd
),
126 /* 24 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
127 /* 25 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
128 /* 26 */ MACH_TRAP(mach_reply_port
, 0, NULL
, NULL
),
129 /* 27 */ MACH_TRAP(thread_self_trap
, 0, NULL
, NULL
),
130 /* 28 */ MACH_TRAP(task_self_trap
, 0, NULL
, NULL
),
131 /* 29 */ MACH_TRAP(host_self_trap
, 0, NULL
, NULL
),
132 /* 30 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
133 /* 31 */ MACH_TRAP(mach_msg_trap
, 7, munge_wwwwwww
, munge_ddddddd
),
134 /* 32 */ MACH_TRAP(mach_msg_overwrite_trap
, 8, munge_wwwwwwww
, munge_dddddddd
),
135 /* 33 */ MACH_TRAP(semaphore_signal_trap
, 1, munge_w
, munge_d
),
136 /* 34 */ MACH_TRAP(semaphore_signal_all_trap
, 1, munge_w
, munge_d
),
137 /* 35 */ MACH_TRAP(semaphore_signal_thread_trap
, 2, munge_ww
, munge_dd
),
138 /* 36 */ MACH_TRAP(semaphore_wait_trap
, 1, munge_w
, munge_d
),
139 /* 37 */ MACH_TRAP(semaphore_wait_signal_trap
, 2, munge_ww
, munge_dd
),
140 /* 38 */ MACH_TRAP(semaphore_timedwait_trap
, 3, munge_www
, munge_ddd
),
141 /* 39 */ MACH_TRAP(semaphore_timedwait_signal_trap
, 4, munge_wwww
, munge_dddd
),
142 /* 40 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
143 /* 41 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
144 /* 42 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
145 #if !defined(CONFIG_EMBEDDED)
146 /* 43 */ MACH_TRAP(map_fd
, 5, munge_wwwww
, munge_ddddd
),
148 /* 43 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
149 #endif /* !defined(CONFIG_EMBEDDED) */
150 /* 44 */ MACH_TRAP(task_name_for_pid
, 3, munge_www
, munge_ddd
),
151 /* 45 */ MACH_TRAP(task_for_pid
, 3, munge_www
, munge_ddd
),
152 /* 46 */ MACH_TRAP(pid_for_task
, 2, munge_ww
,munge_dd
),
153 /* 47 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
154 /* 48 */ MACH_TRAP(macx_swapon
, 5, munge_lwww
, munge_dddd
),
155 /* 49 */ MACH_TRAP(macx_swapoff
, 3, munge_lw
, munge_dd
),
156 /* 50 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
157 /* 51 */ MACH_TRAP(macx_triggers
, 4, munge_wwww
, munge_dddd
),
158 /* 52 */ MACH_TRAP(macx_backing_store_suspend
, 1, munge_w
, munge_d
),
159 /* 53 */ MACH_TRAP(macx_backing_store_recovery
, 1, munge_w
, munge_d
),
160 /* 54 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
161 /* 55 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
162 /* 56 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
163 /* 57 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
164 /* 58 */ MACH_TRAP(pfz_exit
, 0, NULL
, NULL
),
165 /* 59 */ MACH_TRAP(swtch_pri
, 0, NULL
, NULL
),
166 /* 60 */ MACH_TRAP(swtch
, 0, NULL
, NULL
),
167 /* 61 */ MACH_TRAP(thread_switch
, 3, munge_www
, munge_ddd
),
168 /* 62 */ MACH_TRAP(clock_sleep_trap
, 5, munge_wwwww
, munge_ddddd
),
169 /* 63 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
170 /* traps 64 - 95 reserved (debo) */
171 /* 64 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
172 /* 65 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
173 /* 66 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
174 /* 67 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
175 /* 68 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
176 /* 69 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
177 /* 70 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
178 /* 71 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
179 /* 72 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
180 /* 73 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
181 /* 74 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
182 /* 75 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
183 /* 76 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
184 /* 77 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
185 /* 78 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
186 /* 79 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
187 /* 80 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
188 /* 81 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
189 /* 82 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
190 /* 83 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
191 /* 84 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
192 /* 85 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
193 /* 86 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
194 /* 87 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
195 /* 88 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
196 /* 89 */ MACH_TRAP(mach_timebase_info_trap
, 1, munge_w
, munge_d
),
197 /* 90 */ MACH_TRAP(mach_wait_until_trap
, 2, munge_l
, munge_d
),
198 /* 91 */ MACH_TRAP(mk_timer_create_trap
, 0, NULL
, NULL
),
199 /* 92 */ MACH_TRAP(mk_timer_destroy_trap
, 1, munge_w
, munge_d
),
200 /* 93 */ MACH_TRAP(mk_timer_arm_trap
, 3, munge_wl
, munge_dd
),
201 /* 94 */ MACH_TRAP(mk_timer_cancel_trap
, 2, munge_ww
, munge_dd
),
202 /* 95 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
203 /* traps 64 - 95 reserved (debo) */
204 /* 96 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
205 /* 97 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
206 /* 98 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
207 /* 99 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
208 /* traps 100-107 reserved for iokit (esb) */
209 /* 100 */ MACH_TRAP(iokit_user_client_trap
, 8, munge_wwwwwwww
, munge_dddddddd
),
210 /* 101 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
211 /* 102 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
212 /* 103 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
213 /* 104 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
214 /* 105 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
215 /* 106 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
216 /* 107 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
217 /* traps 108-127 unused */
218 /* 108 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
219 /* 109 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
220 /* 110 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
221 /* 111 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
222 /* 112 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
223 /* 113 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
224 /* 114 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
225 /* 115 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
226 /* 116 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
227 /* 117 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
228 /* 118 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
229 /* 119 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
230 /* 120 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
231 /* 121 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
232 /* 122 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
233 /* 123 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
234 /* 124 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
235 /* 125 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
236 /* 126 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
237 /* 127 */ MACH_TRAP(kern_invalid
, 0, NULL
, NULL
),
240 const char * mach_syscall_name_table
[MACH_TRAP_TABLE_COUNT
] = {
241 /* 0 */ "kern_invalid",
242 /* 1 */ "kern_invalid",
243 /* 2 */ "kern_invalid",
244 /* 3 */ "kern_invalid",
245 /* 4 */ "kern_invalid",
246 /* 5 */ "kern_invalid",
247 /* 6 */ "kern_invalid",
248 /* 7 */ "kern_invalid",
249 /* 8 */ "kern_invalid",
250 /* 9 */ "kern_invalid",
251 /* 10 */ "_kernelrpc_mach_vm_allocate_trap",
252 /* 11 */ "kern_invalid",
253 /* 12 */ "_kernelrpc_mach_vm_deallocate_trap",
254 /* 13 */ "kern_invalid",
255 /* 14 */ "_kernelrpc_mach_vm_protect_trap",
256 /* 15 */ "kern_invalid",
257 /* 16 */ "_kernelrpc_mach_port_allocate_trap",
258 /* 17 */ "_kernelrpc_mach_port_destroy_trap",
259 /* 18 */ "_kernelrpc_mach_port_deallocate_trap",
260 /* 19 */ "_kernelrpc_mach_port_mod_refs_trap",
261 /* 20 */ "_kernelrpc_mach_port_move_member_trap",
262 /* 21 */ "_kernelrpc_mach_port_insert_right_trap",
263 /* 22 */ "_kernelrpc_mach_port_insert_member_trap",
264 /* 23 */ "_kernelrpc_mach_port_extract_member_trap",
265 /* 24 */ "kern_invalid",
266 /* 25 */ "kern_invalid",
267 /* 26 */ "mach_reply_port",
268 /* 27 */ "thread_self_trap",
269 /* 28 */ "task_self_trap",
270 /* 29 */ "host_self_trap",
271 /* 30 */ "kern_invalid",
272 /* 31 */ "mach_msg_trap",
273 /* 32 */ "mach_msg_overwrite_trap",
274 /* 33 */ "semaphore_signal_trap",
275 /* 34 */ "semaphore_signal_all_trap",
276 /* 35 */ "semaphore_signal_thread_trap",
277 /* 36 */ "semaphore_wait_trap",
278 /* 37 */ "semaphore_wait_signal_trap",
279 /* 38 */ "semaphore_timedwait_trap",
280 /* 39 */ "semaphore_timedwait_signal_trap",
281 /* 40 */ "kern_invalid",
282 /* 41 */ "kern_invalid",
283 /* 42 */ "kern_invalid",
285 /* 44 */ "task_name_for_pid",
286 /* 45 */ "task_for_pid",
287 /* 46 */ "pid_for_task",
288 /* 47 */ "kern_invalid",
289 /* 48 */ "macx_swapon",
290 /* 49 */ "macx_swapoff",
291 /* 50 */ "kern_invalid",
292 /* 51 */ "macx_triggers",
293 /* 52 */ "macx_backing_store_suspend",
294 /* 53 */ "macx_backing_store_recovery",
295 /* 54 */ "kern_invalid",
296 /* 55 */ "kern_invalid",
297 /* 56 */ "kern_invalid",
298 /* 57 */ "kern_invalid",
300 /* 59 */ "swtch_pri",
302 /* 61 */ "thread_switch",
303 /* 62 */ "clock_sleep_trap",
304 /* 63 */ "kern_invalid",
305 /* traps 64 - 95 reserved (debo) */
306 /* 64 */ "kern_invalid",
307 /* 65 */ "kern_invalid",
308 /* 66 */ "kern_invalid",
309 /* 67 */ "kern_invalid",
310 /* 68 */ "kern_invalid",
311 /* 69 */ "kern_invalid",
312 /* 70 */ "kern_invalid",
313 /* 71 */ "kern_invalid",
314 /* 72 */ "kern_invalid",
315 /* 73 */ "kern_invalid",
316 /* 74 */ "kern_invalid",
317 /* 75 */ "kern_invalid",
318 /* 76 */ "kern_invalid",
319 /* 77 */ "kern_invalid",
320 /* 78 */ "kern_invalid",
321 /* 79 */ "kern_invalid",
322 /* 80 */ "kern_invalid",
323 /* 81 */ "kern_invalid",
324 /* 82 */ "kern_invalid",
325 /* 83 */ "kern_invalid",
326 /* 84 */ "kern_invalid",
327 /* 85 */ "kern_invalid",
328 /* 86 */ "kern_invalid",
329 /* 87 */ "kern_invalid",
330 /* 88 */ "kern_invalid",
331 /* 89 */ "mach_timebase_info_trap",
332 /* 90 */ "mach_wait_until_trap",
333 /* 91 */ "mk_timer_create_trap",
334 /* 92 */ "mk_timer_destroy_trap",
335 /* 93 */ "mk_timer_arm_trap",
336 /* 94 */ "mk_timer_cancel_trap",
337 /* 95 */ "kern_invalid",
338 /* traps 64 - 95 reserved (debo) */
339 /* 96 */ "kern_invalid",
340 /* 97 */ "kern_invalid",
341 /* 98 */ "kern_invalid",
342 /* 99 */ "kern_invalid",
343 /* traps 100-107 reserved for iokit (esb) */
344 /* 100 */ "kern_invalid",
345 /* 100 */ //"iokit_user_client_trap",
346 /* 101 */ "kern_invalid",
347 /* 102 */ "kern_invalid",
348 /* 103 */ "kern_invalid",
349 /* 104 */ "kern_invalid",
350 /* 105 */ "kern_invalid",
351 /* 106 */ "kern_invalid",
352 /* 107 */ "kern_invalid",
353 /* traps 108-127 unused */
354 /* 108 */ "kern_invalid",
355 /* 109 */ "kern_invalid",
356 /* 110 */ "kern_invalid",
357 /* 111 */ "kern_invalid",
358 /* 112 */ "kern_invalid",
359 /* 113 */ "kern_invalid",
360 /* 114 */ "kern_invalid",
361 /* 115 */ "kern_invalid",
362 /* 116 */ "kern_invalid",
363 /* 117 */ "kern_invalid",
364 /* 118 */ "kern_invalid",
365 /* 119 */ "kern_invalid",
366 /* 120 */ "kern_invalid",
367 /* 121 */ "kern_invalid",
368 /* 122 */ "kern_invalid",
369 /* 123 */ "kern_invalid",
370 /* 124 */ "kern_invalid",
371 /* 125 */ "kern_invalid",
372 /* 126 */ "kern_invalid",
373 /* 127 */ "kern_invalid",
376 int mach_trap_count
= (sizeof(mach_trap_table
) / sizeof(mach_trap_table
[0]));
380 __unused
struct kern_invalid_args
*args
)
382 if (kern_invalid_debug
) Debugger("kern_invalid mach trap");
383 return(KERN_INVALID_ARGUMENT
);