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

Unified Diff: base/memory/shared_memory_handle.h

Issue 2875453002: Add a size parameter to SharedMemoryHandle. (Closed)
Patch Set: Fix IPC on POSIX. 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
Index: base/memory/shared_memory_handle.h
diff --git a/base/memory/shared_memory_handle.h b/base/memory/shared_memory_handle.h
index 469eba227d5e71ca93f129da491438cc5752b76b..099723e896fbf98576bffc9a8cd50e76d8903990 100644
--- a/base/memory/shared_memory_handle.h
+++ b/base/memory/shared_memory_handle.h
@@ -71,6 +71,10 @@ class BASE_EXPORT SharedMemoryHandle {
// memory region will have the same GUID. Preserved across IPC.
base::UnguessableToken GetGUID() const;
+ // Returns false on a failure to determine the size. On success, populates the
+ // output variable |size|.
Nico 2017/05/15 22:13:36 What?
erikchen 2017/05/15 22:57:18 Updated comment.
+ size_t GetSize() const;
+
#if defined(OS_MACOSX) && !defined(OS_IOS)
enum Type {
// The SharedMemoryHandle is backed by a POSIX fd.
@@ -92,6 +96,7 @@ class BASE_EXPORT SharedMemoryHandle {
// SharedMemoryHandle. Otherwise, the caller should generate a new
// UnguessableToken.
Nico 2017/05/15 22:13:36 Document size and what happens if the passed-in si
erikchen 2017/05/15 22:57:18 Done.
SharedMemoryHandle(const base::FileDescriptor& file_descriptor,
+ size_t size,
const base::UnguessableToken& guid);
// Makes a Mach-based SharedMemoryHandle of the given size. On error,
@@ -108,10 +113,6 @@ class BASE_EXPORT SharedMemoryHandle {
// processes.
mach_port_t GetMemoryObject() const;
- // Returns false on a failure to determine the size. On success, populates the
- // output variable |size|.
- bool GetSize(size_t* size) const;
-
// The SharedMemoryHandle must be valid.
// Returns whether the SharedMemoryHandle was successfully mapped into memory.
// On success, |memory| is an output variable that contains the start of the
@@ -124,7 +125,7 @@ class BASE_EXPORT SharedMemoryHandle {
// SharedMemoryHandle, the caller must pass the |guid| of that
// SharedMemoryHandle. Otherwise, the caller should generate a new
// UnguessableToken.
- SharedMemoryHandle(HANDLE h, const base::UnguessableToken& guid);
+ SharedMemoryHandle(HANDLE h, size_t size, const base::UnguessableToken& guid);
HANDLE GetHandle() const;
#else
// |guid| uniquely identifies the shared memory region pointed to by the
@@ -133,18 +134,16 @@ class BASE_EXPORT SharedMemoryHandle {
// SharedMemoryHandle. Otherwise, the caller should generate a new
// UnguessableToken.
SharedMemoryHandle(const base::FileDescriptor& file_descriptor,
+ size_t size,
const base::UnguessableToken& guid);
// Creates a SharedMemoryHandle from an |fd| supplied from an external
// service.
- static SharedMemoryHandle ImportHandle(int fd);
+ static SharedMemoryHandle ImportHandle(int fd, size_t size);
// Returns the underlying OS resource.
int GetHandle() const;
- // Takes ownership of the OS resource.
- void SetHandle(int fd);
-
// Invalidates [but doesn't close] the underlying OS resource. This will leak
// unless the caller is careful.
int Release();
@@ -164,10 +163,6 @@ class BASE_EXPORT SharedMemoryHandle {
struct {
mach_port_t memory_object_;
- // The size of the shared memory region when |type_| is MACH. Only
- // relevant if |memory_object_| is not |MACH_PORT_NULL|.
- mach_vm_size_t size_;
-
// Whether passing this object as a parameter to an IPC message passes
// ownership of |memory_object_| to the IPC stack. This is meant to mimic
// the behavior of the |auto_close| parameter of FileDescriptor.
@@ -189,6 +184,9 @@ class BASE_EXPORT SharedMemoryHandle {
#endif
base::UnguessableToken guid_;
+
+ // The size of the region referenced by the SharedMemoryHandle.
+ size_t size_ = 0;
Nico 2017/05/15 22:13:36 Either use in-class initialization for all fields
erikchen 2017/05/15 22:57:18 all of them, it is.
};
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698