erikchen | 89d7423 | 2015-10-12 18:24:01 | [diff] [blame] | 1 | // Copyright 2015 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 | |
erikchen | b82097cc | 2015-10-12 23:27:55 | [diff] [blame] | 5 | // This file contains Mac-specific utility functions used by multiple test |
| 6 | // suites. |
erikchen | 89d7423 | 2015-10-12 18:24:01 | [diff] [blame] | 7 | |
| 8 | #ifndef IPC_TEST_UTIL_MAC_H_ |
| 9 | #define IPC_TEST_UTIL_MAC_H_ |
| 10 | |
| 11 | #include <mach/mach.h> |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 12 | #include <stddef.h> |
erikchen | 89d7423 | 2015-10-12 18:24:01 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
| 16 | #include "base/mac/scoped_mach_port.h" |
| 17 | |
| 18 | namespace IPC { |
| 19 | |
| 20 | // Returns a random name suitable for Mach Server registration. |
| 21 | std::string CreateRandomServiceName(); |
| 22 | |
| 23 | // Makes the current process into a Mach Server with the given |service_name|. |
| 24 | // Returns a receive right for the service port. |
| 25 | base::mac::ScopedMachReceiveRight BecomeMachServer(const char* service_name); |
| 26 | |
| 27 | // Returns a send right to the service port for the Mach Server with the given |
| 28 | // |service_name|. |
| 29 | base::mac::ScopedMachSendRight LookupServer(const char* service_name); |
| 30 | |
| 31 | // Returns the receive right to a newly minted Mach port. |
| 32 | base::mac::ScopedMachReceiveRight MakeReceivingPort(); |
| 33 | |
| 34 | // Blocks until a Mach message is sent to |port_to_listen_on|. This Mach message |
| 35 | // must contain a Mach port. Returns that Mach port. |
| 36 | base::mac::ScopedMachSendRight ReceiveMachPort(mach_port_t port_to_listen_on); |
| 37 | |
| 38 | // Passes a copy of the send right of |port_to_send| to |receiving_port|, using |
| 39 | // the given |disposition|. |
| 40 | void SendMachPort(mach_port_t receiving_port, |
| 41 | mach_port_t port_to_send, |
| 42 | int disposition); |
| 43 | |
| 44 | // The number of active names in the current task's port name space. |
| 45 | mach_msg_type_number_t GetActiveNameCount(); |
| 46 | |
erikchen | b82097cc | 2015-10-12 23:27:55 | [diff] [blame] | 47 | // The number of references the current task has for a given name. |
| 48 | mach_port_urefs_t GetMachRefCount(mach_port_name_t name, |
| 49 | mach_port_right_t right); |
| 50 | |
erikchen | 89d7423 | 2015-10-12 18:24:01 | [diff] [blame] | 51 | // Increments the ref count for the right/name pair. |
| 52 | void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right); |
| 53 | |
erikchen | 328bf3f | 2015-10-24 00:46:54 | [diff] [blame] | 54 | // Gets the current and maximum protection levels of the memory region. |
| 55 | // Returns whether the operation was successful. |
| 56 | // |current| and |max| are output variables only populated on success. |
| 57 | bool GetMachProtections(void* address, size_t size, int* current, int* max); |
| 58 | |
erikchen | 89d7423 | 2015-10-12 18:24:01 | [diff] [blame] | 59 | } // namespace IPC |
| 60 | |
| 61 | #endif // IPC_TEST_UTIL_MAC_H_ |