OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 PAGE_READONLY | SEC_IMAGE, 0, 0, kTestSectionName)); | 598 PAGE_READONLY | SEC_IMAGE, 0, 0, kTestSectionName)); |
599 EXPECT_TRUE(section_handle.IsValid()); | 599 EXPECT_TRUE(section_handle.IsValid()); |
600 | 600 |
601 // Check direct opening by name, from handle and duplicated from handle. | 601 // Check direct opening by name, from handle and duplicated from handle. |
602 SharedMemory shared_memory_open; | 602 SharedMemory shared_memory_open; |
603 EXPECT_TRUE(shared_memory_open.Open(kTestSectionName, true)); | 603 EXPECT_TRUE(shared_memory_open.Open(kTestSectionName, true)); |
604 EXPECT_FALSE(shared_memory_open.Map(1)); | 604 EXPECT_FALSE(shared_memory_open.Map(1)); |
605 EXPECT_EQ(nullptr, shared_memory_open.memory()); | 605 EXPECT_EQ(nullptr, shared_memory_open.memory()); |
606 | 606 |
607 SharedMemory shared_memory_handle_local( | 607 SharedMemory shared_memory_handle_local( |
608 SharedMemoryHandle(section_handle.Take(), ::GetCurrentProcessId()), true); | 608 SharedMemoryHandle(section_handle.Take()), true); |
609 EXPECT_FALSE(shared_memory_handle_local.Map(1)); | 609 EXPECT_FALSE(shared_memory_handle_local.Map(1)); |
610 EXPECT_EQ(nullptr, shared_memory_handle_local.memory()); | 610 EXPECT_EQ(nullptr, shared_memory_handle_local.memory()); |
611 | 611 |
612 // Check that a handle without SECTION_QUERY also can't be mapped as it can't | 612 // Check that a handle without SECTION_QUERY also can't be mapped as it can't |
613 // be checked. | 613 // be checked. |
614 SharedMemory shared_memory_handle_dummy; | 614 SharedMemory shared_memory_handle_dummy; |
615 SharedMemoryCreateOptions options; | 615 SharedMemoryCreateOptions options; |
616 options.size = 0x1000; | 616 options.size = 0x1000; |
617 EXPECT_TRUE(shared_memory_handle_dummy.Create(options)); | 617 EXPECT_TRUE(shared_memory_handle_dummy.Create(options)); |
618 HANDLE handle_no_query; | 618 HANDLE handle_no_query; |
619 EXPECT_TRUE(::DuplicateHandle( | 619 EXPECT_TRUE(::DuplicateHandle( |
620 ::GetCurrentProcess(), shared_memory_handle_dummy.handle().GetHandle(), | 620 ::GetCurrentProcess(), shared_memory_handle_dummy.handle().GetHandle(), |
621 ::GetCurrentProcess(), &handle_no_query, FILE_MAP_READ, FALSE, 0)); | 621 ::GetCurrentProcess(), &handle_no_query, FILE_MAP_READ, FALSE, 0)); |
622 SharedMemory shared_memory_handle_no_query( | 622 SharedMemory shared_memory_handle_no_query( |
623 SharedMemoryHandle(handle_no_query, ::GetCurrentProcessId()), true); | 623 SharedMemoryHandle(handle_no_query), true); |
624 EXPECT_FALSE(shared_memory_handle_no_query.Map(1)); | 624 EXPECT_FALSE(shared_memory_handle_no_query.Map(1)); |
625 EXPECT_EQ(nullptr, shared_memory_handle_no_query.memory()); | 625 EXPECT_EQ(nullptr, shared_memory_handle_no_query.memory()); |
626 } | 626 } |
627 #endif // defined(OS_WIN) | 627 #endif // defined(OS_WIN) |
628 | 628 |
629 // iOS does not allow multiple processes. | 629 // iOS does not allow multiple processes. |
630 // Android ashmem does not support named shared memory. | 630 // Android ashmem does not support named shared memory. |
631 // Mac SharedMemory does not support named shared memory. crbug.com/345734 | 631 // Mac SharedMemory does not support named shared memory. crbug.com/345734 |
632 #if !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 632 #if !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
633 // On POSIX it is especially important we test shmem across processes, | 633 // On POSIX it is especially important we test shmem across processes, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 memory.Close(); | 700 memory.Close(); |
701 SharedMemoryProcessTest::CleanUp(); | 701 SharedMemoryProcessTest::CleanUp(); |
702 } | 702 } |
703 | 703 |
704 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 704 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
705 return SharedMemoryProcessTest::TaskTestMain(); | 705 return SharedMemoryProcessTest::TaskTestMain(); |
706 } | 706 } |
707 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 707 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
708 | 708 |
709 } // namespace base | 709 } // namespace base |
OLD | NEW |