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

Unified Diff: base/memory/shared_memory_posix.cc

Issue 27265002: Implement SharedMemory::NewAnonymousReadOnly(contents). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try to fix Android and Windows Created 7 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_nacl.cc ('k') | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « base/memory/shared_memory_nacl.cc ('k') | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698