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

Unified Diff: base/memory/shared_memory_win.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_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_win.cc
diff --git a/base/memory/shared_memory_win.cc b/base/memory/shared_memory_win.cc
index daa700da6a373cd491ce56228f9b58037517c23f..e19b775584e553a7dff8e34bd62be727088262ce 100644
--- a/base/memory/shared_memory_win.cc
+++ b/base/memory/shared_memory_win.cc
@@ -13,6 +13,7 @@
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/unguessable_token.h"
namespace {
@@ -240,8 +241,9 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
rand_values[2], rand_values[3]);
}
DCHECK(!name_.empty());
- shm_ = SharedMemoryHandle(CreateFileMappingWithReducedPermissions(
- &sa, rounded_size, name_.c_str()));
+ shm_ = SharedMemoryHandle(
+ CreateFileMappingWithReducedPermissions(&sa, rounded_size, name_.c_str()),
+ UnguessableToken::Create());
if (!shm_.IsValid()) {
// The error is logged within CreateFileMappingWithReducedPermissions().
return false;
@@ -279,8 +281,18 @@ bool SharedMemory::Open(const std::string& name, bool read_only) {
access |= FILE_MAP_WRITE;
name_ = ASCIIToUTF16(name);
read_only_ = read_only;
+
+ // 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(
- OpenFileMapping(access, false, name_.empty() ? nullptr : name_.c_str()));
+ OpenFileMapping(access, false, name_.empty() ? nullptr : name_.c_str()),
+ UnguessableToken::Create());
if (!shm_.IsValid())
return false;
// If a name specified assume it's an external section.
@@ -332,7 +344,7 @@ SharedMemoryHandle SharedMemory::GetReadOnlyHandle() {
FILE_MAP_READ | SECTION_QUERY, FALSE, 0)) {
return SharedMemoryHandle();
}
- SharedMemoryHandle handle = SharedMemoryHandle(result);
+ SharedMemoryHandle handle = SharedMemoryHandle(result, shm_.GetGUID());
handle.SetOwnershipPassesToIPC(true);
return handle;
}
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698