| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
| 8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 if (writable != MAP_FAILED) | 427 if (writable != MAP_FAILED) |
| 428 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); | 428 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); |
| 429 | 429 |
| 430 #elif defined(OS_WIN) | 430 #elif defined(OS_WIN) |
| 431 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) | 431 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) |
| 432 << "Shouldn't be able to map memory writable."; | 432 << "Shouldn't be able to map memory writable."; |
| 433 | 433 |
| 434 HANDLE temp_handle; | 434 HANDLE temp_handle; |
| 435 BOOL rv = ::DuplicateHandle(GetCurrentProcess(), | 435 BOOL rv = ::DuplicateHandle(GetCurrentProcess(), |
| 436 handle, | 436 handle, |
| 437 GetCurrentProcess, | 437 GetCurrentProcess(), |
| 438 &temp_handle, | 438 &temp_handle, |
| 439 FILE_MAP_ALL_ACCESS, | 439 FILE_MAP_ALL_ACCESS, |
| 440 false, | 440 false, |
| 441 0); | 441 0); |
| 442 EXPECT_EQ(FALSE, rv) | 442 EXPECT_EQ(FALSE, rv) |
| 443 << "Shouldn't be able to duplicate the handle into a writable one."; | 443 << "Shouldn't be able to duplicate the handle into a writable one."; |
| 444 if (rv) | 444 if (rv) |
| 445 base::win::ScopedHandle writable_handle(temp_handle); | 445 base::win::ScopedHandle writable_handle(temp_handle); |
| 446 rv = ::DuplicateHandle(GetCurrentProcess(), |
| 447 handle, |
| 448 GetCurrentProcess(), |
| 449 &temp_handle, |
| 450 FILE_MAP_READ, |
| 451 false, |
| 452 0); |
| 453 EXPECT_EQ(TRUE, rv) |
| 454 << "Should be able to duplicate the handle into a readable one."; |
| 455 if (rv) |
| 456 base::win::ScopedHandle writable_handle(temp_handle); |
| 446 #else | 457 #else |
| 447 #error Unexpected platform; write a test that tries to make 'handle' writable. | 458 #error Unexpected platform; write a test that tries to make 'handle' writable. |
| 448 #endif // defined(OS_POSIX) || defined(OS_WIN) | 459 #endif // defined(OS_POSIX) || defined(OS_WIN) |
| 449 } | 460 } |
| 450 | 461 |
| 451 TEST(SharedMemoryTest, ShareToSelf) { | 462 TEST(SharedMemoryTest, ShareToSelf) { |
| 452 StringPiece contents = "Hello World"; | 463 StringPiece contents = "Hello World"; |
| 453 | 464 |
| 454 SharedMemory shmem; | 465 SharedMemory shmem; |
| 455 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); | 466 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 SharedMemoryProcessTest::CleanUp(); | 688 SharedMemoryProcessTest::CleanUp(); |
| 678 } | 689 } |
| 679 | 690 |
| 680 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 691 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
| 681 return SharedMemoryProcessTest::TaskTestMain(); | 692 return SharedMemoryProcessTest::TaskTestMain(); |
| 682 } | 693 } |
| 683 | 694 |
| 684 #endif // !OS_IOS | 695 #endif // !OS_IOS |
| 685 | 696 |
| 686 } // namespace base | 697 } // namespace base |
| OLD | NEW |