| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mojo/edk/system/channel.h" | 5 #include "mojo/edk/system/channel.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/uio.h> | 8 #include <sys/uio.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 ScopedPlatformHandleVectorPtr GetReadPlatformHandles( | 135 ScopedPlatformHandleVectorPtr GetReadPlatformHandles( |
| 136 size_t num_handles, | 136 size_t num_handles, |
| 137 const void* extra_header, | 137 const void* extra_header, |
| 138 size_t extra_header_size) override { | 138 size_t extra_header_size) override { |
| 139 #if defined(OS_MACOSX) && !defined(OS_IOS) | 139 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 140 // On OSX, we can have mach ports which are located in the extra header | 140 // On OSX, we can have mach ports which are located in the extra header |
| 141 // section. | 141 // section. |
| 142 using MachPortsEntry = Channel::Message::MachPortsEntry; | 142 using MachPortsEntry = Channel::Message::MachPortsEntry; |
| 143 CHECK(extra_header_size >= num_handles * sizeof(MachPortsEntry)); | 143 using MachPortsExtraHeader = Channel::Message::MachPortsExtraHeader; |
| 144 size_t num_mach_ports = 0; | 144 CHECK(extra_header_size >= |
| 145 const MachPortsEntry* mach_ports = | 145 sizeof(MachPortsExtraHeader) + num_handles * sizeof(MachPortsEntry)); |
| 146 reinterpret_cast<const MachPortsEntry*>(extra_header); | 146 const MachPortsExtraHeader* mach_ports_header = |
| 147 for (size_t i = 0; i < num_handles; i++) { | 147 reinterpret_cast<const MachPortsExtraHeader*>(extra_header); |
| 148 if (mach_ports[i].mach_port != MACH_PORT_NULL) | 148 size_t num_mach_ports = mach_ports_header->num_ports; |
| 149 num_mach_ports++; | |
| 150 } | |
| 151 CHECK(num_mach_ports <= num_handles); | 149 CHECK(num_mach_ports <= num_handles); |
| 152 if (incoming_platform_handles_.size() + num_mach_ports < num_handles) | 150 if (incoming_platform_handles_.size() + num_mach_ports < num_handles) |
| 153 return nullptr; | 151 return nullptr; |
| 154 | 152 |
| 155 ScopedPlatformHandleVectorPtr handles( | 153 ScopedPlatformHandleVectorPtr handles( |
| 156 new PlatformHandleVector(num_handles)); | 154 new PlatformHandleVector(num_handles)); |
| 155 const MachPortsEntry* mach_ports = mach_ports_header->entries; |
| 157 for (size_t i = 0, mach_port_index = 0; i < num_handles; ++i) { | 156 for (size_t i = 0, mach_port_index = 0; i < num_handles; ++i) { |
| 158 if (mach_port_index < num_mach_ports && | 157 if (mach_port_index < num_mach_ports && |
| 159 mach_ports[mach_port_index].index == i) { | 158 mach_ports[mach_port_index].index == i) { |
| 160 (*handles)[i] = PlatformHandle( | 159 (*handles)[i] = PlatformHandle( |
| 161 static_cast<mach_port_t>(mach_ports[mach_port_index].mach_port)); | 160 static_cast<mach_port_t>(mach_ports[mach_port_index].mach_port)); |
| 162 CHECK((*handles)[i].type == PlatformHandle::Type::MACH); | 161 CHECK((*handles)[i].type == PlatformHandle::Type::MACH); |
| 163 // These are actually just Mach port names until they're resolved from | 162 // These are actually just Mach port names until they're resolved from |
| 164 // the remote process. | 163 // the remote process. |
| 165 (*handles)[i].type = PlatformHandle::Type::MACH_NAME; | 164 (*handles)[i].type = PlatformHandle::Type::MACH_NAME; |
| 166 mach_port_index++; | 165 mach_port_index++; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // static | 485 // static |
| 487 scoped_refptr<Channel> Channel::Create( | 486 scoped_refptr<Channel> Channel::Create( |
| 488 Delegate* delegate, | 487 Delegate* delegate, |
| 489 ScopedPlatformHandle platform_handle, | 488 ScopedPlatformHandle platform_handle, |
| 490 scoped_refptr<base::TaskRunner> io_task_runner) { | 489 scoped_refptr<base::TaskRunner> io_task_runner) { |
| 491 return new ChannelPosix(delegate, std::move(platform_handle), io_task_runner); | 490 return new ChannelPosix(delegate, std::move(platform_handle), io_task_runner); |
| 492 } | 491 } |
| 493 | 492 |
| 494 } // namespace edk | 493 } // namespace edk |
| 495 } // namespace mojo | 494 } // namespace mojo |
| OLD | NEW |