blob: 2f5e819dd450db2a12c18fca76fe137f60010898 [file] [log] [blame]
erikchen89d74232015-10-12 18:24:011// 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
erikchenb82097cc2015-10-12 23:27:555// This file contains Mac-specific utility functions used by multiple test
6// suites.
erikchen89d74232015-10-12 18:24:017
8#ifndef IPC_TEST_UTIL_MAC_H_
9#define IPC_TEST_UTIL_MAC_H_
10
11#include <mach/mach.h>
avi246998d82015-12-22 02:39:0412#include <stddef.h>
erikchen89d74232015-10-12 18:24:0113
14#include <string>
15
16#include "base/mac/scoped_mach_port.h"
17
18namespace IPC {
19
20// Returns a random name suitable for Mach Server registration.
21std::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.
25base::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|.
29base::mac::ScopedMachSendRight LookupServer(const char* service_name);
30
31// Returns the receive right to a newly minted Mach port.
32base::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.
36base::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|.
40void 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.
45mach_msg_type_number_t GetActiveNameCount();
46
erikchenb82097cc2015-10-12 23:27:5547// The number of references the current task has for a given name.
48mach_port_urefs_t GetMachRefCount(mach_port_name_t name,
49 mach_port_right_t right);
50
erikchen89d74232015-10-12 18:24:0151// Increments the ref count for the right/name pair.
52void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right);
53
erikchen328bf3f2015-10-24 00:46:5454// 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.
57bool GetMachProtections(void* address, size_t size, int* current, int* max);
58
erikchen89d74232015-10-12 18:24:0159} // namespace IPC
60
61#endif // IPC_TEST_UTIL_MAC_H_