Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1175)

Side by Side Diff: base/shared_memory_unittest.cc

Issue 8585002: Give base::SharedMemory::CreateAnonymous an executable flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/shared_memory.h" 7 #include "base/shared_memory.h"
8 #include "base/test/multiprocess_test.h" 8 #include "base/test/multiprocess_test.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/multiprocess_func_list.h" 12 #include "testing/multiprocess_func_list.h"
13 13
14 #if defined(OS_MACOSX) 14 #if defined(OS_MACOSX)
15 #include "base/mac/scoped_nsautorelease_pool.h" 15 #include "base/mac/scoped_nsautorelease_pool.h"
16 #endif 16 #endif
17 17
18 #if defined(OS_POSIX)
19 #include <sys/mman.h>
20 #endif
21
18 static const int kNumThreads = 5; 22 static const int kNumThreads = 5;
19 static const int kNumTasks = 5; 23 static const int kNumTasks = 5;
20 24
21 namespace base { 25 namespace base {
22 26
23 namespace { 27 namespace {
24 28
25 // Each thread will open the shared memory. Each thread will take a different 4 29 // Each thread will open the shared memory. Each thread will take a different 4
26 // byte int pointer, and keep changing it, with some small pauses in between. 30 // byte int pointer, and keep changing it, with some small pauses in between.
27 // Verify that each thread's value in the shared memory is always correct. 31 // Verify that each thread's value in the shared memory is always correct.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 else 329 else
326 EXPECT_EQ(0, pointers[j][0]); 330 EXPECT_EQ(0, pointers[j][0]);
327 } 331 }
328 } 332 }
329 333
330 for (int i = 0; i < count; i++) { 334 for (int i = 0; i < count; i++) {
331 memories[i].Close(); 335 memories[i].Close();
332 } 336 }
333 } 337 }
334 338
339 #if defined(OS_POSIX)
340 // Create a shared memory object, mmap it, and mprotect it to PROT_EXEC.
341 TEST(SharedMemoryTest, AnonymousExecutable) {
342 const uint32 kTestSize = 1 << 16;
343
344 SharedMemory shared_memory;
345 SharedMemoryCreateOptions options;
346 options.size = kTestSize;
347 options.executable = true;
348
349 EXPECT_TRUE(shared_memory.Create(options));
350 EXPECT_TRUE(shared_memory.Map(shared_memory.created_size()));
351
352 EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.created_size(),
353 PROT_READ | PROT_EXEC));
354 }
355 #endif
356
335 // On POSIX it is especially important we test shmem across processes, 357 // On POSIX it is especially important we test shmem across processes,
336 // not just across threads. But the test is enabled on all platforms. 358 // not just across threads. But the test is enabled on all platforms.
337 class SharedMemoryProcessTest : public MultiProcessTest { 359 class SharedMemoryProcessTest : public MultiProcessTest {
338 public: 360 public:
339 361
340 static void CleanUp() { 362 static void CleanUp() {
341 SharedMemory memory; 363 SharedMemory memory;
342 memory.Delete(s_test_name_); 364 memory.Delete(s_test_name_);
343 } 365 }
344 366
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 424 }
403 425
404 SharedMemoryProcessTest::CleanUp(); 426 SharedMemoryProcessTest::CleanUp();
405 } 427 }
406 428
407 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 429 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
408 return SharedMemoryProcessTest::TaskTestMain(); 430 return SharedMemoryProcessTest::TaskTestMain();
409 } 431 }
410 432
411 } // namespace base 433 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698