OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ipc/attachment_broker_privileged_mac.h" | 5 #include "ipc/attachment_broker_privileged_mac.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <mach/mach_vm.h> | 8 #include <mach/mach_vm.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
16 #include "base/mac/mach_logging.h" | 16 #include "base/mac/mach_logging.h" |
| 17 #include "base/mac/mach_port_util.h" |
17 #include "base/mac/scoped_mach_port.h" | 18 #include "base/mac/scoped_mach_port.h" |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/memory/shared_memory.h" | 20 #include "base/memory/shared_memory.h" |
20 #include "base/process/port_provider_mac.h" | 21 #include "base/process/port_provider_mac.h" |
21 #include "base/process/process_handle.h" | 22 #include "base/process/process_handle.h" |
22 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
23 #include "base/test/multiprocess_test.h" | 24 #include "base/test/multiprocess_test.h" |
24 #include "base/test/test_timeouts.h" | 25 #include "base/test/test_timeouts.h" |
25 #include "ipc/test_util_mac.h" | 26 #include "ipc/test_util_mac.h" |
26 #include "testing/multiprocess_func_list.h" | 27 #include "testing/multiprocess_func_list.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 192 |
192 // Create some shared memory. | 193 // Create some shared memory. |
193 scoped_ptr<base::SharedMemory> shared_memory = | 194 scoped_ptr<base::SharedMemory> shared_memory = |
194 CreateAndPopulateSharedMemoryHandle(s_memory_size); | 195 CreateAndPopulateSharedMemoryHandle(s_memory_size); |
195 ASSERT_TRUE(shared_memory->handle().IsValid()); | 196 ASSERT_TRUE(shared_memory->handle().IsValid()); |
196 | 197 |
197 // Insert the memory object into the destination task, via an intermediate | 198 // Insert the memory object into the destination task, via an intermediate |
198 // port. | 199 // port. |
199 IncrementMachRefCount(shared_memory->handle().GetMemoryObject(), | 200 IncrementMachRefCount(shared_memory->handle().GetMemoryObject(), |
200 MACH_PORT_RIGHT_SEND); | 201 MACH_PORT_RIGHT_SEND); |
201 mach_port_name_t inserted_memory_object = broker.CreateIntermediateMachPort( | 202 mach_port_name_t inserted_memory_object = base::CreateIntermediateMachPort( |
202 client_task_port_.get(), base::mac::ScopedMachSendRight( | 203 client_task_port_.get(), |
203 shared_memory->handle().GetMemoryObject())); | 204 base::mac::ScopedMachSendRight(shared_memory->handle().GetMemoryObject()), |
| 205 nullptr); |
204 EXPECT_NE(inserted_memory_object, | 206 EXPECT_NE(inserted_memory_object, |
205 static_cast<mach_port_name_t>(MACH_PORT_NULL)); | 207 static_cast<mach_port_name_t>(MACH_PORT_NULL)); |
206 SendUInt32(client_port_.get(), inserted_memory_object); | 208 SendUInt32(client_port_.get(), inserted_memory_object); |
207 | 209 |
208 // Check that no names have been leaked. | 210 // Check that no names have been leaked. |
209 shared_memory.reset(); | 211 shared_memory.reset(); |
210 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 212 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
211 | 213 |
212 int rv = -1; | 214 int rv = -1; |
213 ASSERT_TRUE(child_process_.WaitForExitWithTimeout( | 215 ASSERT_TRUE(child_process_.WaitForExitWithTimeout( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // Create some shared memory. | 261 // Create some shared memory. |
260 scoped_ptr<base::SharedMemory> shared_memory = | 262 scoped_ptr<base::SharedMemory> shared_memory = |
261 CreateAndPopulateSharedMemoryHandle(s_memory_size); | 263 CreateAndPopulateSharedMemoryHandle(s_memory_size); |
262 ASSERT_TRUE(shared_memory->handle().IsValid()); | 264 ASSERT_TRUE(shared_memory->handle().IsValid()); |
263 | 265 |
264 // Insert the memory object into the destination task, via an intermediate | 266 // Insert the memory object into the destination task, via an intermediate |
265 // port, twice. | 267 // port, twice. |
266 for (int i = 0; i < 2; ++i) { | 268 for (int i = 0; i < 2; ++i) { |
267 IncrementMachRefCount(shared_memory->handle().GetMemoryObject(), | 269 IncrementMachRefCount(shared_memory->handle().GetMemoryObject(), |
268 MACH_PORT_RIGHT_SEND); | 270 MACH_PORT_RIGHT_SEND); |
269 mach_port_name_t inserted_memory_object = broker.CreateIntermediateMachPort( | 271 mach_port_name_t inserted_memory_object = base::CreateIntermediateMachPort( |
270 client_task_port_.get(), | 272 client_task_port_.get(), |
271 base::mac::ScopedMachSendRight( | 273 base::mac::ScopedMachSendRight( |
272 shared_memory->handle().GetMemoryObject())); | 274 shared_memory->handle().GetMemoryObject()), |
| 275 nullptr); |
273 EXPECT_NE(inserted_memory_object, | 276 EXPECT_NE(inserted_memory_object, |
274 static_cast<mach_port_name_t>(MACH_PORT_NULL)); | 277 static_cast<mach_port_name_t>(MACH_PORT_NULL)); |
275 SendUInt32(client_port_.get(), inserted_memory_object); | 278 SendUInt32(client_port_.get(), inserted_memory_object); |
276 } | 279 } |
277 | 280 |
278 // Check that no names have been leaked. | 281 // Check that no names have been leaked. |
279 shared_memory.reset(); | 282 shared_memory.reset(); |
280 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 283 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
281 | 284 |
282 int rv = -1; | 285 int rv = -1; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 for (int i = 0; i < 2; ++i) { | 358 for (int i = 0; i < 2; ++i) { |
356 // Create some shared memory. | 359 // Create some shared memory. |
357 scoped_ptr<base::SharedMemory> shared_memory = | 360 scoped_ptr<base::SharedMemory> shared_memory = |
358 CreateAndPopulateSharedMemoryHandle(s_memory_size); | 361 CreateAndPopulateSharedMemoryHandle(s_memory_size); |
359 ASSERT_TRUE(shared_memory->handle().IsValid()); | 362 ASSERT_TRUE(shared_memory->handle().IsValid()); |
360 | 363 |
361 // Insert the memory object into the destination task, via an intermediate | 364 // Insert the memory object into the destination task, via an intermediate |
362 // port. | 365 // port. |
363 IncrementMachRefCount(shared_memory->handle().GetMemoryObject(), | 366 IncrementMachRefCount(shared_memory->handle().GetMemoryObject(), |
364 MACH_PORT_RIGHT_SEND); | 367 MACH_PORT_RIGHT_SEND); |
365 mach_port_name_t inserted_memory_object = broker.CreateIntermediateMachPort( | 368 mach_port_name_t inserted_memory_object = base::CreateIntermediateMachPort( |
366 client_task_port_.get(), | 369 client_task_port_.get(), |
367 base::mac::ScopedMachSendRight( | 370 base::mac::ScopedMachSendRight( |
368 shared_memory->handle().GetMemoryObject())); | 371 shared_memory->handle().GetMemoryObject()), |
| 372 nullptr); |
369 EXPECT_NE(inserted_memory_object, | 373 EXPECT_NE(inserted_memory_object, |
370 static_cast<mach_port_name_t>(MACH_PORT_NULL)); | 374 static_cast<mach_port_name_t>(MACH_PORT_NULL)); |
371 SendUInt32(client_port_.get(), inserted_memory_object); | 375 SendUInt32(client_port_.get(), inserted_memory_object); |
372 } | 376 } |
373 | 377 |
374 // Check that no names have been leaked. | 378 // Check that no names have been leaked. |
375 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 379 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
376 | 380 |
377 int rv = -1; | 381 int rv = -1; |
378 ASSERT_TRUE(child_process_.WaitForExitWithTimeout( | 382 ASSERT_TRUE(child_process_.WaitForExitWithTimeout( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 // After releasing one shared memory region, the name count should decrement. | 430 // After releasing one shared memory region, the name count should decrement. |
427 shared_memory.reset(); | 431 shared_memory.reset(); |
428 EXPECT_EQ(original_name_count + 1, GetActiveNameCount()); | 432 EXPECT_EQ(original_name_count + 1, GetActiveNameCount()); |
429 shared_memory2.reset(); | 433 shared_memory2.reset(); |
430 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 434 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
431 | 435 |
432 return 0; | 436 return 0; |
433 } | 437 } |
434 | 438 |
435 } // namespace IPC | 439 } // namespace IPC |
OLD | NEW |