summaryrefslogtreecommitdiffstats
path: root/ipc/test_util_mac.h
blob: 2f5e819dd450db2a12c18fca76fe137f60010898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file contains Mac-specific utility functions used by multiple test
// suites.

#ifndef IPC_TEST_UTIL_MAC_H_
#define IPC_TEST_UTIL_MAC_H_

#include <mach/mach.h>
#include <stddef.h>

#include <string>

#include "base/mac/scoped_mach_port.h"

namespace IPC {

// Returns a random name suitable for Mach Server registration.
std::string CreateRandomServiceName();

// Makes the current process into a Mach Server with the given |service_name|.
// Returns a receive right for the service port.
base::mac::ScopedMachReceiveRight BecomeMachServer(const char* service_name);

// Returns a send right to the service port for the Mach Server with the given
// |service_name|.
base::mac::ScopedMachSendRight LookupServer(const char* service_name);

// Returns the receive right to a newly minted Mach port.
base::mac::ScopedMachReceiveRight MakeReceivingPort();

// Blocks until a Mach message is sent to |port_to_listen_on|. This Mach message
// must contain a Mach port. Returns that Mach port.
base::mac::ScopedMachSendRight ReceiveMachPort(mach_port_t port_to_listen_on);

// Passes a copy of the send right of |port_to_send| to |receiving_port|, using
// the given |disposition|.
void SendMachPort(mach_port_t receiving_port,
                  mach_port_t port_to_send,
                  int disposition);

// The number of active names in the current task's port name space.
mach_msg_type_number_t GetActiveNameCount();

// The number of references the current task has for a given name.
mach_port_urefs_t GetMachRefCount(mach_port_name_t name,
                                  mach_port_right_t right);

// Increments the ref count for the right/name pair.
void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right);

// Gets the current and maximum protection levels of the memory region.
// Returns whether the operation was successful.
// |current| and |max| are output variables only populated on success.
bool GetMachProtections(void* address, size_t size, int* current, int* max);

}  // namespace IPC

#endif  // IPC_TEST_UTIL_MAC_H_