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

Side by Side Diff: mojo/edk/system/channel.h

Issue 1712143002: [mojo-edk] Add support for transferring mach ports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More stuff. Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_ 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_
6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Number of attached handles. May be less than the reserved handle 59 // Number of attached handles. May be less than the reserved handle
60 // storage size in this message on platforms that serialise handles as 60 // storage size in this message on platforms that serialise handles as
61 // data (i.e. HANDLEs on Windows, Mach ports on OSX). 61 // data (i.e. HANDLEs on Windows, Mach ports on OSX).
62 uint16_t num_handles; 62 uint16_t num_handles;
63 63
64 MessageType message_type; 64 MessageType message_type;
65 65
66 char padding[6]; 66 char padding[6];
67 #endif // defined(OS_CHROMEOS) 67 #endif // defined(OS_CHROMEOS)
68 }; 68 };
69
70 #if defined(OS_MACOSX)
71 struct MachPortsEntry {
72 uint16_t index;
73 uint32_t mach_port;
74 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t),
75 "mach_port_t must be smaller than uint32_t");
Ken Rockot(use gerrit already) 2016/03/09 08:34:31 nit: must be no larger than uint32_t
Anand Mistry (off Chromium) 2016/03/11 07:44:18 Done.
76 };
77 static_assert(sizeof(MachPortsEntry) == 6,
78 "sizeof(MachPortsEntry) must be 6 bytes");
79 #endif
69 #pragma pack(pop) 80 #pragma pack(pop)
70 81
71 // Allocates and owns a buffer for message data with enough capacity for 82 // Allocates and owns a buffer for message data with enough capacity for
72 // |payload_size| bytes plus a header, plus |max_handles| platform handles. 83 // |payload_size| bytes plus a header, plus |max_handles| platform handles.
73 Message(size_t payload_size, 84 Message(size_t payload_size,
74 size_t max_handles, 85 size_t max_handles,
75 Header::MessageType message_type = Header::MessageType::NORMAL); 86 Header::MessageType message_type = Header::MessageType::NORMAL);
76 87
77 ~Message(); 88 ~Message();
78 89
(...skipping 25 matching lines...) Expand all
104 bool has_handles() const { return header_->num_handles > 0; } 115 bool has_handles() const { return header_->num_handles > 0; }
105 PlatformHandle* handles(); 116 PlatformHandle* handles();
106 #if defined(OS_MACOSX) && !defined(OS_IOS) 117 #if defined(OS_MACOSX) && !defined(OS_IOS)
107 bool has_mach_ports() const; 118 bool has_mach_ports() const;
108 #endif 119 #endif
109 120
110 // Note: SetHandles() and TakeHandles() invalidate any previous value of 121 // Note: SetHandles() and TakeHandles() invalidate any previous value of
111 // handles(). 122 // handles().
112 void SetHandles(ScopedPlatformHandleVectorPtr new_handles); 123 void SetHandles(ScopedPlatformHandleVectorPtr new_handles);
113 ScopedPlatformHandleVectorPtr TakeHandles(); 124 ScopedPlatformHandleVectorPtr TakeHandles();
125 // Version of TakeHandles that returns a vector of platform handles suitable
126 // for transfer over an underlying OS mechanism. i.e. file descriptors over
127 // a unix domain socket. Any handle that cannot be transferred this way,
128 // such as Mach port, will be removed.
129 ScopedPlatformHandleVectorPtr TakeHandlesForTransport();
114 130
115 #if defined(OS_WIN) 131 #if defined(OS_WIN)
116 // Prepares the handles in this message for use in a different process. 132 // Prepares the handles in this message for use in a different process.
117 // Upon calling this the handles should belong to |from_process|; after the 133 // Upon calling this the handles should belong to |from_process|; after the
118 // call they'll belong to |to_process|. The source handles are always 134 // call they'll belong to |to_process|. The source handles are always
119 // closed by this call. Returns false iff one or more handles failed 135 // closed by this call. Returns false iff one or more handles failed
120 // duplication. 136 // duplication.
121 static bool RewriteHandles(base::ProcessHandle from_process, 137 static bool RewriteHandles(base::ProcessHandle from_process,
122 base::ProcessHandle to_process, 138 base::ProcessHandle to_process,
123 PlatformHandle* handles, 139 PlatformHandle* handles,
124 size_t num_handles); 140 size_t num_handles);
125 #endif 141 #endif
126 142
127 private: 143 private:
128 size_t size_; 144 size_t size_;
129 size_t max_handles_; 145 size_t max_handles_;
130 char* data_; 146 char* data_;
131 Header* header_; 147 Header* header_;
132 148
133 #if defined(OS_WIN) 149 #if defined(OS_WIN)
134 // On Windows, handles are serialized in the data buffer along with the 150 // On Windows, handles are serialized in the data buffer along with the
135 // rest of the payload. 151 // rest of the payload.
136 PlatformHandle* handles_ = nullptr; 152 PlatformHandle* handles_ = nullptr;
137 #else 153 #else
138 ScopedPlatformHandleVectorPtr handle_vector_; 154 ScopedPlatformHandleVectorPtr handle_vector_;
139 #endif 155 #endif
140 156
157 #if defined(OS_MACOSX)
158 // On OSX, handles which are mach ports are serialised into the data buffer
159 // after the rest of the payload.
160 MachPortsEntry* mach_ports_ = nullptr;
Ken Rockot(use gerrit already) 2016/03/09 08:34:31 nit: this comment appears to be out of date since
Anand Mistry (off Chromium) 2016/03/11 07:44:17 Done, and updated the windows comment.
161 #endif
162
141 DISALLOW_COPY_AND_ASSIGN(Message); 163 DISALLOW_COPY_AND_ASSIGN(Message);
142 }; 164 };
143 165
144 // Delegate methods are called from the I/O task runner with which the Channel 166 // Delegate methods are called from the I/O task runner with which the Channel
145 // was created (see Channel::Create). 167 // was created (see Channel::Create).
146 class Delegate { 168 class Delegate {
147 public: 169 public:
148 virtual ~Delegate() {} 170 virtual ~Delegate() {}
149 171
150 // Notify of a received message. |payload| is not owned and must not be 172 // Notify of a received message. |payload| is not owned and must not be
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 Delegate* delegate_; 254 Delegate* delegate_;
233 const scoped_ptr<ReadBuffer> read_buffer_; 255 const scoped_ptr<ReadBuffer> read_buffer_;
234 256
235 DISALLOW_COPY_AND_ASSIGN(Channel); 257 DISALLOW_COPY_AND_ASSIGN(Channel);
236 }; 258 };
237 259
238 } // namespace edk 260 } // namespace edk
239 } // namespace mojo 261 } // namespace mojo
240 262
241 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ 263 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698