Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ | 5 #ifndef MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ |
| 6 #define MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ | 6 #define MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ |
| 7 | 7 |
| 8 #include "mojo/public/c/system/handle.h" | 8 #include "mojo/public/c/system/handle.h" |
| 9 #include "mojo/public/c/system/result.h" | 9 #include "mojo/public/c/system/result.h" |
| 10 | 10 |
| 11 typedef int MojoPlatformHandle; // Unix file descriptor | 11 // |MojoPlatformHandle|: Type for "platform handles", i.e., the underlying OS's |
| 12 // handles. Currently this is always just a Unix file descriptor. | |
| 13 | |
| 14 typedef int MojoPlatformHandle; | |
| 12 | 15 |
| 13 #ifdef __cplusplus | 16 #ifdef __cplusplus |
| 14 extern "C" { | 17 extern "C" { |
| 15 #endif | 18 #endif |
| 16 | 19 |
| 17 // Wraps |platform_handle| in a MojoHandle so that it can transported. Returns | 20 // |MojoCreatePlatformHandleWrapper()|: Creates a |MojoHandle| that wraps (and |
| 18 // MOJO_RESULT_OK on success, all other results indicate failure. This takes | 21 // takes ownership of) the platform handle |platform_handle|, which must be |
| 19 // ownership of |platform_handle|, regardless of whether this succeeds. | 22 // valid. |
| 20 MojoResult MojoCreatePlatformHandleWrapper(MojoPlatformHandle platform_handle, | 23 // |
| 21 MojoHandle* wrapper); | 24 // On success, |*platform_handle_wrapper_handle| will be set to the wrapper |
| 25 // handle. It will have (at least) the |MOJO_HANDLE_RIGHT_TRANSFER|, | |
| 26 // |MOJO_HANDLE_RIGHT_READ|, and |MOJO_HANDLE_RIGHT_WRITE| rights. Warning: No | |
| 27 // validation of |platform_handle| is done. (TODO(vtl): This has poor/annoying | |
| 28 // implications, since we may detect this when we transfer the wrapper handle.) | |
| 29 // | |
| 30 // Warning: On failure, this will still take ownership of |platform_handle| | |
|
azani
2016/05/10 21:15:35
Maybe this is a bit clearer:
Warning: On failure,
| |
| 31 // (which just means that it will close it). | |
| 32 // | |
| 33 // Returns: | |
| 34 // |MOJO_RESULT_OK| on success. | |
| 35 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | |
| 36 // been reached (e.g., if the maximum number of handles was exceeded). | |
| 37 MojoResult MojoCreatePlatformHandleWrapper( | |
| 38 MojoPlatformHandle platform_handle, | |
| 39 MojoHandle* platform_handle_wrapper_handle); | |
| 22 | 40 |
| 23 // Extracts |platform_handle| from |wrapper|. Returns MOJO_RESULT_OK on success, | 41 // |MojoExtractPlatformHandle()|: Extracts the wrapped platform handle from |
| 24 // all other results indicate failure. If this succeeds, it causes |wrapper| to | 42 // |platform_handle_wrapper_handle| (which must have both the |
| 25 // relinquish ownership of |platform_handle|, so MojoClose'ing |wrapper| will no | 43 // |MOJO_HANDLE_RIGHT_READ| and |MOJO_HANDLE_RIGHT_WRITE| rights). |
| 26 // longer close the underlying |platform_handle|. Never the less, it is still | 44 // |
| 27 // neccessary to MojoClose |wrapper|, but this will not affect the underlying | 45 // On success, |*platform_handle| will be set to the wrapped platform handle and |
| 28 // descriptor after this call. | 46 // ownership of the wrapped platform handle will be passed to the caller (i.e., |
| 29 MojoResult MojoExtractPlatformHandle(MojoHandle wrapper, | 47 // closing |platform_handle_wrapper_handle| will no longer close the platform |
| 48 // handle). | |
| 49 // | |
| 50 // Warnings: | |
| 51 // - Even though |platform_handle_wrapper_handle| is then basically useless | |
| 52 // (it no longer "contains" a platform handle), it must still be closed as | |
| 53 // usual. | |
| 54 // - If the wrapped platform handle has already been extracted from | |
| 55 // |platform_handle_wrapper_handle|, then this will still succeed, but | |
| 56 // |*platform_handle| will be set to -1. | |
| 57 // | |
| 58 // Returns: | |
| 59 // |MOJO_RESULT_OK| on success. | |
| 60 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | |
| 61 // |platform_handle_wrapper_handle| is not a valid wrapper handle). | |
| 62 // |MOJO_RESULT_PERMISSION_DENIED| if |platform_handle_wrapper_handle| does | |
| 63 // not have the both the |MOJO_HANDLE_RIGHT_READ| and | |
| 64 // |MOJO_HANDLE_RIGHT_WRITE| rights. | |
| 65 MojoResult MojoExtractPlatformHandle(MojoHandle platform_handle_wrapper_handle, | |
| 30 MojoPlatformHandle* platform_handle); | 66 MojoPlatformHandle* platform_handle); |
| 31 | 67 |
| 32 #ifdef __cplusplus | 68 #ifdef __cplusplus |
| 33 } // extern "C" | 69 } // extern "C" |
| 34 #endif | 70 #endif |
| 35 | 71 |
| 36 #endif // MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ | 72 #endif // MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ |
| OLD | NEW |