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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 EXPECT_TRUE(rv); | 507 EXPECT_TRUE(rv); |
508 | 508 |
509 void* old_address = memory.memory(); | 509 void* old_address = memory.memory(); |
510 | 510 |
511 rv = memory.Map(kDataSize); | 511 rv = memory.Map(kDataSize); |
512 EXPECT_FALSE(rv); | 512 EXPECT_FALSE(rv); |
513 EXPECT_EQ(old_address, memory.memory()); | 513 EXPECT_EQ(old_address, memory.memory()); |
514 } | 514 } |
515 | 515 |
516 #if defined(OS_POSIX) | 516 #if defined(OS_POSIX) |
517 #if !defined(OS_IOS) | |
Nico
2014/07/31 20:11:12
Add a comment that explains why this is disabled o
lliabraa
2014/07/31 20:26:13
Done.
| |
517 // Create a shared memory object, mmap it, and mprotect it to PROT_EXEC. | 518 // Create a shared memory object, mmap it, and mprotect it to PROT_EXEC. |
518 TEST(SharedMemoryTest, AnonymousExecutable) { | 519 TEST(SharedMemoryTest, AnonymousExecutable) { |
519 const uint32 kTestSize = 1 << 16; | 520 const uint32 kTestSize = 1 << 16; |
520 | 521 |
521 SharedMemory shared_memory; | 522 SharedMemory shared_memory; |
522 SharedMemoryCreateOptions options; | 523 SharedMemoryCreateOptions options; |
523 options.size = kTestSize; | 524 options.size = kTestSize; |
524 options.executable = true; | 525 options.executable = true; |
525 | 526 |
526 EXPECT_TRUE(shared_memory.Create(options)); | 527 EXPECT_TRUE(shared_memory.Create(options)); |
527 EXPECT_TRUE(shared_memory.Map(shared_memory.requested_size())); | 528 EXPECT_TRUE(shared_memory.Map(shared_memory.requested_size())); |
528 | 529 |
529 EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.requested_size(), | 530 EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.requested_size(), |
530 PROT_READ | PROT_EXEC)); | 531 PROT_READ | PROT_EXEC)); |
531 } | 532 } |
533 #endif // !defined(OS_IOS) | |
532 | 534 |
533 // Android supports a different permission model than POSIX for its "ashmem" | 535 // Android supports a different permission model than POSIX for its "ashmem" |
534 // shared memory implementation. So the tests about file permissions are not | 536 // shared memory implementation. So the tests about file permissions are not |
535 // included on Android. | 537 // included on Android. |
536 #if !defined(OS_ANDROID) | 538 #if !defined(OS_ANDROID) |
537 | 539 |
538 // Set a umask and restore the old mask on destruction. | 540 // Set a umask and restore the old mask on destruction. |
539 class ScopedUmaskSetter { | 541 class ScopedUmaskSetter { |
540 public: | 542 public: |
541 explicit ScopedUmaskSetter(mode_t target_mask) { | 543 explicit ScopedUmaskSetter(mode_t target_mask) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 SharedMemoryProcessTest::CleanUp(); | 679 SharedMemoryProcessTest::CleanUp(); |
678 } | 680 } |
679 | 681 |
680 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { | 682 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { |
681 return SharedMemoryProcessTest::TaskTestMain(); | 683 return SharedMemoryProcessTest::TaskTestMain(); |
682 } | 684 } |
683 | 685 |
684 #endif // !OS_IOS | 686 #endif // !OS_IOS |
685 | 687 |
686 } // namespace base | 688 } // namespace base |
OLD | NEW |