1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_MAC_MACH_PORT_UTIL_H_ 6 #define BASE_MAC_MACH_PORT_UTIL_H_ 7 8 #include <mach/mach.h> 9 10 #include "base/base_export.h" 11 #include "base/mac/scoped_mach_port.h" 12 13 namespace base { 14 15 enum class MachCreateError { 16 ERROR_MAKE_RECEIVE_PORT, 17 ERROR_SET_ATTRIBUTES, 18 ERROR_EXTRACT_DEST_RIGHT, 19 ERROR_SEND_MACH_PORT, 20 }; 21 22 // Sends a Mach port to |dest_port|. Assumes that |dest_port| is a send once 23 // right. Takes ownership of |dest_port|. 24 BASE_EXPORT kern_return_t SendMachPort(mach_port_t dest_port, 25 mach_port_t port_to_send, 26 int disposition); 27 28 // Receives a Mach port from |port_to_listen_on|, which should have exactly one 29 // queued message. Returns |MACH_PORT_NULL| on any error. 30 BASE_EXPORT base::mac::ScopedMachSendRight ReceiveMachPort( 31 mach_port_t port_to_listen_on); 32 33 // Creates an intermediate Mach port in |task_port| and sends |port_to_insert| 34 // as a mach_msg to the intermediate Mach port. 35 // |task_port| is the task port of another process. 36 // |port_to_insert| must be a send right in the current task's name space. 37 // Returns the intermediate port on success, and MACH_PORT_NULL on failure. 38 // On failure, |error_code| is set if not null. 39 // This method takes ownership of |port_to_insert|. On success, ownership is 40 // passed to the intermediate Mach port. 41 BASE_EXPORT mach_port_name_t CreateIntermediateMachPort( 42 mach_port_t task_port, 43 base::mac::ScopedMachSendRight port_to_insert, 44 MachCreateError* error_code); 45 46 } // namespace base 47 48 #endif // BASE_MAC_MACH_PORT_UTIL_H_ 49