summaryrefslogtreecommitdiffstats
path: root/base/shared_memory_win.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_win.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_win.cc')
-rw-r--r--base/shared_memory_win.cc20
1 files changed, 8 insertions, 12 deletions
diff --git a/base/shared_memory_win.cc b/base/shared_memory_win.cc
index 3e5ad36..042eb8b 100644
--- a/base/shared_memory_win.cc
+++ b/base/shared_memory_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -74,14 +74,10 @@ bool SharedMemory::CreateAndMapAnonymous(uint32 size) {
return CreateAnonymous(size) && Map(size);
}
-bool SharedMemory::CreateAnonymous(uint32 size) {
- return CreateNamed("", false, size);
-}
-
-bool SharedMemory::CreateNamed(const std::string& name,
- bool open_existing, uint32 size) {
+bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
+ DCHECK(!options.executable);
DCHECK(!mapped_file_);
- if (size == 0)
+ if (options.size == 0)
return false;
// NaCl's memory allocator requires 0mod64K alignment and size for
@@ -89,22 +85,22 @@ bool SharedMemory::CreateNamed(const std::string& name,
// therefore we round the size actually created to the nearest 64K unit.
// To avoid client impact, we continue to retain the size as the
// actual requested size.
- uint32 rounded_size = (size + 0xffff) & ~0xffff;
- name_ = ASCIIToWide(name);
+ uint32 rounded_size = (options.size + 0xffff) & ~0xffff;
+ name_ = ASCIIToWide(options.name == NULL ? "" : *options.name);
mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size),
name_.empty() ? NULL : name_.c_str());
if (!mapped_file_)
return false;
- created_size_ = size;
+ created_size_ = options.size;
// Check if the shared memory pre-exists.
if (GetLastError() == ERROR_ALREADY_EXISTS) {
// If the file already existed, set created_size_ to 0 to show that
// we don't know the size.
created_size_ = 0;
- if (!open_existing) {
+ if (!options.open_existing) {
Close();
return false;
}