Chromium Code Reviews| 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 { |
|
viettrungluu
2016/03/01 20:36:20
This is an ABI-breaking change, but luckily, no on
| |
| 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 the size of |struct MojoBufferInformation| (if/when the | |
| 152 // definition of this struct is extended, sizes of previous definitions will | |
| 153 // still be accepted and |*info| filled accordingly). | |
| 154 // | |
| 155 // On success, |*info| will be filled with information about the given buffer. | |
| 156 // | |
| 157 // Returns: | |
| 158 // |MOJO_RESULT_OK| on success. | |
| 159 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | |
| 160 // |buffer_handle| is not a valid buffer handle, |*info| is null, or | |
| 161 // |info_num_bytes| is too small). | |
|
jamesr
2016/03/07 19:26:36
hm, buffer too small is a MOJO_RESULT_RESOURCE_EXH
viettrungluu
2016/03/07 20:44:22
See the parenthetical comment in the first paragra
jamesr
2016/03/07 21:42:35
Do we have any definition for what "old valid size
| |
| 162 MojoResult MojoGetBufferInformation(MojoHandle buffer_handle, | |
| 163 struct MojoBufferInformation* info, // Out. | |
| 164 uint32_t info_num_bytes); // In. | |
|
jamesr
2016/03/07 19:26:36
inparams before outparams?
viettrungluu
2016/03/07 20:44:23
I'm following existing (arguably-bad[*]) precedent
jamesr
2016/03/07 21:42:35
Read's params are in/out except for flags which co
| |
| 165 | |
| 128 // Maps the part (at offset |offset| of length |num_bytes|) of the buffer given | 166 // 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 + | 167 // 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, | 168 // 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 | 169 // |*buffer| points to memory with the requested part of the buffer. (On |
| 132 // failure, it is not modified.) | 170 // failure, it is not modified.) |
| 133 // | 171 // |
| 134 // A single buffer handle may have multiple active mappings (possibly depending | 172 // 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 | 173 // 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 | 174 // returned memory may depend on the properties of the buffer and properties |
| 137 // attached to the buffer handle as well as |flags|. | 175 // attached to the buffer handle as well as |flags|. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 162 // |MOJO_RESULT_OK| on success. | 200 // |MOJO_RESULT_OK| on success. |
| 163 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the | 201 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the |
| 164 // result of |MojoMapBuffer()| or has already been unmapped). | 202 // result of |MojoMapBuffer()| or has already been unmapped). |
| 165 MojoResult MojoUnmapBuffer(void* buffer); // In. | 203 MojoResult MojoUnmapBuffer(void* buffer); // In. |
| 166 | 204 |
| 167 #ifdef __cplusplus | 205 #ifdef __cplusplus |
| 168 } // extern "C" | 206 } // extern "C" |
| 169 #endif | 207 #endif |
| 170 | 208 |
| 171 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ | 209 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ |
| OLD | NEW |