summaryrefslogtreecommitdiffstats
path: root/base/shared_memory_unittest.cc
diff options
context:
space:
mode:
authormcgrathr@chromium.org <mcgrathr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-01 23:19:31 +0000
committermcgrathr@chromium.org <mcgrathr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-01 23:19:31 +0000
commitb05df6b03e0d5dc552a96578ea6a8a7e47af407c (patch)
tree34a9231715fe019e140160b4046e50d76b6357e2 /base/shared_memory_unittest.cc
parenta84c55dab98485bb27156a7e99e464ceb9e7f311 (diff)
downloadchromium_src-b05df6b03e0d5dc552a96578ea6a8a7e47af407c.zip
chromium_src-b05df6b03e0d5dc552a96578ea6a8a7e47af407c.tar.gz
chromium_src-b05df6b03e0d5dc552a96578ea6a8a7e47af407c.tar.bz2
Give base::SharedMemory::CreateAnonymous an executable flag
NaCl on Mac and Linux needs to create a shared memory object that it can later make executable with mprotect. Express this need in the interface it uses. Add a test that pages mapped from such an object can later be passed to mprotect with PROT_EXEC. This lays the groundwork for a later change that will sometimes use a different method to allocate an object on Linux when it needs to be executable. On some Linux distributions, shm_open yields objects whose mappings cannot be made executable. BUG= http://code.google.com/p/chromium/issues/detail?id=103377 TEST= SharedMemory.AnonymousExecutable R=mark@chromium.org,jam@chromium.org,amit@chromium.org,ben@chromium.org Review URL: http://codereview.chromium.org/8585002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112570 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory_unittest.cc')
-rw-r--r--base/shared_memory_unittest.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/base/shared_memory_unittest.cc b/base/shared_memory_unittest.cc
index 9f69a5d..41b8ba5 100644
--- a/base/shared_memory_unittest.cc
+++ b/base/shared_memory_unittest.cc
@@ -15,6 +15,10 @@
#include "base/mac/scoped_nsautorelease_pool.h"
#endif
+#if defined(OS_POSIX)
+#include <sys/mman.h>
+#endif
+
static const int kNumThreads = 5;
static const int kNumTasks = 5;
@@ -332,6 +336,24 @@ TEST(SharedMemoryTest, AnonymousPrivate) {
}
}
+#if defined(OS_POSIX)
+// Create a shared memory object, mmap it, and mprotect it to PROT_EXEC.
+TEST(SharedMemoryTest, AnonymousExecutable) {
+ const uint32 kTestSize = 1 << 16;
+
+ SharedMemory shared_memory;
+ SharedMemoryCreateOptions options;
+ options.size = kTestSize;
+ options.executable = true;
+
+ EXPECT_TRUE(shared_memory.Create(options));
+ EXPECT_TRUE(shared_memory.Map(shared_memory.created_size()));
+
+ EXPECT_EQ(0, mprotect(shared_memory.memory(), shared_memory.created_size(),
+ PROT_READ | PROT_EXEC));
+}
+#endif
+
// On POSIX it is especially important we test shmem across processes,
// not just across threads. But the test is enabled on all platforms.
class SharedMemoryProcessTest : public MultiProcessTest {