OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mach_ipc_mac.h" | 5 #include "base/mach_ipc_mac.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <mach/vm_map.h> |
8 | 9 |
9 #include <stdio.h> | 10 #include <stdio.h> |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 | 14 |
14 // static | 15 // static |
15 const size_t MachMessage::kEmptyMessageSize = sizeof(mach_msg_header_t) + | 16 const size_t MachMessage::kEmptyMessageSize = sizeof(mach_msg_header_t) + |
16 sizeof(mach_msg_body_t) + sizeof(MessageDataPacket); | 17 sizeof(mach_msg_body_t) + sizeof(MessageDataPacket); |
17 | 18 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 MACH_SEND_MSG | MACH_SEND_TIMEOUT, | 316 MACH_SEND_MSG | MACH_SEND_TIMEOUT, |
316 message.Head()->msgh_size, | 317 message.Head()->msgh_size, |
317 0, | 318 0, |
318 MACH_PORT_NULL, | 319 MACH_PORT_NULL, |
319 timeout, // timeout in ms | 320 timeout, // timeout in ms |
320 MACH_PORT_NULL); | 321 MACH_PORT_NULL); |
321 | 322 |
322 return result; | 323 return result; |
323 } | 324 } |
324 | 325 |
| 326 //============================================================================== |
| 327 |
| 328 namespace mac { |
| 329 |
| 330 kern_return_t GetNumberOfMachPorts(mach_port_t task_port, int* num_ports) { |
| 331 mach_port_name_array_t names; |
| 332 mach_msg_type_number_t names_count; |
| 333 mach_port_type_array_t types; |
| 334 mach_msg_type_number_t types_count; |
| 335 |
| 336 // A friendlier interface would allow NULL buffers to only get the counts. |
| 337 kern_return_t kr = mach_port_names(task_port, &names, &names_count, |
| 338 &types, &types_count); |
| 339 if (kr != KERN_SUCCESS) |
| 340 return kr; |
| 341 |
| 342 // The documentation states this is an invariant. |
| 343 DCHECK_EQ(names_count, types_count); |
| 344 *num_ports = names_count; |
| 345 |
| 346 kr = vm_deallocate(mach_task_self(), |
| 347 reinterpret_cast<vm_address_t>(names), |
| 348 names_count * sizeof(mach_port_name_array_t)); |
| 349 kr = vm_deallocate(mach_task_self(), |
| 350 reinterpret_cast<vm_address_t>(types), |
| 351 types_count * sizeof(mach_port_type_array_t)); |
| 352 |
| 353 return kr; |
| 354 } |
| 355 |
| 356 } // namespace mac |
| 357 |
325 } // namespace base | 358 } // namespace base |
OLD | NEW |