]> git.saurik.com Git - apple/xnu.git/blobdiff - libsyscall/mach/mach_port.c
xnu-6153.81.5.tar.gz
[apple/xnu.git] / libsyscall / mach / mach_port.c
index 3219d730162e105c135e215075b1249ae886f81c..57d67509466e616870fe0f203631cc25dbd7ca86 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2011 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * unlawful or unlicensed copies of an Apple operating system, or to
  * circumvent, violate, or enable the circumvention or violation of, any
  * terms of an Apple operating system software license agreement.
- * 
+ *
  * Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -22,7 +22,7 @@
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
@@ -33,6 +33,7 @@
 #include <mach/mach_sync_ipc.h>
 #include "tsd.h"
 
+
 kern_return_t
 mach_port_names(
        ipc_space_t task,
@@ -44,9 +45,9 @@ mach_port_names(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_names(task, names, namesCnt, types,
-                       typesCnt);
+           typesCnt);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -57,9 +58,13 @@ mach_port_type(
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_type(task, name, ptype);
+       rv = _kernelrpc_mach_port_type_trap(task, name, ptype);
 
-       return (rv);
+       if (rv == MACH_SEND_INVALID_DEST) {
+               rv = _kernelrpc_mach_port_type(task, name, ptype);
+       }
+
+       return rv;
 }
 
 kern_return_t
@@ -72,7 +77,7 @@ mach_port_rename(
 
        rv = _kernelrpc_mach_port_rename(task, old_name, new_name);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -85,7 +90,7 @@ mach_port_allocate_name(
 
        rv = _kernelrpc_mach_port_allocate_name(task, right, name);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -98,10 +103,11 @@ mach_port_allocate(
 
        rv = _kernelrpc_mach_port_allocate_trap(task, right, name);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_allocate(task, right, name);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -113,10 +119,11 @@ mach_port_destroy(
 
        rv = _kernelrpc_mach_port_destroy_trap(task, name);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_destroy(task, name);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -126,12 +133,13 @@ mach_port_deallocate(
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_deallocate_trap(task, name); 
+       rv = _kernelrpc_mach_port_deallocate_trap(task, name);
 
-       if (rv == MACH_SEND_INVALID_DEST)
-               rv = _kernelrpc_mach_port_deallocate(task,name);
+       if (rv == MACH_SEND_INVALID_DEST) {
+               rv = _kernelrpc_mach_port_deallocate(task, name);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -145,7 +153,7 @@ mach_port_get_refs(
 
        rv = _kernelrpc_mach_port_get_refs(task, name, right, refs);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -157,32 +165,33 @@ mach_port_mod_refs(
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_mod_refs_trap(task, name, right, delta); 
+       rv = _kernelrpc_mach_port_mod_refs_trap(task, name, right, delta);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_mod_refs(task, name, right, delta);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
 mach_port_peek(
-       ipc_space_t             task,
-       mach_port_name_t        name,
+       ipc_space_t             task,
+       mach_port_name_t        name,
        mach_msg_trailer_type_t trailer_type,
-       mach_port_seqno_t       *seqnop,
-       mach_msg_size_t         *msg_sizep,
-       mach_msg_id_t           *msg_idp,
+       mach_port_seqno_t       *seqnop,
+       mach_msg_size_t         *msg_sizep,
+       mach_msg_id_t           *msg_idp,
        mach_msg_trailer_info_t trailer_infop,
-       mach_msg_type_number_t  *trailer_sizep)
+       mach_msg_type_number_t  *trailer_sizep)
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_peek(task, name, trailer_type, 
-                                      seqnop, msg_sizep, msg_idp,
-                                      trailer_infop, trailer_sizep);
+       rv = _kernelrpc_mach_port_peek(task, name, trailer_type,
+           seqnop, msg_sizep, msg_idp,
+           trailer_infop, trailer_sizep);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -195,7 +204,7 @@ mach_port_set_mscount(
 
        rv = _kernelrpc_mach_port_set_mscount(task, name, mscount);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -208,9 +217,9 @@ mach_port_get_set_status(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_get_set_status(task, name, members,
-                       membersCnt);
+           membersCnt);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -223,10 +232,11 @@ mach_port_move_member(
 
        rv = _kernelrpc_mach_port_move_member_trap(task, member, after);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_move_member(task, member, after);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -241,10 +251,15 @@ mach_port_request_notification(
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_request_notification(task, name, msgid,
-               sync, notify, notifyPoly, previous);
+       rv = _kernelrpc_mach_port_request_notification_trap(task, name, msgid,
+           sync, notify, notifyPoly, previous);
+
+       if (rv == MACH_SEND_INVALID_DEST) {
+               rv = _kernelrpc_mach_port_request_notification(task, name, msgid,
+                   sync, notify, notifyPoly, previous);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -256,13 +271,14 @@ mach_port_insert_right(
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_insert_right_trap(task, name, poly, polyPoly); 
+       rv = _kernelrpc_mach_port_insert_right_trap(task, name, poly, polyPoly);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_insert_right(task, name, poly,
                    polyPoly);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -276,9 +292,9 @@ mach_port_extract_right(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_extract_right(task, name, msgt_name,
-               poly, polyPoly);
+           poly, polyPoly);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -291,7 +307,7 @@ mach_port_set_seqno(
 
        rv = _kernelrpc_mach_port_set_seqno(task, name, seqno);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -305,23 +321,26 @@ mach_port_get_attributes(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_get_attributes_trap(task, name, flavor,
-                       port_info_out, port_info_outCnt);
+           port_info_out, port_info_outCnt);
 
 #ifdef __x86_64__
        /* REMOVE once XBS kernel has new trap */
-       if (rv == ((1 << 24) | 40)) /* see mach/i386/syscall_sw.h */
+       if (rv == ((1 << 24) | 40)) /* see mach/i386/syscall_sw.h */
                rv = MACH_SEND_INVALID_DEST;
+       }
 #elif defined(__i386__)
        /* REMOVE once XBS kernel has new trap */
-       if (rv == (kern_return_t)(-40))
+       if (rv == (kern_return_t)(-40)) {
                rv = MACH_SEND_INVALID_DEST;
+       }
 #endif
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_get_attributes(task, name, flavor,
-                               port_info_out, port_info_outCnt);
+                   port_info_out, port_info_outCnt);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -335,9 +354,9 @@ mach_port_set_attributes(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_set_attributes(task, name, flavor,
-                       port_info, port_infoCnt);
+           port_info, port_infoCnt);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -351,7 +370,7 @@ mach_port_allocate_qos(
 
        rv = _kernelrpc_mach_port_allocate_qos(task, right, qos, name);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -366,7 +385,7 @@ mach_port_allocate_full(
 
        rv = _kernelrpc_mach_port_allocate_full(task, right, proto, qos, name);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -378,7 +397,7 @@ task_set_port_space(
 
        rv = _kernelrpc_task_set_port_space(task, table_entries);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -391,7 +410,7 @@ mach_port_get_srights(
 
        rv = _kernelrpc_mach_port_get_srights(task, name, srights);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -406,9 +425,9 @@ mach_port_space_info(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_space_info(task, space_info, table_info,
-                       table_infoCnt, tree_info, tree_infoCnt);
+           table_infoCnt, tree_info, tree_infoCnt);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -420,7 +439,7 @@ mach_port_space_basic_info(
 
        rv = _kernelrpc_mach_port_space_basic_info(task, space_basic_info);
 
-       return (rv);
+       return rv;
 }
 
 static inline mach_port_t
@@ -520,9 +539,9 @@ mach_port_dnrequest_info(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_dnrequest_info(task, name, dnr_total,
-                       dnr_used);
+           dnr_used);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -535,9 +554,9 @@ mach_port_kernel_object(
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_kernel_object(task, name,
-                       object_type, object_addr);
+           object_type, object_addr);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -550,10 +569,11 @@ mach_port_insert_member(
 
        rv = _kernelrpc_mach_port_insert_member_trap(task, name, pset);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_insert_member(task, name, pset);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -564,12 +584,13 @@ mach_port_extract_member(
 {
        kern_return_t rv;
 
-       rv = _kernelrpc_mach_port_extract_member_trap(task, name, pset); 
+       rv = _kernelrpc_mach_port_extract_member_trap(task, name, pset);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_extract_member(task, name, pset);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -587,7 +608,7 @@ mach_port_get_context(
                *context = (mach_port_context_t)wide_context;
        }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -600,7 +621,7 @@ mach_port_set_context(
 
        rv = _kernelrpc_mach_port_set_context(task, name, context);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
@@ -614,85 +635,86 @@ mach_port_kobject(
 
        rv = _kernelrpc_mach_port_kobject(task, name, object_type, object_addr);
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
 mach_port_construct(
-       ipc_space_t             task,
-       mach_port_options_t     *options,
-       mach_port_context_t     context,
-       mach_port_name_t        *name)
+       ipc_space_t             task,
+       mach_port_options_t     *options,
+       mach_port_context_t     context,
+       mach_port_name_t        *name)
 {
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_construct_trap(task, options, (uint64_t) context, name);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_construct(task, options, (uint64_t) context, name);
+       }
 
-       return (rv);
+       return rv;
 }
 
 kern_return_t
 mach_port_destruct(
-       ipc_space_t             task,
-       mach_port_name_t        name,
-       mach_port_delta_t       srdelta,
-       mach_port_context_t     guard)
+       ipc_space_t             task,
+       mach_port_name_t        name,
+       mach_port_delta_t       srdelta,
+       mach_port_context_t     guard)
 {
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_destruct_trap(task, name, srdelta, (uint64_t) guard);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_destruct(task, name, srdelta, (uint64_t) guard);
+       }
 
-       return (rv);
-
+       return rv;
 }
 
 kern_return_t
 mach_port_guard(
-       ipc_space_t             task,
-       mach_port_name_t        name,
-       mach_port_context_t     guard,
-       boolean_t               strict)
+       ipc_space_t             task,
+       mach_port_name_t        name,
+       mach_port_context_t     guard,
+       boolean_t               strict)
 {
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_guard_trap(task, name, (uint64_t) guard, strict);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_guard(task, name, (uint64_t) guard, strict);
+       }
 
-       return (rv);
-
+       return rv;
 }
 
 kern_return_t
 mach_port_unguard(
-       ipc_space_t             task,
-       mach_port_name_t        name,
-       mach_port_context_t     guard)
+       ipc_space_t             task,
+       mach_port_name_t        name,
+       mach_port_context_t     guard)
 {
        kern_return_t rv;
 
        rv = _kernelrpc_mach_port_unguard_trap(task, name, (uint64_t) guard);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_port_unguard(task, name, (uint64_t) guard);
+       }
 
-       return (rv);
-
+       return rv;
 }
 
 extern kern_return_t
 _kernelrpc_mach_voucher_extract_attr_recipe(
-               mach_port_name_t voucher,
-               mach_voucher_attr_key_t key,
-               mach_voucher_attr_raw_recipe_t recipe,
-               mach_msg_type_number_t *recipe_size);
+       mach_port_name_t voucher,
+       mach_voucher_attr_key_t key,
+       mach_voucher_attr_raw_recipe_t recipe,
+       mach_msg_type_number_t *recipe_size);
 
 kern_return_t
 mach_voucher_extract_attr_recipe(
@@ -705,8 +727,9 @@ mach_voucher_extract_attr_recipe(
 
        rv = mach_voucher_extract_attr_recipe_trap(voucher, key, recipe, recipe_size);
 
-       if (rv == MACH_SEND_INVALID_DEST)
+       if (rv == MACH_SEND_INVALID_DEST) {
                rv = _kernelrpc_mach_voucher_extract_attr_recipe(voucher, key, recipe, recipe_size);
+       }
 
        return rv;
 }
@@ -714,8 +737,8 @@ mach_voucher_extract_attr_recipe(
 
 kern_return_t
 thread_destruct_special_reply_port(
-               mach_port_name_t port,
-               thread_destruct_special_reply_port_rights_t rights)
+       mach_port_name_t port,
+       thread_destruct_special_reply_port_rights_t rights)
 {
        switch (rights) {
        case THREAD_SPECIAL_REPLY_PORT_ALL:
@@ -731,3 +754,31 @@ thread_destruct_special_reply_port(
                return KERN_INVALID_ARGUMENT;
        }
 }
+
+kern_return_t
+mach_port_guard_with_flags(
+       ipc_space_t             task,
+       mach_port_name_t        name,
+       mach_port_context_t     guard,
+       uint64_t                flags)
+{
+       kern_return_t rv;
+
+       rv = _kernelrpc_mach_port_guard_with_flags(task, name, (uint64_t) guard, flags);
+
+       return rv;
+}
+
+kern_return_t
+mach_port_swap_guard(
+       ipc_space_t             task,
+       mach_port_name_t        name,
+       mach_port_context_t     old_guard,
+       mach_port_context_t     new_guard)
+{
+       kern_return_t rv;
+
+       rv = _kernelrpc_mach_port_swap_guard(task, name, (uint64_t)old_guard, (uint64_t)new_guard);
+
+       return rv;
+}