| OLD | NEW |
| 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 types/constants and functions specific to buffers (and in | 5 // This file contains types/constants and functions specific to buffers (and in |
| 6 // particular shared buffers). | 6 // particular shared buffers). |
| 7 // TODO(vtl): Reorganize this file (etc.) to separate general buffer functions | 7 // TODO(vtl): Reorganize this file (etc.) to separate general buffer functions |
| 8 // from (shared) buffer creation. | 8 // from (shared) buffer creation. |
| 9 // | 9 // |
| 10 // Note: This header should be compilable as C. | 10 // Note: This header should be compilable as C. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); | 35 MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); |
| 36 struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { | 36 struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { |
| 37 uint32_t struct_size; | 37 uint32_t struct_size; |
| 38 MojoCreateSharedBufferOptionsFlags flags; | 38 MojoCreateSharedBufferOptionsFlags flags; |
| 39 }; | 39 }; |
| 40 MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, | 40 MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, |
| 41 "MojoCreateSharedBufferOptions has wrong size"); | 41 "MojoCreateSharedBufferOptions has wrong size"); |
| 42 | 42 |
| 43 // |MojoDuplicateBufferHandleOptions|: Used to specify parameters in duplicating | 43 // |MojoDuplicateBufferHandleOptions|: Used to specify parameters in duplicating |
| 44 // access to a shared buffer to |MojoDuplicateBufferHandle()|. | 44 // access to a buffer to |MojoDuplicateBufferHandle()|. |
| 45 // |uint32_t struct_size|: Set to the size of the | 45 // |uint32_t struct_size|: Set to the size of the |
| 46 // |MojoDuplicateBufferHandleOptions| struct. (Used to allow for future | 46 // |MojoDuplicateBufferHandleOptions| struct. (Used to allow for future |
| 47 // extensions.) | 47 // extensions.) |
| 48 // |MojoDuplicateBufferHandleOptionsFlags flags|: Reserved for future use. | 48 // |MojoDuplicateBufferHandleOptionsFlags flags|: Reserved for future use. |
| 49 // |MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE|: No flags; default | 49 // |MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE|: No flags; default |
| 50 // mode. | 50 // mode. |
| 51 // | 51 // |
| 52 // TODO(vtl): Add flags to remove writability (and executability)? Also, COW? | 52 // TODO(vtl): Add flags to remove writability (and executability)? Also, COW? |
| 53 | 53 |
| 54 typedef uint32_t MojoDuplicateBufferHandleOptionsFlags; | 54 typedef uint32_t MojoDuplicateBufferHandleOptionsFlags; |
| 55 | 55 |
| 56 #define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \ | 56 #define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \ |
| 57 ((MojoDuplicateBufferHandleOptionsFlags)0) | 57 ((MojoDuplicateBufferHandleOptionsFlags)0) |
| 58 | 58 |
| 59 struct MojoDuplicateBufferHandleOptions { | 59 struct MOJO_ALIGNAS(8) MojoDuplicateBufferHandleOptions { |
| 60 uint32_t struct_size; | 60 uint32_t struct_size; |
| 61 MojoDuplicateBufferHandleOptionsFlags flags; | 61 MojoDuplicateBufferHandleOptionsFlags flags; |
| 62 }; | 62 }; |
| 63 MOJO_STATIC_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8, | 63 MOJO_STATIC_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8, |
| 64 "MojoDuplicateBufferHandleOptions has wrong size"); | 64 "MojoDuplicateBufferHandleOptions has wrong size"); |
| 65 | 65 |
| 66 // |MojoBufferInformation|: Used to provide information about a buffer (see |
| 67 // |MojoGetBufferInformation()|. |
| 68 // |uint32_t struct_size|: Set to the size of the |MojoBufferInformation| |
| 69 // struct. (Used to allow for future extensions.) |
| 70 // |MojoBufferInformationFlags flags|: Reserved for future use. |
| 71 // |uint64_t num_bytes|: Size of the buffer. |
| 72 // |
| 73 // TODO(vtl): Add flags to indicate writability, etc.? Also, type of buffer? |
| 74 |
| 75 typedef uint32_t MojoBufferInformationFlags; |
| 76 |
| 77 #define MOJO_BUFFER_INFORMATION_FLAG_NONE ((MojoBufferInformationFlags)0) |
| 78 |
| 79 struct MOJO_ALIGNAS(8) MojoBufferInformation { |
| 80 uint32_t struct_size; |
| 81 MojoBufferInformationFlags flags; |
| 82 uint64_t num_bytes; |
| 83 }; |
| 84 MOJO_STATIC_ASSERT(sizeof(MojoBufferInformation) == 16, |
| 85 "MojoBufferInformation has wrong size"); |
| 86 |
| 66 // |MojoMapBufferFlags|: Used to specify different modes to |MojoMapBuffer()|. | 87 // |MojoMapBufferFlags|: Used to specify different modes to |MojoMapBuffer()|. |
| 67 // |MOJO_MAP_BUFFER_FLAG_NONE| - No flags; default mode. | 88 // |MOJO_MAP_BUFFER_FLAG_NONE| - No flags; default mode. |
| 68 | 89 |
| 69 typedef uint32_t MojoMapBufferFlags; | 90 typedef uint32_t MojoMapBufferFlags; |
| 70 | 91 |
| 71 #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags)0) | 92 #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags)0) |
| 72 | 93 |
| 73 #ifdef __cplusplus | 94 #ifdef __cplusplus |
| 74 extern "C" { | 95 extern "C" { |
| 75 #endif | 96 #endif |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // Returns: | 139 // Returns: |
| 119 // |MOJO_RESULT_OK| on success. | 140 // |MOJO_RESULT_OK| on success. |
| 120 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 141 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 121 // |buffer_handle| is not a valid buffer handle or |*options| is invalid). | 142 // |buffer_handle| is not a valid buffer handle or |*options| is invalid). |
| 122 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 143 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
| 123 MojoResult MojoDuplicateBufferHandle( | 144 MojoResult MojoDuplicateBufferHandle( |
| 124 MojoHandle buffer_handle, | 145 MojoHandle buffer_handle, |
| 125 const struct MojoDuplicateBufferHandleOptions* options, // Optional. | 146 const struct MojoDuplicateBufferHandleOptions* options, // Optional. |
| 126 MojoHandle* new_buffer_handle); // Out. | 147 MojoHandle* new_buffer_handle); // Out. |
| 127 | 148 |
| 149 // Gets information about the buffer with handle |buffer_handle|. |info| should |
| 150 // be non-null and point to a buffer of size |info_num_bytes|; |info_num_bytes| |
| 151 // should be at least 16 (the size of the first, and currently only, version of |
| 152 // |struct MojoBufferInformation|). |
| 153 // |
| 154 // On success, |*info| will be filled with information about the given buffer. |
| 155 // Note that if additional (larger) versions of |struct MojoBufferInformation| |
| 156 // are defined, the largest version permitted by |info_num_bytes| that is |
| 157 // supported by the implementation will be filled. Callers expecting more than |
| 158 // the first 16-byte version must check the resulting |info->struct_size|. |
| 159 // |
| 160 // Returns: |
| 161 // |MOJO_RESULT_OK| on success. |
| 162 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 163 // |buffer_handle| is not a valid buffer handle, |*info| is null, or |
| 164 // |info_num_bytes| is too small). |
| 165 MojoResult MojoGetBufferInformation(MojoHandle buffer_handle, |
| 166 struct MojoBufferInformation* info, // Out. |
| 167 uint32_t info_num_bytes); // In. |
| 168 |
| 128 // Maps the part (at offset |offset| of length |num_bytes|) of the buffer given | 169 // Maps the part (at offset |offset| of length |num_bytes|) of the buffer given |
| 129 // by |buffer_handle| into memory, with options specified by |flags|. |offset + | 170 // by |buffer_handle| into memory, with options specified by |flags|. |offset + |
| 130 // num_bytes| must be less than or equal to the size of the buffer. On success, | 171 // num_bytes| must be less than or equal to the size of the buffer. On success, |
| 131 // |*buffer| points to memory with the requested part of the buffer. (On | 172 // |*buffer| points to memory with the requested part of the buffer. (On |
| 132 // failure, it is not modified.) | 173 // failure, it is not modified.) |
| 133 // | 174 // |
| 134 // A single buffer handle may have multiple active mappings (possibly depending | 175 // A single buffer handle may have multiple active mappings (possibly depending |
| 135 // on the buffer type). The permissions (e.g., writable or executable) of the | 176 // on the buffer type). The permissions (e.g., writable or executable) of the |
| 136 // returned memory may depend on the properties of the buffer and properties | 177 // returned memory may depend on the properties of the buffer and properties |
| 137 // attached to the buffer handle as well as |flags|. | 178 // attached to the buffer handle as well as |flags|. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 162 // |MOJO_RESULT_OK| on success. | 203 // |MOJO_RESULT_OK| on success. |
| 163 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the | 204 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the |
| 164 // result of |MojoMapBuffer()| or has already been unmapped). | 205 // result of |MojoMapBuffer()| or has already been unmapped). |
| 165 MojoResult MojoUnmapBuffer(void* buffer); // In. | 206 MojoResult MojoUnmapBuffer(void* buffer); // In. |
| 166 | 207 |
| 167 #ifdef __cplusplus | 208 #ifdef __cplusplus |
| 168 } // extern "C" | 209 } // extern "C" |
| 169 #endif | 210 #endif |
| 170 | 211 |
| 171 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ | 212 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ |
| OLD | NEW |