Chromium Code Reviews| 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 #else | 446 #else |
| 447 #error Unexpected platform; write a test that tries to make 'handle' writable. | 447 #error Unexpected platform; write a test that tries to make 'handle' writable. |
| 448 #endif // defined(OS_POSIX) || defined(OS_WIN) | 448 #endif // defined(OS_POSIX) || defined(OS_WIN) |
| 449 } | 449 } |
|
rvargas (doing something else)
2014/08/07 18:24:02
could we add a call to duplicate the handle with r
jschuh
2014/08/07 18:35:47
Not if it has the same bug. :P
I mean, certainly.
| |
| 450 | 450 |
| 451 TEST(SharedMemoryTest, ShareToSelf) { | 451 TEST(SharedMemoryTest, ShareToSelf) { |
| 452 StringPiece contents = "Hello World"; | 452 StringPiece contents = "Hello World"; |
| 453 | 453 |
| 454 SharedMemory shmem; | 454 SharedMemory shmem; |
| 455 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); | 455 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); |
| 456 memcpy(shmem.memory(), contents.data(), contents.size()); | 456 memcpy(shmem.memory(), contents.data(), contents.size()); |
| 457 EXPECT_TRUE(shmem.Unmap()); | 457 EXPECT_TRUE(shmem.Unmap()); |
| 458 | 458 |
| 459 SharedMemoryHandle shared_handle; | 459 SharedMemoryHandle shared_handle; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 SharedMemoryProcessTest::CleanUp(); | 677 SharedMemoryProcessTest::CleanUp(); |
| 678 } | 678 } |
| 679 | 679 |
| 680 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 680 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
| 681 return SharedMemoryProcessTest::TaskTestMain(); | 681 return SharedMemoryProcessTest::TaskTestMain(); |
| 682 } | 682 } |
| 683 | 683 |
| 684 #endif // !OS_IOS | 684 #endif // !OS_IOS |
| 685 | 685 |
| 686 } // namespace base | 686 } // namespace base |
| OLD | NEW |