Index: base/memory/shared_memory_posix.cc |
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc |
index 0444e59dba1c9f5ca52df331126ecbf8c47ea6f8..f44e3a27d10e66f0a8f6edee84bfe73854b0a22d 100644 |
--- a/base/memory/shared_memory_posix.cc |
+++ b/base/memory/shared_memory_posix.cc |
@@ -23,6 +23,7 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "base/threading/thread_restrictions.h" |
#include "base/trace_event/trace_event.h" |
+#include "base/unguessable_token.h" |
#include "build/build_config.h" |
#if defined(OS_ANDROID) |
@@ -211,8 +212,10 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
int readonly_mapped_file = -1; |
bool result = PrepareMapFile(std::move(fp), std::move(readonly_fd), |
&mapped_file, &readonly_mapped_file); |
- shm_ = SharedMemoryHandle::ImportHandle(mapped_file); |
- readonly_shm_ = SharedMemoryHandle::ImportHandle(readonly_mapped_file); |
+ shm_ = SharedMemoryHandle(base::FileDescriptor(mapped_file, false), |
+ UnguessableToken::Create()); |
+ readonly_shm_ = SharedMemoryHandle( |
+ base::FileDescriptor(readonly_mapped_file, false), shm_.GetGUID()); |
return result; |
} |
@@ -249,8 +252,18 @@ bool SharedMemory::Open(const std::string& name, bool read_only) { |
int readonly_mapped_file = -1; |
bool result = PrepareMapFile(std::move(fp), std::move(readonly_fd), |
&mapped_file, &readonly_mapped_file); |
- shm_ = SharedMemoryHandle::ImportHandle(mapped_file); |
- readonly_shm_ = SharedMemoryHandle::ImportHandle(readonly_mapped_file); |
+ // This form of sharing shared memory is deprecated. https://crbug.com/345734. |
+ // However, we can't get rid of it without a significant refactor because its |
+ // used to communicate between two versions of the same service process, very |
+ // early in the life cycle. |
+ // Technically, we should also pass the GUID from the original shared memory |
+ // region. We don't do that - this means that we will overcount this memory, |
+ // which thankfully isn't relevant since Chrome only communicates with a |
+ // single version of the service process. |
+ shm_ = SharedMemoryHandle(base::FileDescriptor(mapped_file, false), |
+ UnguessableToken::Create()); |
+ readonly_shm_ = SharedMemoryHandle( |
+ base::FileDescriptor(readonly_mapped_file, false), shm_.GetGUID()); |
return result; |
} |
#endif // !defined(OS_ANDROID) |