Index: base/memory/shared_memory_posix.cc |
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc |
index efb0caf5bc9a29d805700c3abdad18ad6671a199..6c6845f4b4b774e14278b54c32ac8b8fd6648480 100644 |
--- a/base/memory/shared_memory_posix.cc |
+++ b/base/memory/shared_memory_posix.cc |
@@ -16,6 +16,7 @@ |
#include "base/logging.h" |
#include "base/process/process_metrics.h" |
#include "base/safe_strerror_posix.h" |
+#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/synchronization/lock.h" |
#include "base/threading/platform_thread.h" |
@@ -399,12 +400,32 @@ void SharedMemory::LockOrUnlockCommon(int function) { |
} |
bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
- SharedMemoryHandle *new_handle, |
- bool close_self) { |
- const int new_fd = dup(mapped_file_); |
- if (new_fd < 0) { |
- DPLOG(ERROR) << "dup() failed."; |
- return false; |
+ SharedMemoryHandle* new_handle, |
+ bool close_self, |
+ ShareMode share_mode) { |
+ int new_fd = -1; |
+ switch(share_mode) { |
+ case SHARE_CURRENT_MODE: { |
+ new_fd = dup(mapped_file_); |
+ if (new_fd < 0) { |
+ DPLOG(ERROR) << "dup() failed."; |
+ return false; |
+ } |
+ } break; |
+ case SHARE_READONLY: { |
+ const std::string writable_fd_path = StringPrintf( |
+#if defined(OS_ANDROID) |
+ "/proc/self/fd/%d", |
+#else |
+ "/dev/fd/%d", |
+#endif |
+ mapped_file_); |
+ new_fd = HANDLE_EINTR(open(writable_fd_path.c_str(), O_RDONLY)); |
Jeffrey Yasskin
2013/10/17 03:00:25
This approach doesn't work on Apple OSen.
iOS: ht
|
+ if (new_fd < 0) { |
+ DPLOG(ERROR) << "open(\"" << writable_fd_path << "\", O_RDONLY) failed"; |
+ return false; |
+ } |
+ } break; |
} |
new_handle->fd = new_fd; |