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