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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 EXPECT_EQ(MAP_FAILED, writable) | 418 EXPECT_EQ(MAP_FAILED, writable) |
419 << "It shouldn't be possible to re-mmap the descriptor writable."; | 419 << "It shouldn't be possible to re-mmap the descriptor writable."; |
420 EXPECT_EQ(EACCES, mmap_errno) << strerror(mmap_errno); | 420 EXPECT_EQ(EACCES, mmap_errno) << strerror(mmap_errno); |
421 if (writable != MAP_FAILED) | 421 if (writable != MAP_FAILED) |
422 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); | 422 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); |
423 | 423 |
424 #elif defined(OS_WIN) | 424 #elif defined(OS_WIN) |
425 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) | 425 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) |
426 << "Shouldn't be able to map memory writable."; | 426 << "Shouldn't be able to map memory writable."; |
427 | 427 |
428 base::win::ScopedHandle writable_handle; | 428 HANDLE temp_handle; |
429 EXPECT_EQ(0, | 429 BOOL rv = ::DuplicateHandle(GetCurrentProcess(), |
430 ::DuplicateHandle(GetCurrentProcess(), | |
431 handle, | 430 handle, |
432 GetCurrentProcess, | 431 GetCurrentProcess, |
433 writable_handle.Receive(), | 432 &temp_handle, |
434 FILE_MAP_ALL_ACCESS, | 433 FILE_MAP_ALL_ACCESS, |
435 false, | 434 false, |
436 0)) | 435 0); |
| 436 EXPECT_EQ(FALSE, rv) |
437 << "Shouldn't be able to duplicate the handle into a writable one."; | 437 << "Shouldn't be able to duplicate the handle into a writable one."; |
| 438 if (rv) |
| 439 base::win::ScopedHandle writable_handle(temp_handle); |
438 #else | 440 #else |
439 #error Unexpected platform; write a test that tries to make 'handle' writable. | 441 #error Unexpected platform; write a test that tries to make 'handle' writable. |
440 #endif // defined(OS_POSIX) || defined(OS_WIN) | 442 #endif // defined(OS_POSIX) || defined(OS_WIN) |
441 } | 443 } |
442 | 444 |
443 TEST(SharedMemoryTest, ShareToSelf) { | 445 TEST(SharedMemoryTest, ShareToSelf) { |
444 StringPiece contents = "Hello World"; | 446 StringPiece contents = "Hello World"; |
445 | 447 |
446 SharedMemory shmem; | 448 SharedMemory shmem; |
447 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); | 449 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 SharedMemoryProcessTest::CleanUp(); | 659 SharedMemoryProcessTest::CleanUp(); |
658 } | 660 } |
659 | 661 |
660 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 662 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
661 return SharedMemoryProcessTest::TaskTestMain(); | 663 return SharedMemoryProcessTest::TaskTestMain(); |
662 } | 664 } |
663 | 665 |
664 #endif // !OS_IOS | 666 #endif // !OS_IOS |
665 | 667 |
666 } // namespace base | 668 } // namespace base |
OLD | NEW |