| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ | |
| 6 #define MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ | |
| 7 | |
| 8 #include <mojo/result.h> | |
| 9 #include <mojo/system/handle.h> | |
| 10 | |
| 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; | |
| 15 | |
| 16 #ifdef __cplusplus | |
| 17 extern "C" { | |
| 18 #endif | |
| 19 | |
| 20 // |MojoCreatePlatformHandleWrapper()|: Creates a |MojoHandle| that wraps (and | |
| 21 // takes ownership of) the platform handle |platform_handle|, which must be | |
| 22 // valid. | |
| 23 // | |
| 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| | |
| 31 // (which just means that |platform_handle| will be closed). | |
| 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); | |
| 40 | |
| 41 // |MojoExtractPlatformHandle()|: Extracts the wrapped platform handle from | |
| 42 // |platform_handle_wrapper_handle| (which must have both the | |
| 43 // |MOJO_HANDLE_RIGHT_READ| and |MOJO_HANDLE_RIGHT_WRITE| rights). | |
| 44 // | |
| 45 // On success, |*platform_handle| will be set to the wrapped platform handle and | |
| 46 // ownership of the wrapped platform handle will be passed to the caller (i.e., | |
| 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, | |
| 66 MojoPlatformHandle* platform_handle); | |
| 67 | |
| 68 #ifdef __cplusplus | |
| 69 } // extern "C" | |
| 70 #endif | |
| 71 | |
| 72 #endif // MOJO_PUBLIC_PLATFORM_NATIVE_PLATFORM_HANDLE_PRIVATE_H_ | |
| OLD | NEW |