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 17 matching lines...) Expand all Loading... |
28 // executable or not? | 28 // executable or not? |
29 // TODO(vtl): Also a flag for discardable (ashmem-style) buffers. | 29 // TODO(vtl): Also a flag for discardable (ashmem-style) buffers. |
30 | 30 |
31 typedef uint32_t MojoCreateSharedBufferOptionsFlags; | 31 typedef uint32_t MojoCreateSharedBufferOptionsFlags; |
32 | 32 |
33 #ifdef __cplusplus | 33 #ifdef __cplusplus |
34 const MojoCreateSharedBufferOptionsFlags | 34 const MojoCreateSharedBufferOptionsFlags |
35 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE = 0; | 35 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE = 0; |
36 #else | 36 #else |
37 #define MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE \ | 37 #define MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE \ |
38 ((MojoCreateSharedBufferOptionsFlags) 0) | 38 ((MojoCreateSharedBufferOptionsFlags)0) |
39 #endif | 39 #endif |
40 | 40 |
41 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); | 41 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); |
42 struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { | 42 struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { |
43 uint32_t struct_size; | 43 uint32_t struct_size; |
44 MojoCreateSharedBufferOptionsFlags flags; | 44 MojoCreateSharedBufferOptionsFlags flags; |
45 }; | 45 }; |
46 MOJO_COMPILE_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, | 46 MOJO_COMPILE_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, |
47 MojoCreateSharedBufferOptions_has_wrong_size); | 47 MojoCreateSharedBufferOptions_has_wrong_size); |
48 | 48 |
49 // |MojoDuplicateBufferHandleOptions|: Used to specify parameters in duplicating | 49 // |MojoDuplicateBufferHandleOptions|: Used to specify parameters in duplicating |
50 // access to a shared buffer to |MojoDuplicateBufferHandle()|. | 50 // access to a shared buffer to |MojoDuplicateBufferHandle()|. |
51 // |uint32_t struct_size|: Set to the size of the | 51 // |uint32_t struct_size|: Set to the size of the |
52 // |MojoDuplicateBufferHandleOptions| struct. (Used to allow for future | 52 // |MojoDuplicateBufferHandleOptions| struct. (Used to allow for future |
53 // extensions.) | 53 // extensions.) |
54 // |MojoDuplicateBufferHandleOptionsFlags flags|: Reserved for future use. | 54 // |MojoDuplicateBufferHandleOptionsFlags flags|: Reserved for future use. |
55 // |MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE|: No flags; default | 55 // |MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE|: No flags; default |
56 // mode. | 56 // mode. |
57 // | 57 // |
58 // TODO(vtl): Add flags to remove writability (and executability)? Also, COW? | 58 // TODO(vtl): Add flags to remove writability (and executability)? Also, COW? |
59 | 59 |
60 typedef uint32_t MojoDuplicateBufferHandleOptionsFlags; | 60 typedef uint32_t MojoDuplicateBufferHandleOptionsFlags; |
61 | 61 |
62 #ifdef __cplusplus | 62 #ifdef __cplusplus |
63 const MojoDuplicateBufferHandleOptionsFlags | 63 const MojoDuplicateBufferHandleOptionsFlags |
64 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE = 0; | 64 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE = 0; |
65 #else | 65 #else |
66 #define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \ | 66 #define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \ |
67 ((MojoDuplicateBufferHandleOptionsFlags) 0) | 67 ((MojoDuplicateBufferHandleOptionsFlags)0) |
68 #endif | 68 #endif |
69 | 69 |
70 struct MojoDuplicateBufferHandleOptions { | 70 struct MojoDuplicateBufferHandleOptions { |
71 uint32_t struct_size; | 71 uint32_t struct_size; |
72 MojoDuplicateBufferHandleOptionsFlags flags; | 72 MojoDuplicateBufferHandleOptionsFlags flags; |
73 }; | 73 }; |
74 MOJO_COMPILE_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8, | 74 MOJO_COMPILE_ASSERT(sizeof(MojoDuplicateBufferHandleOptions) == 8, |
75 MojoDuplicateBufferHandleOptions_has_wrong_size); | 75 MojoDuplicateBufferHandleOptions_has_wrong_size); |
76 | 76 |
77 // |MojoMapBufferFlags|: Used to specify different modes to |MojoMapBuffer()|. | 77 // |MojoMapBufferFlags|: Used to specify different modes to |MojoMapBuffer()|. |
78 // |MOJO_MAP_BUFFER_FLAG_NONE| - No flags; default mode. | 78 // |MOJO_MAP_BUFFER_FLAG_NONE| - No flags; default mode. |
79 | 79 |
80 typedef uint32_t MojoMapBufferFlags; | 80 typedef uint32_t MojoMapBufferFlags; |
81 | 81 |
82 #ifdef __cplusplus | 82 #ifdef __cplusplus |
83 const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0; | 83 const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0; |
84 #else | 84 #else |
85 #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags) 0) | 85 #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags)0) |
86 #endif | 86 #endif |
87 | 87 |
88 #ifdef __cplusplus | 88 #ifdef __cplusplus |
89 extern "C" { | 89 extern "C" { |
90 #endif | 90 #endif |
91 | 91 |
92 // Note: See the comment in functions.h about the meaning of the "optional" | 92 // Note: See the comment in functions.h about the meaning of the "optional" |
93 // label for pointer parameters. | 93 // label for pointer parameters. |
94 | 94 |
95 // Creates a buffer of size |num_bytes| bytes that can be shared between | 95 // Creates a buffer of size |num_bytes| bytes that can be shared between |
(...skipping 13 matching lines...) Expand all Loading... |
109 // Returns: | 109 // Returns: |
110 // |MOJO_RESULT_OK| on success. | 110 // |MOJO_RESULT_OK| on success. |
111 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 111 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
112 // |*options| is invalid). | 112 // |*options| is invalid). |
113 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | 113 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has |
114 // been reached (e.g., if the requested size was too large, or if the | 114 // been reached (e.g., if the requested size was too large, or if the |
115 // maximum number of handles was exceeded). | 115 // maximum number of handles was exceeded). |
116 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 116 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
117 MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer( | 117 MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer( |
118 const struct MojoCreateSharedBufferOptions* options, // Optional. | 118 const struct MojoCreateSharedBufferOptions* options, // Optional. |
119 uint64_t num_bytes, // In. | 119 uint64_t num_bytes, // In. |
120 MojoHandle* shared_buffer_handle); // Out. | 120 MojoHandle* shared_buffer_handle); // Out. |
121 | 121 |
122 // Duplicates the handle |buffer_handle| to a buffer. This creates another | 122 // Duplicates the handle |buffer_handle| to a buffer. This creates another |
123 // handle (returned in |*new_buffer_handle| on success), which can then be sent | 123 // handle (returned in |*new_buffer_handle| on success), which can then be sent |
124 // to another application over a message pipe, while retaining access to the | 124 // to another application over a message pipe, while retaining access to the |
125 // |buffer_handle| (and any mappings that it may have). | 125 // |buffer_handle| (and any mappings that it may have). |
126 // | 126 // |
127 // |options| may be set to null to duplicate the buffer handle with the default | 127 // |options| may be set to null to duplicate the buffer handle with the default |
128 // options. | 128 // options. |
129 // | 129 // |
130 // On success, |*shared_buffer_handle| will be set to the handle for the new | 130 // On success, |*shared_buffer_handle| will be set to the handle for the new |
131 // buffer handle. (On failure, it is not modified.) | 131 // buffer handle. (On failure, it is not modified.) |
132 // | 132 // |
133 // Returns: | 133 // Returns: |
134 // |MOJO_RESULT_OK| on success. | 134 // |MOJO_RESULT_OK| on success. |
135 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 135 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
136 // |buffer_handle| is not a valid buffer handle or |*options| is invalid). | 136 // |buffer_handle| is not a valid buffer handle or |*options| is invalid). |
137 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 137 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
138 MOJO_SYSTEM_EXPORT MojoResult MojoDuplicateBufferHandle( | 138 MOJO_SYSTEM_EXPORT MojoResult MojoDuplicateBufferHandle( |
139 MojoHandle buffer_handle, | 139 MojoHandle buffer_handle, |
140 const struct MojoDuplicateBufferHandleOptions* options, // Optional. | 140 const struct MojoDuplicateBufferHandleOptions* options, // Optional. |
141 MojoHandle* new_buffer_handle); // Out. | 141 MojoHandle* new_buffer_handle); // Out. |
142 | 142 |
143 // Maps the part (at offset |offset| of length |num_bytes|) of the buffer given | 143 // Maps the part (at offset |offset| of length |num_bytes|) of the buffer given |
144 // by |buffer_handle| into memory, with options specified by |flags|. |offset + | 144 // by |buffer_handle| into memory, with options specified by |flags|. |offset + |
145 // num_bytes| must be less than or equal to the size of the buffer. On success, | 145 // num_bytes| must be less than or equal to the size of the buffer. On success, |
146 // |*buffer| points to memory with the requested part of the buffer. (On | 146 // |*buffer| points to memory with the requested part of the buffer. (On |
147 // failure, it is not modified.) | 147 // failure, it is not modified.) |
148 // | 148 // |
149 // A single buffer handle may have multiple active mappings (possibly depending | 149 // A single buffer handle may have multiple active mappings (possibly depending |
150 // on the buffer type). The permissions (e.g., writable or executable) of the | 150 // on the buffer type). The permissions (e.g., writable or executable) of the |
151 // returned memory may depend on the properties of the buffer and properties | 151 // returned memory may depend on the properties of the buffer and properties |
(...skipping 25 matching lines...) Expand all Loading... |
177 // |MOJO_RESULT_OK| on success. | 177 // |MOJO_RESULT_OK| on success. |
178 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the | 178 // |MOJO_RESULT_INVALID_ARGUMENT| if |buffer| is invalid (e.g., is not the |
179 // result of |MojoMapBuffer()| or has already been unmapped). | 179 // result of |MojoMapBuffer()| or has already been unmapped). |
180 MOJO_SYSTEM_EXPORT MojoResult MojoUnmapBuffer(void* buffer); // In. | 180 MOJO_SYSTEM_EXPORT MojoResult MojoUnmapBuffer(void* buffer); // In. |
181 | 181 |
182 #ifdef __cplusplus | 182 #ifdef __cplusplus |
183 } // extern "C" | 183 } // extern "C" |
184 #endif | 184 #endif |
185 | 185 |
186 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ | 186 #endif // MOJO_PUBLIC_C_SYSTEM_BUFFER_H_ |
OLD | NEW |