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

Unified Diff: base/memory/shared_memory_posix.cc

Issue 2859843002: Add a GUID to base::SharedMemoryHandle. (Closed)
Patch Set: fix guid on android. Created 3 years, 7 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_mac_unittest.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 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)
« no previous file with comments | « base/memory/shared_memory_mac_unittest.cc ('k') | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698