diff options
author | mcgrathr@chromium.org <mcgrathr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 23:19:31 +0000 |
---|---|---|
committer | mcgrathr@chromium.org <mcgrathr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 23:19:31 +0000 |
commit | b05df6b03e0d5dc552a96578ea6a8a7e47af407c (patch) | |
tree | 34a9231715fe019e140160b4046e50d76b6357e2 /base/shared_memory.h | |
parent | a84c55dab98485bb27156a7e99e464ceb9e7f311 (diff) | |
download | chromium_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.h')
-rw-r--r-- | base/shared_memory.h | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h index c9dfd6e..8cb27ec 100644 --- a/base/shared_memory.h +++ b/base/shared_memory.h @@ -38,6 +38,29 @@ typedef ino_t SharedMemoryId; // needed. #endif +// Options for creating a shared memory object. +struct SharedMemoryCreateOptions { + SharedMemoryCreateOptions() : name(NULL), size(0), open_existing(false), + executable(false) {} + + // If NULL, the object is anonymous. This pointer is owned by the caller + // and must live through the call to Create(). + const std::string* name; + + // Size of the shared memory object to be created. + // When opening an existing object, this has no effect. + uint32 size; + + // If true, and the shared memory already exists, Create() will open the + // existing shared memory and ignore the size parameter. If false, + // shared memory must not exist. This flag is meaningless unless name is + // non-NULL. + bool open_existing; + + // If true, mappings might need to be made executable later. + bool executable; +}; + // Platform abstraction for shared memory. Provides a C++ wrapper // around the OS primitive for a memory mapped file. class BASE_EXPORT SharedMemory { @@ -74,13 +97,21 @@ class BASE_EXPORT SharedMemory { // Closes a shared memory handle. static void CloseHandle(const SharedMemoryHandle& handle); + // Creates a shared memory object as described by the options struct. + // Returns true on success and false on failure. + bool Create(const SharedMemoryCreateOptions& options); + // Creates and maps an anonymous shared memory segment of size size. // Returns true on success and false on failure. bool CreateAndMapAnonymous(uint32 size); // Creates an anonymous shared memory segment of size size. // Returns true on success and false on failure. - bool CreateAnonymous(uint32 size); + bool CreateAnonymous(uint32 size) { + SharedMemoryCreateOptions options; + options.size = size; + return Create(options); + } // Creates or opens a shared memory segment based on a name. // If open_existing is true, and the shared memory already exists, @@ -88,7 +119,13 @@ class BASE_EXPORT SharedMemory { // If open_existing is false, shared memory must not exist. // size is the size of the block to be created. // Returns true on success, false on failure. - bool CreateNamed(const std::string& name, bool open_existing, uint32 size); + bool CreateNamed(const std::string& name, bool open_existing, uint32 size) { + SharedMemoryCreateOptions options; + options.name = &name; + options.open_existing = open_existing; + options.size = size; + return Create(options); + } // Deletes resources associated with a shared memory segment based on name. // Not all platforms require this call. |