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

Side by Side Diff: mojo/public/c/system/functions.h

Issue 1995753002: [mojo-edk] Expose portable API for platform handle wrapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file contains basic functions common to different Mojo system APIs. 5 // This file contains basic functions common to different Mojo system APIs.
6 // 6 //
7 // Note: This header should be compilable as C. 7 // Note: This header should be compilable as C.
8 8
9 #ifndef MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ 9 #ifndef MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_
10 #define MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ 10 #define MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_
11 11
12 #include <stddef.h> 12 #include <stddef.h>
13 #include <stdint.h> 13 #include <stdint.h>
14 14
15 #include "mojo/public/c/system/system_export.h" 15 #include "mojo/public/c/system/system_export.h"
16 #include "mojo/public/c/system/types.h" 16 #include "mojo/public/c/system/types.h"
17 17
18 #ifdef __cplusplus 18 #ifdef __cplusplus
19 extern "C" { 19 extern "C" {
20 #endif 20 #endif
21 21
22 // |MojoPlatformSharedBufferHandleFlags|: Flags relevant to wrapped platform
23 // shared buffers.
24 //
25 // |MOJO_PLATFORM_SHARED_BUFFER_HANDLE_NONE| - No flags.
26 // |MOJO_PLATFORM_SHARED_BUFFER_HANDLE_READ_ONLY| - Indicates that the wrapped
27 // buffer handle may only be mapped for reading.
28
29 typedef uint32_t MojoPlatformSharedBufferHandleFlags;
30
31 #ifdef __cplusplus
32 const MojoPlatformSharedBufferHandleFlags
33 MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE = 0;
34
35 const MojoPlatformSharedBufferHandleFlags
36 MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY = 1 << 0;
37 #else
38 #define MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE
39 ((MojoPlatformSharedBufferHandleFlags)0)
40
41 #define MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY \
42 ((MojoPlatformSharedBufferHandleFlags)1 << 0)
43 #endif
44
22 // A callback used to notify watchers registered via |MojoWatch()|. Called when 45 // A callback used to notify watchers registered via |MojoWatch()|. Called when
23 // some watched signals are satisfied or become unsatisfiable. See the 46 // some watched signals are satisfied or become unsatisfiable. See the
24 // documentation for |MojoWatch()| for more details. 47 // documentation for |MojoWatch()| for more details.
25 typedef void (*MojoWatchCallback)(uintptr_t context, 48 typedef void (*MojoWatchCallback)(uintptr_t context,
26 MojoResult result, 49 MojoResult result,
27 struct MojoHandleSignalsState signals_state, 50 struct MojoHandleSignalsState signals_state,
28 MojoWatchNotificationFlags flags); 51 MojoWatchNotificationFlags flags);
29 52
30 // Note: Pointer parameters that are labelled "optional" may be null (at least 53 // Note: Pointer parameters that are labelled "optional" may be null (at least
31 // under some circumstances). Non-const pointer parameters are also labeled 54 // under some circumstances). Non-const pointer parameters are also labeled
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // |MojoWatch()|. Only the watch corresponding to this context will be 222 // |MojoWatch()|. Only the watch corresponding to this context will be
200 // cancelled. 223 // cancelled.
201 // 224 //
202 // Returns: 225 // Returns:
203 // |MOJO_RESULT_OK| if the watch corresponding to |context| was cancelled. 226 // |MOJO_RESULT_OK| if the watch corresponding to |context| was cancelled.
204 // |MOJO_RESULT_INVALID_ARGUMENT| if no watch was registered with |context| 227 // |MOJO_RESULT_INVALID_ARGUMENT| if no watch was registered with |context|
205 // for the given |handle|, or if |handle| is invalid. 228 // for the given |handle|, or if |handle| is invalid.
206 MOJO_SYSTEM_EXPORT MojoResult 229 MOJO_SYSTEM_EXPORT MojoResult
207 MojoCancelWatch(MojoHandle handle, uintptr_t context); 230 MojoCancelWatch(MojoHandle handle, uintptr_t context);
208 231
232 // Wraps a generic platform handle as a Mojo handle which can be transferred
233 // over a message pipe. Takes ownership of the platform handle.
234 //
235 // |platform_handle|: The platform handle to wrap.
236 //
237 // Returns:
238 // |MOJO_RESULT_OK| if the handle was successfully wrapped. In this case
239 // |*mojo_handle| contains the Mojo handle of the wrapped object.
240 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the system is out of handles.
241 // |MOJO_RESULT_INVALID_ARGUMENT| if |platform_handle| was not a valid
242 // platform handle.
243 //
244 // NOTE: It is not alwawys possible to detect if |platform_handle| is valid, so
245 // this call may succeed even when |handle| invalid (e.g. a valid file
246 // descriptor value for a file descriptor that isn't actually open.)
247 MOJO_SYSTEM_EXPORT MojoResult
248 MojoWrapPlatformHandle(MojoPlatformHandle platform_handle,
249 MojoHandle* mojo_handle); // Out
250
251 // Unwraps a generic platform handle from a Mojo handle. If this call succeeds,
252 // the Mojo handle is closed. If this call succeeds, ownership of the underlying
253 // platform object is bound to the returned platform handle and becomes the
254 // caller's responsibility.
255 //
256 // |mojo_handle|: The Mojo handle from which to unwrap the platform handle.
257 //
258 // Returns:
259 // |MOJO_RESULT_OK| if the handle was successfully unwrapped. In this case
260 // |*platform_handle| contains the unwrapped platform handle.
261 // |MOJO_RESULT_INVALID_ARGUMENT| if |mojo_handle| was not a valid Mojo
262 // handle wrapping a platform handle.
263 MOJO_SYSTEM_EXPORT MojoResult
264 MojoUnwrapPlatformHandle(MojoHandle mojo_handle,
265 MojoPlatformHandle* platform_handle); // Out
266
267 // Wraps a platform shared buffer handle as a Mojo shared buffer handle which
268 // can be transferred over a message pipe. Takes ownership of the platform
269 // shared buffer handle.
270 //
271 // |platform_handle|: The platform handle to wrap. Must be a handle to a
272 // shared buffer object.
273 // |num_bytes|: The size of the shared buffer in bytes.
274 //
275 // NOTE: Set |MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY| in |flags| if
276 // the buffer to be wrapped is already read-only. This flag does NOT change the
277 // access control of the buffer in any way.
278 //
279 // Returns:
280 // |MOJO_RESULT_OK| if the handle was successfully wrapped. In this case
281 // |*mojo_handle| contains a Mojo shared buffer handle.
282 // |MOJO_RESULT_INVALID_ARGUMENT| if |platform_handle| was not a valid
283 // platform shared buffer handle.
284 MOJO_SYSTEM_EXPORT MojoResult
285 MojoWrapPlatformSharedBufferHandle(MojoPlatformHandle platform_handle,
286 size_t num_bytes,
287 MojoPlatformSharedBufferHandleFlags flags,
288 MojoHandle* mojo_handle); // Out
289
290 // Unwraps a platform shared buffer handle from a Mojo shared buffer handle.
291 // If this call succeeds, ownership of the underlying shared buffer object is
292 // bound to the returned platform handle and becomes the caller's
293 // responsibility.
294 //
295 // |mojo_handle|: The Mojo shared buffer handle to unwrap.
296 //
297 // Returns:
298 // |MOJO_RESULT_OK| if the handle was successfully unwrapped. In this case
299 // |*platform_handle| contains a platform shared buffer handle,
300 // |*num_bytes| contains the size of the shared buffer object, and
301 // |*flags| indicates flags relevant to the wrapped buffer (see below).
302 // |MOJO_RESULT_INVALID_ARGUMENT| if |mojo_handle| is not a valid Mojo
303 // shared buffer handle.
304 //
305 // Flags which may be set in |*flags| upon success:
306 // |MOJO_PLATFORM_SHARED_BUFFER_FLAG_READ_ONLY| is set iff the unwrapped
307 // shared buffer handle may only be used for read-only mapping.
308 MOJO_SYSTEM_EXPORT MojoResult
309 MojoUnwrapPlatformSharedBufferHandle(
310 MojoHandle mojo_handle,
311 MojoPlatformHandle* platform_handle,
312 size_t* num_bytes,
313 MojoPlatformSharedBufferHandleFlags* flags);
314
209 #ifdef __cplusplus 315 #ifdef __cplusplus
210 } // extern "C" 316 } // extern "C"
211 #endif 317 #endif
212 318
213 #endif // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ 319 #endif // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698