1/*
2 * Copyright (c) 2000-2005, 2020 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 * @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>
60#include <mach/mach_traps.h>
61
62#include <kern/syscall_sw.h>
63#if CONFIG_REQUIRES_U32_MUNGING
64#include <sys/munge.h>
65#endif
66
67/* Forwards */
68
69
70/*
71 * To add a new entry:
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.
79 *
80 * Also, add trap definition to mach/syscall_sw.h and
81 * recompile user library.
82 *
83 *
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
104
105const mach_trap_t mach_trap_table[MACH_TRAP_TABLE_COUNT] = {
106/* 0 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
107/* 1 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
108/* 2 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
109/* 3 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
110/* 4 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
111/* 5 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
112/* 6 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
113/* 7 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
114/* 8 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
115/* 9 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
116/* 10 */ MACH_TRAP(_kernelrpc_mach_vm_allocate_trap, 4, 5, munge_wwlw),
117/* 11 */ MACH_TRAP(_kernelrpc_mach_vm_purgable_control_trap, 4, 5, munge_wlww),
118/* 12 */ MACH_TRAP(_kernelrpc_mach_vm_deallocate_trap, 3, 5, munge_wll),
119/* 13 */ MACH_TRAP(task_dyld_process_info_notify_get_trap, 2, 4, munge_ll),
120/* 14 */ MACH_TRAP(_kernelrpc_mach_vm_protect_trap, 5, 7, munge_wllww),
121/* 15 */ MACH_TRAP(_kernelrpc_mach_vm_map_trap, 6, 8, munge_wwllww),
122/* 16 */ MACH_TRAP(_kernelrpc_mach_port_allocate_trap, 3, 3, munge_www),
123/* 17 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
124/* 18 */ MACH_TRAP(_kernelrpc_mach_port_deallocate_trap, 2, 2, munge_ww),
125/* 19 */ MACH_TRAP(_kernelrpc_mach_port_mod_refs_trap, 4, 4, munge_wwww),
126/* 20 */ MACH_TRAP(_kernelrpc_mach_port_move_member_trap, 3, 3, munge_www),
127/* 21 */ MACH_TRAP(_kernelrpc_mach_port_insert_right_trap, 4, 4, munge_wwww),
128/* 22 */ MACH_TRAP(_kernelrpc_mach_port_insert_member_trap, 3, 3, munge_www),
129/* 23 */ MACH_TRAP(_kernelrpc_mach_port_extract_member_trap, 3, 3, munge_www),
130/* 24 */ MACH_TRAP(_kernelrpc_mach_port_construct_trap, 4, 5, munge_wwlw),
131/* 25 */ MACH_TRAP(_kernelrpc_mach_port_destruct_trap, 4, 5, munge_wwwl),
132/* 26 */ MACH_TRAP(mach_reply_port, 0, 0, NULL, .mach_trap_returns_port = 1),
133/* 27 */ MACH_TRAP(thread_self_trap, 0, 0, NULL, .mach_trap_returns_port = 1),
134/* 28 */ MACH_TRAP(task_self_trap, 0, 0, NULL, .mach_trap_returns_port = 1),
135/* 29 */ MACH_TRAP(host_self_trap, 0, 0, NULL, .mach_trap_returns_port = 1),
136/* 30 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
137/* 31 */ MACH_TRAP(mach_msg_trap, 7, 7, munge_wwwwwww),
138/* 32 */ MACH_TRAP(mach_msg_overwrite_trap, 8, 8, munge_wwwwwwww),
139/* 33 */ MACH_TRAP(semaphore_signal_trap, 1, 1, munge_w),
140/* 34 */ MACH_TRAP(semaphore_signal_all_trap, 1, 1, munge_w),
141/* 35 */ MACH_TRAP(semaphore_signal_thread_trap, 2, 2, munge_ww),
142/* 36 */ MACH_TRAP(semaphore_wait_trap, 1, 1, munge_w),
143/* 37 */ MACH_TRAP(semaphore_wait_signal_trap, 2, 2, munge_ww),
144/* 38 */ MACH_TRAP(semaphore_timedwait_trap, 3, 3, munge_www),
145/* 39 */ MACH_TRAP(semaphore_timedwait_signal_trap, 4, 4, munge_wwww),
146/* 40 */ MACH_TRAP(_kernelrpc_mach_port_get_attributes_trap, 5, 5, munge_wwwww),
147/* 41 */ MACH_TRAP(_kernelrpc_mach_port_guard_trap, 4, 5, munge_wwlw),
148/* 42 */ MACH_TRAP(_kernelrpc_mach_port_unguard_trap, 3, 4, munge_wwl),
149/* 43 */ MACH_TRAP(mach_generate_activity_id, 3, 3, munge_www),
150/* 44 */ MACH_TRAP(task_name_for_pid, 3, 3, munge_www),
151/* 45 */ MACH_TRAP(task_for_pid, 3, 3, munge_www),
152/* 46 */ MACH_TRAP(pid_for_task, 2, 2, munge_ww),
153#if defined(__LP64__) || defined(__arm64__)
154/* 47 */ MACH_TRAP(mach_msg2_trap, 8, 16, munge_llllllll),
155#else
156/* 47 */ MACH_TRAP(kern_invalid, 0, 0, NULL), /* Do not take */
157#endif
158/* 48 */ MACH_TRAP(macx_swapon, 4, 5, munge_lwww),
159/* 49 */ MACH_TRAP(macx_swapoff, 2, 3, munge_lw),
160/* 50 */ MACH_TRAP(thread_get_special_reply_port, 0, 0, NULL, .mach_trap_returns_port = 1),
161/* 51 */ MACH_TRAP(macx_triggers, 4, 4, munge_wwww),
162/* 52 */ MACH_TRAP(macx_backing_store_suspend, 1, 1, munge_w),
163/* 53 */ MACH_TRAP(macx_backing_store_recovery, 1, 1, munge_w),
164/* 54 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
165/* 55 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
166/* 56 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
167/* 57 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
168/* 58 */ MACH_TRAP(pfz_exit, 0, 0, NULL),
169/* 59 */ MACH_TRAP(swtch_pri, 0, 0, NULL),
170/* 60 */ MACH_TRAP(swtch, 0, 0, NULL),
171/* 61 */ MACH_TRAP(thread_switch, 3, 3, munge_www),
172/* 62 */ MACH_TRAP(clock_sleep_trap, 5, 5, munge_wwwww),
173/* 63 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
174/* 64 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
175/* 65 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
176/* 66 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
177/* 67 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
178/* 68 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
179/* 69 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
180/* 70 */ MACH_TRAP(host_create_mach_voucher_trap, 4, 4, munge_wwww),
181/* 71 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
182/* 72 */ MACH_TRAP(mach_voucher_extract_attr_recipe_trap, 4, 4, munge_wwww),
183/* 73 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
184/* 74 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
185/* 75 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
186/* 76 */ MACH_TRAP(_kernelrpc_mach_port_type_trap, 3, 3, munge_wwww),
187/* 77 */ MACH_TRAP(_kernelrpc_mach_port_request_notification_trap, 7, 7, munge_wwwwwww),
188/* 78 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
189/* 79 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
190/* 80 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
191/* 81 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
192/* 82 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
193/* 83 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
194/* 84 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
195/* 85 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
196/* 86 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
197/* 87 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
198/* 88 */ MACH_TRAP(_exclaves_ctl_trap, 7, 12, munge_wwlllll),
199/* 89 */ MACH_TRAP(mach_timebase_info_trap, 1, 1, munge_w),
200/* 90 */ MACH_TRAP(mach_wait_until_trap, 1, 2, munge_l),
201/* 91 */ MACH_TRAP(mk_timer_create_trap, 0, 0, NULL, .mach_trap_returns_port = 1),
202/* 92 */ MACH_TRAP(mk_timer_destroy_trap, 1, 1, munge_w),
203/* 93 */ MACH_TRAP(mk_timer_arm_trap, 2, 3, munge_wl),
204/* 94 */ MACH_TRAP(mk_timer_cancel_trap, 2, 2, munge_ww),
205/* 95 */ MACH_TRAP(mk_timer_arm_leeway_trap, 4, 6, munge_wlll),
206/* 96 */ MACH_TRAP(debug_control_port_for_pid, 3, 3, munge_www),
207/* 97 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
208/* 98 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
209/* 99 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
210/* traps 100-107 reserved for IOKit */
211/* 100 */ MACH_TRAP(iokit_user_client_trap, 8, 8, munge_wwwwwwww),
212/* 101 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
213/* 102 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
214/* 103 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
215/* 104 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
216/* 105 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
217/* 106 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
218/* 107 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
219/* 108 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
220/* 109 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
221/* 110 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
222/* 111 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
223/* 112 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
224/* 113 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
225/* 114 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
226/* 115 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
227/* 116 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
228/* 117 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
229/* 118 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
230/* 119 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
231/* 120 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
232/* 121 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
233/* 122 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
234/* 123 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
235/* 124 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
236/* 125 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
237/* 126 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
238/* 127 */ MACH_TRAP(kern_invalid, 0, 0, NULL),
239};
240
241const char * const mach_syscall_name_table[MACH_TRAP_TABLE_COUNT] = {
242/* 0 */ "kern_invalid",
243/* 1 */ "kern_invalid",
244/* 2 */ "kern_invalid",
245/* 3 */ "kern_invalid",
246/* 4 */ "kern_invalid",
247/* 5 */ "kern_invalid",
248/* 6 */ "kern_invalid",
249/* 7 */ "kern_invalid",
250/* 8 */ "kern_invalid",
251/* 9 */ "kern_invalid",
252/* 10 */ "_kernelrpc_mach_vm_allocate_trap",
253/* 11 */ "_kernelrpc_mach_vm_purgable_control_trap",
254/* 12 */ "_kernelrpc_mach_vm_deallocate_trap",
255/* 13 */ "task_dyld_process_info_notify_get_trap",
256/* 14 */ "_kernelrpc_mach_vm_protect_trap",
257/* 15 */ "_kernelrpc_mach_vm_map_trap",
258/* 16 */ "_kernelrpc_mach_port_allocate_trap",
259/* 17 */ "kern_invalid",
260/* 18 */ "_kernelrpc_mach_port_deallocate_trap",
261/* 19 */ "_kernelrpc_mach_port_mod_refs_trap",
262/* 20 */ "_kernelrpc_mach_port_move_member_trap",
263/* 21 */ "_kernelrpc_mach_port_insert_right_trap",
264/* 22 */ "_kernelrpc_mach_port_insert_member_trap",
265/* 23 */ "_kernelrpc_mach_port_extract_member_trap",
266/* 24 */ "_kernelrpc_mach_port_construct_trap",
267/* 25 */ "_kernelrpc_mach_port_destruct_trap",
268/* 26 */ "mach_reply_port",
269/* 27 */ "thread_self_trap",
270/* 28 */ "task_self_trap",
271/* 29 */ "host_self_trap",
272/* 30 */ "kern_invalid",
273/* 31 */ "mach_msg_trap",
274/* 32 */ "mach_msg_overwrite_trap",
275/* 33 */ "semaphore_signal_trap",
276/* 34 */ "semaphore_signal_all_trap",
277/* 35 */ "semaphore_signal_thread_trap",
278/* 36 */ "semaphore_wait_trap",
279/* 37 */ "semaphore_wait_signal_trap",
280/* 38 */ "semaphore_timedwait_trap",
281/* 39 */ "semaphore_timedwait_signal_trap",
282/* 40 */ "_kernelrpc_mach_port_get_attributes_trap",
283/* 41 */ "_kernelrpc_mach_port_guard_trap",
284/* 42 */ "_kernelrpc_mach_port_unguard_trap",
285/* 43 */ "mach_generate_activity_id",
286/* 44 */ "task_name_for_pid",
287/* 45 */ "task_for_pid",
288/* 46 */ "pid_for_task",
289#if defined(__LP64__) || defined(__arm64__)
290/* 47 */ "mach_msg2_trap",
291#else
292/* 47 */ "kern_invalid",
293#endif
294/* 48 */ "macx_swapon",
295/* 49 */ "macx_swapoff",
296/* 50 */ "thread_get_special_reply_port",
297/* 51 */ "macx_triggers",
298/* 52 */ "macx_backing_store_suspend",
299/* 53 */ "macx_backing_store_recovery",
300/* 54 */ "kern_invalid",
301/* 55 */ "kern_invalid",
302/* 56 */ "kern_invalid",
303/* 57 */ "kern_invalid",
304/* 58 */ "pfz_exit",
305/* 59 */ "swtch_pri",
306/* 60 */ "swtch",
307/* 61 */ "thread_switch",
308/* 62 */ "clock_sleep_trap",
309/* 63 */ "kern_invalid",
310/* traps 64 - 95 reserved (debo) */
311/* 64 */ "kern_invalid",
312/* 65 */ "kern_invalid",
313/* 66 */ "kern_invalid",
314/* 67 */ "kern_invalid",
315/* 68 */ "kern_invalid",
316/* 69 */ "kern_invalid",
317/* 70 */ "host_create_mach_voucher_trap",
318/* 71 */ "kern_invalid",
319/* 72 */ "mach_voucher_extract_attr_recipe_trap",
320/* 73 */ "kern_invalid",
321/* 74 */ "kern_invalid",
322/* 75 */ "kern_invalid",
323/* 76 */ "_kernelrpc_mach_port_type_trap",
324/* 77 */ "_kernelrpc_mach_port_request_notification_trap",
325/* 78 */ "kern_invalid",
326/* 79 */ "kern_invalid",
327/* 80 */ "kern_invalid",
328/* 81 */ "kern_invalid",
329/* 82 */ "kern_invalid",
330/* 83 */ "kern_invalid",
331/* 84 */ "kern_invalid",
332/* 85 */ "kern_invalid",
333/* 86 */ "kern_invalid",
334/* 87 */ "kern_invalid",
335/* 88 */ "_exclaves_ctl_trap",
336/* 89 */ "mach_timebase_info_trap",
337/* 90 */ "mach_wait_until_trap",
338/* 91 */ "mk_timer_create_trap",
339/* 92 */ "mk_timer_destroy_trap",
340/* 93 */ "mk_timer_arm_trap",
341/* 94 */ "mk_timer_cancel_trap",
342/* 95 */ "mk_timer_arm_leeway_trap",
343/* traps 64 - 95 reserved (debo) */
344/* 96 */ "debug_control_port_for_pid",
345/* 97 */ "kern_invalid",
346/* 98 */ "kern_invalid",
347/* 99 */ "kern_invalid",
348/* traps 100-107 reserved for iokit (esb) */
349/* 100 */ "iokit_user_client_trap",
350/* 101 */ "kern_invalid",
351/* 102 */ "kern_invalid",
352/* 103 */ "kern_invalid",
353/* 104 */ "kern_invalid",
354/* 105 */ "kern_invalid",
355/* 106 */ "kern_invalid",
356/* 107 */ "kern_invalid",
357/* traps 108-127 unused */
358/* 108 */ "kern_invalid",
359/* 109 */ "kern_invalid",
360/* 110 */ "kern_invalid",
361/* 111 */ "kern_invalid",
362/* 112 */ "kern_invalid",
363/* 113 */ "kern_invalid",
364/* 114 */ "kern_invalid",
365/* 115 */ "kern_invalid",
366/* 116 */ "kern_invalid",
367/* 117 */ "kern_invalid",
368/* 118 */ "kern_invalid",
369/* 119 */ "kern_invalid",
370/* 120 */ "kern_invalid",
371/* 121 */ "kern_invalid",
372/* 122 */ "kern_invalid",
373/* 123 */ "kern_invalid",
374/* 124 */ "kern_invalid",
375/* 125 */ "kern_invalid",
376/* 126 */ "kern_invalid",
377/* 127 */ "kern_invalid",
378};
379
380const int mach_trap_count = (sizeof(mach_trap_table) / sizeof(mach_trap_table[0]));
381
382kern_return_t
383kern_invalid(
384 __unused struct kern_invalid_args *args)
385{
386 if (kern_invalid_debug) {
387 Debugger(message: "kern_invalid mach trap");
388 }
389 return KERN_INVALID_ARGUMENT;
390}
391