Avi Drissman | ea1be23 | 2022-09-14 23:29:06 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ipc/mach_port_attachment_mac.h" |
| 6 | |
avi | 246998d | 2015-12-22 02:39:04 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Avi Drissman | 0b20071 | 2023-08-16 20:35:49 | [diff] [blame] | 9 | #include "base/apple/mach_logging.h" |
erikchen | 3722a32 | 2015-10-07 20:51:55 | [diff] [blame] | 10 | |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 11 | namespace IPC { |
| 12 | namespace internal { |
| 13 | |
| 14 | MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port) |
erikchen | 3722a32 | 2015-10-07 20:51:55 | [diff] [blame] | 15 | : mach_port_(mach_port), owns_mach_port_(true) { |
| 16 | if (mach_port != MACH_PORT_NULL) { |
| 17 | kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port, |
| 18 | MACH_PORT_RIGHT_SEND, 1); |
| 19 | MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 20 | << "MachPortAttachmentMac mach_port_mod_refs"; |
| 21 | } |
| 22 | } |
sammc | 57ed9f98 | 2016-03-10 06:28:35 | [diff] [blame] | 23 | MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port, |
| 24 | FromWire from_wire) |
| 25 | : mach_port_(mach_port), owns_mach_port_(true) {} |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 26 | |
erikchen | 3722a32 | 2015-10-07 20:51:55 | [diff] [blame] | 27 | MachPortAttachmentMac::~MachPortAttachmentMac() { |
| 28 | if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) { |
| 29 | kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_, |
| 30 | MACH_PORT_RIGHT_SEND, -1); |
| 31 | MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 32 | << "~MachPortAttachmentMac mach_port_mod_refs"; |
| 33 | } |
| 34 | } |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 35 | |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 36 | MessageAttachment::Type MachPortAttachmentMac::GetType() const { |
| 37 | return Type::MACH_PORT; |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | } // namespace internal |
| 41 | } // namespace IPC |