| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 MOJO_BEGIN_EXTERN_C | 95 MOJO_BEGIN_EXTERN_C |
| 96 | 96 |
| 97 // |MojoCreateSharedBuffer()|: Creates a buffer of size |num_bytes| bytes that | 97 // |MojoCreateSharedBuffer()|: Creates a buffer of size |num_bytes| bytes that |
| 98 // can be shared between applications (by duplicating the handle -- see | 98 // can be shared between applications (by duplicating the handle -- see |
| 99 // |MojoDuplicateBufferHandle()| -- and passing it over a message pipe). To | 99 // |MojoDuplicateBufferHandle()| -- and passing it over a message pipe). To |
| 100 // access the buffer, one must call |MojoMapBuffer()|. | 100 // access the buffer, one must call |MojoMapBuffer()|. |
| 101 // | 101 // |
| 102 // |options| may be set to null for a shared buffer with the default options. | 102 // |options| may be set to null for a shared buffer with the default options. |
| 103 // | 103 // |
| 104 // On success, |*shared_buffer_handle| will be set to the handle for the shared | 104 // On success, |*shared_buffer_handle| will be set to the handle for the shared |
| 105 // buffer. (On failure, it is not modified.) | 105 // buffer. (On failure, it is not modified.) The handle has (at least) the |
| 106 // following rights: |MOJO_HANDLE_RIGHT_DUPLICATE|, |
| 107 // |MOJO_HANDLE_RIGHT_TRANSFER|, |MOJO_HANDLE_RIGHT_GET_OPTIONS|, |
| 108 // |MOJO_HANDLE_RIGHT_SET_OPTIONS|, |MOJO_HANDLE_RIGHT_MAP_READABLE|, |
| 109 // |MOJO_HANDLE_RIGHT_MAP_WRITABLE|, and |MOJO_HANDLE_RIGHT_MAP_EXECUTABLE|. |
| 106 // | 110 // |
| 107 // Note: While more than |num_bytes| bytes may apparently be | 111 // Note: While more than |num_bytes| bytes may apparently be |
| 108 // available/visible/readable/writable, trying to use those extra bytes is | 112 // available/visible/readable/writable, trying to use those extra bytes is |
| 109 // undefined behavior. | 113 // undefined behavior. |
| 110 // | 114 // |
| 111 // Returns: | 115 // Returns: |
| 112 // |MOJO_RESULT_OK| on success. | 116 // |MOJO_RESULT_OK| on success. |
| 113 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 117 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 114 // |*options| is invalid). | 118 // |*options| is invalid). |
| 115 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | 119 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has |
| 116 // been reached (e.g., if the requested size was too large, or if the | 120 // been reached (e.g., if the requested size was too large, or if the |
| 117 // maximum number of handles was exceeded). | 121 // maximum number of handles was exceeded). |
| 118 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 122 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
| 119 MojoResult MojoCreateSharedBuffer( | 123 MojoResult MojoCreateSharedBuffer( |
| 120 const struct MojoCreateSharedBufferOptions* MOJO_RESTRICT | 124 const struct MojoCreateSharedBufferOptions* MOJO_RESTRICT |
| 121 options, // Optional in. | 125 options, // Optional in. |
| 122 uint64_t num_bytes, // In. | 126 uint64_t num_bytes, // In. |
| 123 MojoHandle* MOJO_RESTRICT shared_buffer_handle); // Out. | 127 MojoHandle* MOJO_RESTRICT shared_buffer_handle); // Out. |
| 124 | 128 |
| 125 // |MojoDuplicateBufferHandle()|: Duplicates the handle |buffer_handle| to a | 129 // |MojoDuplicateBufferHandle()|: Duplicates the handle |buffer_handle| (which |
| 126 // buffer. This creates another handle (returned in |*new_buffer_handle| on | 130 // must have the |MOJO_HANDLE_RIGHT_DUPLICATE| right) to a buffer. This creates |
| 127 // success), which can then be sent to another application over a message pipe, | 131 // another handle (returned in |*new_buffer_handle| on success), which can then |
| 128 // while retaining access to the |buffer_handle| (and any mappings that it may | 132 // be sent to another application over a message pipe, while retaining access to |
| 129 // have). | 133 // the |buffer_handle| (and any mappings that it may have). |
| 130 // | 134 // |
| 131 // |options| may be set to null to duplicate the buffer handle with the default | 135 // |options| may be set to null to duplicate the buffer handle with the default |
| 132 // options. | 136 // options. |
| 133 // | 137 // |
| 134 // On success, |*shared_buffer_handle| will be set to the handle for the new | 138 // On success, |*shared_buffer_handle| will be set to the handle for the new |
| 135 // buffer handle. (On failure, it is not modified.) | 139 // buffer handle. (On failure, it is not modified.) |
| 136 // | 140 // |
| 137 // Returns: | 141 // Returns: |
| 138 // |MOJO_RESULT_OK| on success. | 142 // |MOJO_RESULT_OK| on success. |
| 139 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 143 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 140 // |buffer_handle| is not a valid buffer handle or |*options| is invalid). | 144 // |buffer_handle| is not a valid buffer handle or |*options| is invalid). |
| 145 // |MOJO_RESULT_PERMISSION_DENIED| if |buffer_handle| does not have the |
| 146 // |MOJO_HANDLE_RIGHT_DUPLICATE| right. |
| 141 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 147 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
| 142 // |MOJO_RESULT_BUSY| if |buffer_handle| is currently in use in some | 148 // |MOJO_RESULT_BUSY| if |buffer_handle| is currently in use in some |
| 143 // transaction (that, e.g., may result in it being invalidated, such as | 149 // transaction (that, e.g., may result in it being invalidated, such as |
| 144 // being sent in a message). | 150 // being sent in a message). |
| 145 MojoResult MojoDuplicateBufferHandle( | 151 MojoResult MojoDuplicateBufferHandle( |
| 146 MojoHandle buffer_handle, // In. | 152 MojoHandle buffer_handle, // In. |
| 147 const struct MojoDuplicateBufferHandleOptions* MOJO_RESTRICT | 153 const struct MojoDuplicateBufferHandleOptions* MOJO_RESTRICT |
| 148 options, // Optional in. | 154 options, // Optional in. |
| 149 MojoHandle* MOJO_RESTRICT new_buffer_handle); // Out. | 155 MojoHandle* MOJO_RESTRICT new_buffer_handle); // Out. |
| 150 | 156 |
| 151 // |MojoGetBufferInformation()|: Gets information about the buffer with handle | 157 // |MojoGetBufferInformation()|: Gets information about the buffer with handle |
| 152 // |buffer_handle|. |info| should be non-null and point to a buffer of size | 158 // |buffer_handle| (which must have the |MOJO_HANDLE_RIGHT_GET_OPTIONS| right). |
| 153 // |info_num_bytes|; |info_num_bytes| should be at least 16 (the size of the | 159 // |info| should be non-null and point to a buffer of size |info_num_bytes|; |
| 154 // first, and currently only, version of |struct MojoBufferInformation|). | 160 // |info_num_bytes| should be at least 16 (the size of the first, and currently |
| 161 // only, version of |struct MojoBufferInformation|). |
| 155 // | 162 // |
| 156 // On success, |*info| will be filled with information about the given buffer. | 163 // On success, |*info| will be filled with information about the given buffer. |
| 157 // Note that if additional (larger) versions of |struct MojoBufferInformation| | 164 // Note that if additional (larger) versions of |struct MojoBufferInformation| |
| 158 // are defined, the largest version permitted by |info_num_bytes| that is | 165 // are defined, the largest version permitted by |info_num_bytes| that is |
| 159 // supported by the implementation will be filled. Callers expecting more than | 166 // supported by the implementation will be filled. Callers expecting more than |
| 160 // the first 16-byte version must check the resulting |info->struct_size|. | 167 // the first 16-byte version must check the resulting |info->struct_size|. |
| 161 // | 168 // |
| 162 // Returns: | 169 // Returns: |
| 163 // |MOJO_RESULT_OK| on success. | 170 // |MOJO_RESULT_OK| on success. |
| 164 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 171 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 165 // |buffer_handle| is not a valid buffer handle, |*info| is null, or | 172 // |buffer_handle| is not a valid buffer handle, |*info| is null, or |
| 166 // |info_num_bytes| is too small). | 173 // |info_num_bytes| is too small). |
| 174 // |MOJO_RESULT_PERMISSION_DENIED| if |buffer_handle| does not have the |
| 175 // |MOJO_HANDLE_RIGHT_GET_OPTIONS| right. |
| 167 // |MOJO_RESULT_BUSY| if |buffer_handle| is currently in use in some | 176 // |MOJO_RESULT_BUSY| if |buffer_handle| is currently in use in some |
| 168 // transaction (that, e.g., may result in it being invalidated, such as | 177 // transaction (that, e.g., may result in it being invalidated, such as |
| 169 // being sent in a message). | 178 // being sent in a message). |
| 170 MojoResult MojoGetBufferInformation(MojoHandle buffer_handle, // In. | 179 MojoResult MojoGetBufferInformation(MojoHandle buffer_handle, // In. |
| 171 struct MojoBufferInformation* info, // Out. | 180 struct MojoBufferInformation* info, // Out. |
| 172 uint32_t info_num_bytes); // In. | 181 uint32_t info_num_bytes); // In. |
| 173 | 182 |
| 174 // |MojoMapBuffer()|: Maps the part (at offset |offset| of length |num_bytes|) | 183 // |MojoMapBuffer()|: Maps the part (at offset |offset| of length |num_bytes|) |
| 175 // of the buffer given by |buffer_handle| into memory, with options specified by | 184 // of the buffer given by |buffer_handle| (which must have both the |
| 176 // |flags|. |offset + num_bytes| must be less than or equal to the size of the | 185 // |MOJO_HANDLE_RIGHT_MAP_READABLE| and |MOJO_HANDLE_RIGHT_MAP_WRITABLE| rights) |
| 177 // buffer. On success, |*buffer| points to memory with the requested part of the | 186 // into memory, with options specified by |flags|. |offset + num_bytes| must be |
| 178 // buffer. (On failure, it is not modified.) | 187 // less than or equal to the size of the buffer. On success, |*buffer| points to |
| 188 // memory with the requested part of the buffer. (On failure, it is not |
| 189 // modified.) |
| 179 // | 190 // |
| 180 // A single buffer handle may have multiple active mappings (possibly depending | 191 // A single buffer handle may have multiple active mappings (possibly depending |
| 181 // on the buffer type). The permissions (e.g., writable or executable) of the | 192 // on the buffer type). The permissions (e.g., writable or executable) of the |
| 182 // returned memory may depend on the properties of the buffer and properties | 193 // returned memory may depend on the properties of the buffer and properties |
| 183 // attached to the buffer handle as well as |flags|. | 194 // attached to the buffer handle as well as |flags|. |
| 184 // | 195 // |
| 185 // Note: Though data outside the specified range may apparently be | 196 // Note: Though data outside the specified range may apparently be |
| 186 // available/visible/readable/writable, trying to use those extra bytes is | 197 // available/visible/readable/writable, trying to use those extra bytes is |
| 187 // undefined behavior. | 198 // undefined behavior. |
| 188 // | 199 // |
| 189 // Returns: | 200 // Returns: |
| 190 // |MOJO_RESULT_OK| on success. | 201 // |MOJO_RESULT_OK| on success. |
| 191 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 202 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 192 // |buffer_handle| is not a valid buffer handle or the range specified by | 203 // |buffer_handle| is not a valid buffer handle or the range specified by |
| 193 // |offset| and |num_bytes| is not valid). | 204 // |offset| and |num_bytes| is not valid). |
| 205 // |MOJO_RESULT_PERMISSION_DENIED| if |buffer_handle| does not have both the |
| 206 // |MOJO_HANDLE_RIGHT_MAP_READABLE| and |MOJO_HANDLE_RIGHT_MAP_WRITABLE| |
| 207 // rights. |
| 194 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the mapping operation itself failed | 208 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the mapping operation itself failed |
| 195 // (e.g., due to not having appropriate address space available). | 209 // (e.g., due to not having appropriate address space available). |
| 196 // |MOJO_RESULT_BUSY| if |buffer_handle| is currently in use in some | 210 // |MOJO_RESULT_BUSY| if |buffer_handle| is currently in use in some |
| 197 // transaction (that, e.g., may result in it being invalidated, such as | 211 // transaction (that, e.g., may result in it being invalidated, such as |
| 198 // being sent in a message). | 212 // being sent in a message). |
| 199 MojoResult MojoMapBuffer(MojoHandle buffer_handle, // In. | 213 MojoResult MojoMapBuffer(MojoHandle buffer_handle, // In. |
| 200 uint64_t offset, // In. | 214 uint64_t offset, // In. |
| 201 uint64_t num_bytes, // In. | 215 uint64_t num_bytes, // In. |
| 202 void** buffer, // Out. | 216 void** buffer, // Out. |
| 203 MojoMapBufferFlags flags); // In. | 217 MojoMapBufferFlags flags); // In. |
| 204 | 218 |
| 205 // |MojoUnmapBuffer()|: Unmaps a buffer pointer that was mapped by | 219 // |MojoUnmapBuffer()|: Unmaps a buffer pointer that was mapped by |
| 206 // |MojoMapBuffer()|. |buffer| must have been the result of |MojoMapBuffer()| | 220 // |MojoMapBuffer()|. |buffer| must have been the result of |MojoMapBuffer()| |
| 207 // (not some other pointer inside the mapped memory), and the entire mapping | 221 // (not some other pointer inside the mapped memory), and the entire mapping |
| 208 // will be removed (partial unmapping is not supported). A mapping may only be | 222 // will be removed (partial unmapping is not supported). A mapping may only be |
| 209 // unmapped once. | 223 // unmapped once. |
| 210 // | 224 // |
| 211 // Returns: | 225 // Returns: |
| 212 // |MOJO_RESULT_OK| on success. | 226 // |MOJO_RESULT_OK| on success. |
| 213 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the | 227 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the |
| 214 // result of |MojoMapBuffer()| or has already been unmapped). | 228 // result of |MojoMapBuffer()| or has already been unmapped). |
| 215 MojoResult MojoUnmapBuffer(void* buffer); // In. | 229 MojoResult MojoUnmapBuffer(void* buffer); // In. |
| 216 | 230 |
| 217 MOJO_END_EXTERN_C | 231 MOJO_END_EXTERN_C |
| 218 | 232 |
| 219 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ | 233 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ |
| OLD | NEW |