]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/mach/mach_port.c
xnu-4570.71.2.tar.gz
[apple/xnu.git] / libsyscall / mach / mach_port.c
1 /*
2 * Copyright (c) 2011 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 #include <mach/mach_port_internal.h>
30 #include <mach/mach.h>
31 #include <mach/mach_vm.h>
32 #include <mach/mach_traps.h>
33
34 kern_return_t
35 mach_port_names(
36 ipc_space_t task,
37 mach_port_name_array_t *names,
38 mach_msg_type_number_t *namesCnt,
39 mach_port_type_array_t *types,
40 mach_msg_type_number_t *typesCnt)
41 {
42 kern_return_t rv;
43
44 rv = _kernelrpc_mach_port_names(task, names, namesCnt, types,
45 typesCnt);
46
47 return (rv);
48 }
49
50 kern_return_t
51 mach_port_type(
52 ipc_space_t task,
53 mach_port_name_t name,
54 mach_port_type_t *ptype)
55 {
56 kern_return_t rv;
57
58 rv = _kernelrpc_mach_port_type(task, name, ptype);
59
60 return (rv);
61 }
62
63 kern_return_t
64 mach_port_rename(
65 ipc_space_t task,
66 mach_port_name_t old_name,
67 mach_port_name_t new_name)
68 {
69 kern_return_t rv;
70
71 rv = _kernelrpc_mach_port_rename(task, old_name, new_name);
72
73 return (rv);
74 }
75
76 kern_return_t
77 mach_port_allocate_name(
78 ipc_space_t task,
79 mach_port_right_t right,
80 mach_port_name_t name)
81 {
82 kern_return_t rv;
83
84 rv = _kernelrpc_mach_port_allocate_name(task, right, name);
85
86 return (rv);
87 }
88
89 kern_return_t
90 mach_port_allocate(
91 ipc_space_t task,
92 mach_port_right_t right,
93 mach_port_name_t *name)
94 {
95 kern_return_t rv;
96
97 rv = _kernelrpc_mach_port_allocate_trap(task, right, name);
98
99 if (rv == MACH_SEND_INVALID_DEST)
100 rv = _kernelrpc_mach_port_allocate(task, right, name);
101
102 return (rv);
103 }
104
105 kern_return_t
106 mach_port_destroy(
107 ipc_space_t task,
108 mach_port_name_t name)
109 {
110 kern_return_t rv;
111
112 rv = _kernelrpc_mach_port_destroy_trap(task, name);
113
114 if (rv == MACH_SEND_INVALID_DEST)
115 rv = _kernelrpc_mach_port_destroy(task, name);
116
117 return (rv);
118 }
119
120 kern_return_t
121 mach_port_deallocate(
122 ipc_space_t task,
123 mach_port_name_t name)
124 {
125 kern_return_t rv;
126
127 rv = _kernelrpc_mach_port_deallocate_trap(task, name);
128
129 if (rv == MACH_SEND_INVALID_DEST)
130 rv = _kernelrpc_mach_port_deallocate(task,name);
131
132 return (rv);
133 }
134
135 kern_return_t
136 mach_port_get_refs(
137 ipc_space_t task,
138 mach_port_name_t name,
139 mach_port_right_t right,
140 mach_port_urefs_t *refs)
141 {
142 kern_return_t rv;
143
144 rv = _kernelrpc_mach_port_get_refs(task, name, right, refs);
145
146 return (rv);
147 }
148
149 kern_return_t
150 mach_port_mod_refs(
151 ipc_space_t task,
152 mach_port_name_t name,
153 mach_port_right_t right,
154 mach_port_delta_t delta)
155 {
156 kern_return_t rv;
157
158 rv = _kernelrpc_mach_port_mod_refs_trap(task, name, right, delta);
159
160 if (rv == MACH_SEND_INVALID_DEST)
161 rv = _kernelrpc_mach_port_mod_refs(task, name, right, delta);
162
163 return (rv);
164 }
165
166 kern_return_t
167 mach_port_peek(
168 ipc_space_t task,
169 mach_port_name_t name,
170 mach_msg_trailer_type_t trailer_type,
171 mach_port_seqno_t *seqnop,
172 mach_msg_size_t *msg_sizep,
173 mach_msg_id_t *msg_idp,
174 mach_msg_trailer_info_t trailer_infop,
175 mach_msg_type_number_t *trailer_sizep)
176 {
177 kern_return_t rv;
178
179 rv = _kernelrpc_mach_port_peek(task, name, trailer_type,
180 seqnop, msg_sizep, msg_idp,
181 trailer_infop, trailer_sizep);
182
183 return (rv);
184 }
185
186 kern_return_t
187 mach_port_set_mscount(
188 ipc_space_t task,
189 mach_port_name_t name,
190 mach_port_mscount_t mscount)
191 {
192 kern_return_t rv;
193
194 rv = _kernelrpc_mach_port_set_mscount(task, name, mscount);
195
196 return (rv);
197 }
198
199 kern_return_t
200 mach_port_get_set_status(
201 ipc_space_t task,
202 mach_port_name_t name,
203 mach_port_name_array_t *members,
204 mach_msg_type_number_t *membersCnt)
205 {
206 kern_return_t rv;
207
208 rv = _kernelrpc_mach_port_get_set_status(task, name, members,
209 membersCnt);
210
211 return (rv);
212 }
213
214 kern_return_t
215 mach_port_move_member(
216 ipc_space_t task,
217 mach_port_name_t member,
218 mach_port_name_t after)
219 {
220 kern_return_t rv;
221
222 rv = _kernelrpc_mach_port_move_member_trap(task, member, after);
223
224 if (rv == MACH_SEND_INVALID_DEST)
225 rv = _kernelrpc_mach_port_move_member(task, member, after);
226
227 return (rv);
228 }
229
230 kern_return_t
231 mach_port_request_notification(
232 ipc_space_t task,
233 mach_port_name_t name,
234 mach_msg_id_t msgid,
235 mach_port_mscount_t sync,
236 mach_port_t notify,
237 mach_msg_type_name_t notifyPoly,
238 mach_port_t *previous)
239 {
240 kern_return_t rv;
241
242 rv = _kernelrpc_mach_port_request_notification(task, name, msgid,
243 sync, notify, notifyPoly, previous);
244
245 return (rv);
246 }
247
248 kern_return_t
249 mach_port_insert_right(
250 ipc_space_t task,
251 mach_port_name_t name,
252 mach_port_t poly,
253 mach_msg_type_name_t polyPoly)
254 {
255 kern_return_t rv;
256
257 rv = _kernelrpc_mach_port_insert_right_trap(task, name, poly, polyPoly);
258
259 if (rv == MACH_SEND_INVALID_DEST)
260 rv = _kernelrpc_mach_port_insert_right(task, name, poly,
261 polyPoly);
262
263 return (rv);
264 }
265
266 kern_return_t
267 mach_port_extract_right(
268 ipc_space_t task,
269 mach_port_name_t name,
270 mach_msg_type_name_t msgt_name,
271 mach_port_t *poly,
272 mach_msg_type_name_t *polyPoly)
273 {
274 kern_return_t rv;
275
276 rv = _kernelrpc_mach_port_extract_right(task, name, msgt_name,
277 poly, polyPoly);
278
279 return (rv);
280 }
281
282 kern_return_t
283 mach_port_set_seqno(
284 ipc_space_t task,
285 mach_port_name_t name,
286 mach_port_seqno_t seqno)
287 {
288 kern_return_t rv;
289
290 rv = _kernelrpc_mach_port_set_seqno(task, name, seqno);
291
292 return (rv);
293 }
294
295 kern_return_t
296 mach_port_get_attributes(
297 ipc_space_t task,
298 mach_port_name_t name,
299 mach_port_flavor_t flavor,
300 mach_port_info_t port_info_out,
301 mach_msg_type_number_t *port_info_outCnt)
302 {
303 kern_return_t rv;
304
305 rv = _kernelrpc_mach_port_get_attributes(task, name, flavor,
306 port_info_out, port_info_outCnt);
307
308 return (rv);
309 }
310
311 kern_return_t
312 mach_port_set_attributes(
313 ipc_space_t task,
314 mach_port_name_t name,
315 mach_port_flavor_t flavor,
316 mach_port_info_t port_info,
317 mach_msg_type_number_t port_infoCnt)
318 {
319 kern_return_t rv;
320
321 rv = _kernelrpc_mach_port_set_attributes(task, name, flavor,
322 port_info, port_infoCnt);
323
324 return (rv);
325 }
326
327 kern_return_t
328 mach_port_allocate_qos(
329 ipc_space_t task,
330 mach_port_right_t right,
331 mach_port_qos_t *qos,
332 mach_port_name_t *name)
333 {
334 kern_return_t rv;
335
336 rv = _kernelrpc_mach_port_allocate_qos(task, right, qos, name);
337
338 return (rv);
339 }
340
341 kern_return_t
342 mach_port_allocate_full(
343 ipc_space_t task,
344 mach_port_right_t right,
345 mach_port_t proto,
346 mach_port_qos_t *qos,
347 mach_port_name_t *name)
348 {
349 kern_return_t rv;
350
351 rv = _kernelrpc_mach_port_allocate_full(task, right, proto, qos, name);
352
353 return (rv);
354 }
355
356 kern_return_t
357 task_set_port_space(
358 ipc_space_t task,
359 int table_entries)
360 {
361 kern_return_t rv;
362
363 rv = _kernelrpc_task_set_port_space(task, table_entries);
364
365 return (rv);
366 }
367
368 kern_return_t
369 mach_port_get_srights(
370 ipc_space_t task,
371 mach_port_name_t name,
372 mach_port_rights_t *srights)
373 {
374 kern_return_t rv;
375
376 rv = _kernelrpc_mach_port_get_srights(task, name, srights);
377
378 return (rv);
379 }
380
381 kern_return_t
382 mach_port_space_info(
383 ipc_space_t task,
384 ipc_info_space_t *space_info,
385 ipc_info_name_array_t *table_info,
386 mach_msg_type_number_t *table_infoCnt,
387 ipc_info_tree_name_array_t *tree_info,
388 mach_msg_type_number_t *tree_infoCnt)
389 {
390 kern_return_t rv;
391
392 rv = _kernelrpc_mach_port_space_info(task, space_info, table_info,
393 table_infoCnt, tree_info, tree_infoCnt);
394
395 return (rv);
396 }
397
398 kern_return_t
399 mach_port_space_basic_info(
400 ipc_space_t task,
401 ipc_info_space_basic_t *space_basic_info)
402 {
403 kern_return_t rv;
404
405 rv = _kernelrpc_mach_port_space_basic_info(task, space_basic_info);
406
407 return (rv);
408 }
409
410 kern_return_t
411 mach_port_dnrequest_info(
412 ipc_space_t task,
413 mach_port_name_t name,
414 unsigned *dnr_total,
415 unsigned *dnr_used)
416 {
417 kern_return_t rv;
418
419 rv = _kernelrpc_mach_port_dnrequest_info(task, name, dnr_total,
420 dnr_used);
421
422 return (rv);
423 }
424
425 kern_return_t
426 mach_port_kernel_object(
427 ipc_space_t task,
428 mach_port_name_t name,
429 unsigned *object_type,
430 unsigned *object_addr)
431 {
432 kern_return_t rv;
433
434 rv = _kernelrpc_mach_port_kernel_object(task, name,
435 object_type, object_addr);
436
437 return (rv);
438 }
439
440 kern_return_t
441 mach_port_insert_member(
442 ipc_space_t task,
443 mach_port_name_t name,
444 mach_port_name_t pset)
445 {
446 kern_return_t rv;
447
448 rv = _kernelrpc_mach_port_insert_member_trap(task, name, pset);
449
450 if (rv == MACH_SEND_INVALID_DEST)
451 rv = _kernelrpc_mach_port_insert_member(task, name, pset);
452
453 return (rv);
454 }
455
456 kern_return_t
457 mach_port_extract_member(
458 ipc_space_t task,
459 mach_port_name_t name,
460 mach_port_name_t pset)
461 {
462 kern_return_t rv;
463
464 rv = _kernelrpc_mach_port_extract_member_trap(task, name, pset);
465
466 if (rv == MACH_SEND_INVALID_DEST)
467 rv = _kernelrpc_mach_port_extract_member(task, name, pset);
468
469 return (rv);
470 }
471
472 kern_return_t
473 mach_port_get_context(
474 ipc_space_t task,
475 mach_port_name_t name,
476 mach_port_context_t *context)
477 {
478 kern_return_t rv;
479 mach_vm_address_t wide_context;
480
481 rv = _kernelrpc_mach_port_get_context(task, name, &wide_context);
482
483 if (rv == KERN_SUCCESS) {
484 *context = (mach_port_context_t)wide_context;
485 }
486
487 return (rv);
488 }
489
490 kern_return_t
491 mach_port_set_context(
492 ipc_space_t task,
493 mach_port_name_t name,
494 mach_port_context_t context)
495 {
496 kern_return_t rv;
497
498 rv = _kernelrpc_mach_port_set_context(task, name, context);
499
500 return (rv);
501 }
502
503 kern_return_t
504 mach_port_kobject(
505 ipc_space_t task,
506 mach_port_name_t name,
507 natural_t *object_type,
508 mach_vm_address_t *object_addr)
509 {
510 kern_return_t rv;
511
512 rv = _kernelrpc_mach_port_kobject(task, name, object_type, object_addr);
513
514 return (rv);
515 }
516
517 kern_return_t
518 mach_port_construct(
519 ipc_space_t task,
520 mach_port_options_t *options,
521 mach_port_context_t context,
522 mach_port_name_t *name)
523 {
524 kern_return_t rv;
525
526 rv = _kernelrpc_mach_port_construct_trap(task, options, (uint64_t) context, name);
527
528 if (rv == MACH_SEND_INVALID_DEST)
529 rv = _kernelrpc_mach_port_construct(task, options, (uint64_t) context, name);
530
531 return (rv);
532 }
533
534 kern_return_t
535 mach_port_destruct(
536 ipc_space_t task,
537 mach_port_name_t name,
538 mach_port_delta_t srdelta,
539 mach_port_context_t guard)
540 {
541 kern_return_t rv;
542
543 rv = _kernelrpc_mach_port_destruct_trap(task, name, srdelta, (uint64_t) guard);
544
545 if (rv == MACH_SEND_INVALID_DEST)
546 rv = _kernelrpc_mach_port_destruct(task, name, srdelta, (uint64_t) guard);
547
548 return (rv);
549
550 }
551
552 kern_return_t
553 mach_port_guard(
554 ipc_space_t task,
555 mach_port_name_t name,
556 mach_port_context_t guard,
557 boolean_t strict)
558 {
559 kern_return_t rv;
560
561 rv = _kernelrpc_mach_port_guard_trap(task, name, (uint64_t) guard, strict);
562
563 if (rv == MACH_SEND_INVALID_DEST)
564 rv = _kernelrpc_mach_port_guard(task, name, (uint64_t) guard, strict);
565
566 return (rv);
567
568 }
569
570 kern_return_t
571 mach_port_unguard(
572 ipc_space_t task,
573 mach_port_name_t name,
574 mach_port_context_t guard)
575 {
576 kern_return_t rv;
577
578 rv = _kernelrpc_mach_port_unguard_trap(task, name, (uint64_t) guard);
579
580 if (rv == MACH_SEND_INVALID_DEST)
581 rv = _kernelrpc_mach_port_unguard(task, name, (uint64_t) guard);
582
583 return (rv);
584
585 }
586
587 extern kern_return_t
588 _kernelrpc_mach_voucher_extract_attr_recipe(
589 mach_port_name_t voucher,
590 mach_voucher_attr_key_t key,
591 mach_voucher_attr_raw_recipe_t recipe,
592 mach_msg_type_number_t *recipe_size);
593
594 kern_return_t
595 mach_voucher_extract_attr_recipe(
596 mach_port_name_t voucher,
597 mach_voucher_attr_key_t key,
598 mach_voucher_attr_raw_recipe_t recipe,
599 mach_msg_type_number_t *recipe_size)
600 {
601 kern_return_t rv;
602
603 rv = mach_voucher_extract_attr_recipe_trap(voucher, key, recipe, recipe_size);
604
605 #ifdef __x86_64__
606 /* REMOVE once XBS kernel has new trap */
607 if (rv == ((1 << 24) | 72)) /* see mach/i386/syscall_sw.h */
608 rv = MACH_SEND_INVALID_DEST;
609 #elif defined(__i386__)
610 /* REMOVE once XBS kernel has new trap */
611 if (rv == (kern_return_t)(-72))
612 rv = MACH_SEND_INVALID_DEST;
613 #endif
614
615 if (rv == MACH_SEND_INVALID_DEST)
616 rv = _kernelrpc_mach_voucher_extract_attr_recipe(voucher, key, recipe, recipe_size);
617
618 return rv;
619 }