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

Unified Diff: base/memory/shared_memory_handle_mac.cc

Issue 1418113003: mac: Add auto-close and share-read-only functionality to SharedMemory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from mark. Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_handle_mac.cc
diff --git a/base/memory/shared_memory_handle_mac.cc b/base/memory/shared_memory_handle_mac.cc
index 13af82dbd952263bc36d023a736eea808717a654..12f2f6893e016e9513e61a72596cd5e9f5a31630 100644
--- a/base/memory/shared_memory_handle_mac.cc
+++ b/base/memory/shared_memory_handle_mac.cc
@@ -8,6 +8,7 @@
#include <sys/mman.h>
#include <unistd.h>
+#include "base/mac/mac_util.h"
#include "base/posix/eintr_wrapper.h"
namespace base {
@@ -44,12 +45,17 @@ SharedMemoryHandle::SharedMemoryHandle(mach_vm_size_t size) {
memory_object_ = named_right;
size_ = size;
pid_ = GetCurrentProcId();
+ ownership_passes_to_ipc_ = false;
}
SharedMemoryHandle::SharedMemoryHandle(mach_port_t memory_object,
mach_vm_size_t size,
base::ProcessId pid)
- : type_(MACH), memory_object_(memory_object), size_(size), pid_(pid) {}
+ : type_(MACH),
+ memory_object_(memory_object),
+ size_(size),
+ pid_(pid),
+ ownership_passes_to_ipc_(false) {}
SharedMemoryHandle::SharedMemoryHandle(const SharedMemoryHandle& handle)
: type_(handle.type_) {
@@ -171,6 +177,9 @@ bool SharedMemoryHandle::MapAt(off_t offset,
return *memory && *memory != reinterpret_cast<void*>(-1);
case SharedMemoryHandle::MACH:
+ // The flag VM_PROT_IS_MASK is only supported on OSX 10.7+.
+ DCHECK(mac::IsOSLionOrLater());
+
DCHECK_EQ(pid_, GetCurrentProcId());
kern_return_t kr = mach_vm_map(
mach_task_self(),
@@ -182,7 +191,7 @@ bool SharedMemoryHandle::MapAt(off_t offset,
offset,
FALSE, // Copy
VM_PROT_READ | (read_only ? 0 : VM_PROT_WRITE), // Current protection
- VM_PROT_READ | VM_PROT_WRITE, // Maximum protection
+ VM_PROT_WRITE | VM_PROT_READ | VM_PROT_IS_MASK, // Maximum protection
VM_INHERIT_NONE);
return kr == KERN_SUCCESS;
}
@@ -205,6 +214,16 @@ void SharedMemoryHandle::Close() const {
}
}
+void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
+ DCHECK_EQ(type_, MACH);
+ ownership_passes_to_ipc_ = ownership_passes;
+}
+
+bool SharedMemoryHandle::OwnershipPassesToIPC() const {
+ DCHECK_EQ(type_, MACH);
+ return ownership_passes_to_ipc_;
+}
+
void SharedMemoryHandle::CopyRelevantData(const SharedMemoryHandle& handle) {
switch (type_) {
case POSIX:
@@ -214,6 +233,7 @@ void SharedMemoryHandle::CopyRelevantData(const SharedMemoryHandle& handle) {
memory_object_ = handle.memory_object_;
size_ = handle.size_;
pid_ = handle.pid_;
+ ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_;
break;
}
}
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698