Fixes for Android GN build input/outputs
[chromium-blink-merge.git] / third_party / mojo / src / nacl_bindings / mojo_irt.c
blob3595f0b6aed3f5de4b05d452032859ef084da2d2
1 // Copyright 2015 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.
5 // WARNING this file was generated by generate_nacl_bindings.py
6 // Do not edit by hand.
8 #include <stdio.h>
9 #include <string.h>
11 #include "mojo/public/c/system/core.h"
12 #include "mojo/public/platform/nacl/mojo_irt.h"
13 #include "native_client/src/public/chrome_main.h"
14 #include "native_client/src/public/imc_syscalls.h"
15 #include "native_client/src/public/imc_types.h"
16 #include "native_client/src/public/irt_core.h"
18 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3)
20 static void DoMojoCall(uint32_t params[], nacl_abi_size_t num_params) {
21 struct NaClAbiNaClImcMsgIoVec iov[1] = {
22 {params, num_params}
24 struct NaClAbiNaClImcMsgHdr msgh = {iov, 1, NULL, 0};
25 // Note: return value unchecked. We're relying on the result parameter being
26 // unmodified - if the syscall fails, the Mojo function will return whatever
27 // the result parameter was initialized to before this function was called.
28 imc_sendmsg(NACL_MOJO_DESC, &msgh, 0);
31 static MojoResult irt_MojoCreateSharedBuffer(
32 const struct MojoCreateSharedBufferOptions* options,
33 uint64_t num_bytes,
34 MojoHandle* shared_buffer_handle) {
35 uint32_t params[5];
36 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
37 params[0] = 0;
38 params[1] = (uint32_t)(options);
39 params[2] = (uint32_t)(&num_bytes);
40 params[3] = (uint32_t)(shared_buffer_handle);
41 params[4] = (uint32_t)(&result);
42 DoMojoCall(params, sizeof(params));
43 return result;
46 static MojoResult irt_MojoDuplicateBufferHandle(
47 MojoHandle buffer_handle,
48 const struct MojoDuplicateBufferHandleOptions* options,
49 MojoHandle* new_buffer_handle) {
50 uint32_t params[5];
51 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
52 params[0] = 1;
53 params[1] = (uint32_t)(&buffer_handle);
54 params[2] = (uint32_t)(options);
55 params[3] = (uint32_t)(new_buffer_handle);
56 params[4] = (uint32_t)(&result);
57 DoMojoCall(params, sizeof(params));
58 return result;
61 static MojoResult irt_MojoMapBuffer(
62 MojoHandle buffer_handle,
63 uint64_t offset,
64 uint64_t num_bytes,
65 void** buffer,
66 MojoMapBufferFlags flags) {
67 uint32_t params[7];
68 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
69 params[0] = 2;
70 params[1] = (uint32_t)(&buffer_handle);
71 params[2] = (uint32_t)(&offset);
72 params[3] = (uint32_t)(&num_bytes);
73 params[4] = (uint32_t)(buffer);
74 params[5] = (uint32_t)(&flags);
75 params[6] = (uint32_t)(&result);
76 DoMojoCall(params, sizeof(params));
77 return result;
80 static MojoResult irt_MojoUnmapBuffer(void* buffer) {
81 uint32_t params[3];
82 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
83 params[0] = 3;
84 params[1] = (uint32_t)(&buffer);
85 params[2] = (uint32_t)(&result);
86 DoMojoCall(params, sizeof(params));
87 return result;
90 static MojoResult irt_MojoCreateDataPipe(
91 const struct MojoCreateDataPipeOptions* options,
92 MojoHandle* data_pipe_producer_handle,
93 MojoHandle* data_pipe_consumer_handle) {
94 uint32_t params[5];
95 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
96 params[0] = 4;
97 params[1] = (uint32_t)(options);
98 params[2] = (uint32_t)(data_pipe_producer_handle);
99 params[3] = (uint32_t)(data_pipe_consumer_handle);
100 params[4] = (uint32_t)(&result);
101 DoMojoCall(params, sizeof(params));
102 return result;
105 static MojoResult irt_MojoWriteData(
106 MojoHandle data_pipe_producer_handle,
107 const void* elements,
108 uint32_t* num_bytes,
109 MojoWriteDataFlags flags) {
110 uint32_t params[6];
111 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
112 params[0] = 5;
113 params[1] = (uint32_t)(&data_pipe_producer_handle);
114 params[2] = (uint32_t)(elements);
115 params[3] = (uint32_t)(num_bytes);
116 params[4] = (uint32_t)(&flags);
117 params[5] = (uint32_t)(&result);
118 DoMojoCall(params, sizeof(params));
119 return result;
122 static MojoResult irt_MojoBeginWriteData(
123 MojoHandle data_pipe_producer_handle,
124 void** buffer,
125 uint32_t* buffer_num_bytes,
126 MojoWriteDataFlags flags) {
127 uint32_t params[6];
128 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
129 params[0] = 6;
130 params[1] = (uint32_t)(&data_pipe_producer_handle);
131 params[2] = (uint32_t)(buffer);
132 params[3] = (uint32_t)(buffer_num_bytes);
133 params[4] = (uint32_t)(&flags);
134 params[5] = (uint32_t)(&result);
135 DoMojoCall(params, sizeof(params));
136 return result;
139 static MojoResult irt_MojoEndWriteData(
140 MojoHandle data_pipe_producer_handle,
141 uint32_t num_bytes_written) {
142 uint32_t params[4];
143 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
144 params[0] = 7;
145 params[1] = (uint32_t)(&data_pipe_producer_handle);
146 params[2] = (uint32_t)(&num_bytes_written);
147 params[3] = (uint32_t)(&result);
148 DoMojoCall(params, sizeof(params));
149 return result;
152 static MojoResult irt_MojoReadData(
153 MojoHandle data_pipe_consumer_handle,
154 void* elements,
155 uint32_t* num_bytes,
156 MojoReadDataFlags flags) {
157 uint32_t params[6];
158 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
159 params[0] = 8;
160 params[1] = (uint32_t)(&data_pipe_consumer_handle);
161 params[2] = (uint32_t)(elements);
162 params[3] = (uint32_t)(num_bytes);
163 params[4] = (uint32_t)(&flags);
164 params[5] = (uint32_t)(&result);
165 DoMojoCall(params, sizeof(params));
166 return result;
169 static MojoResult irt_MojoBeginReadData(
170 MojoHandle data_pipe_consumer_handle,
171 const void** buffer,
172 uint32_t* buffer_num_bytes,
173 MojoReadDataFlags flags) {
174 uint32_t params[6];
175 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
176 params[0] = 9;
177 params[1] = (uint32_t)(&data_pipe_consumer_handle);
178 params[2] = (uint32_t)(buffer);
179 params[3] = (uint32_t)(buffer_num_bytes);
180 params[4] = (uint32_t)(&flags);
181 params[5] = (uint32_t)(&result);
182 DoMojoCall(params, sizeof(params));
183 return result;
186 static MojoResult irt_MojoEndReadData(
187 MojoHandle data_pipe_consumer_handle,
188 uint32_t num_bytes_read) {
189 uint32_t params[4];
190 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
191 params[0] = 10;
192 params[1] = (uint32_t)(&data_pipe_consumer_handle);
193 params[2] = (uint32_t)(&num_bytes_read);
194 params[3] = (uint32_t)(&result);
195 DoMojoCall(params, sizeof(params));
196 return result;
199 static MojoTimeTicks irt_MojoGetTimeTicksNow() {
200 uint32_t params[2];
201 MojoTimeTicks result = 0;
202 params[0] = 11;
203 params[1] = (uint32_t)(&result);
204 DoMojoCall(params, sizeof(params));
205 return result;
208 static MojoResult irt_MojoClose(MojoHandle handle) {
209 uint32_t params[3];
210 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
211 params[0] = 12;
212 params[1] = (uint32_t)(&handle);
213 params[2] = (uint32_t)(&result);
214 DoMojoCall(params, sizeof(params));
215 return result;
218 static MojoResult irt_MojoWait(
219 MojoHandle handle,
220 MojoHandleSignals signals,
221 MojoDeadline deadline,
222 struct MojoHandleSignalsState* signals_state) {
223 uint32_t params[6];
224 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
225 params[0] = 13;
226 params[1] = (uint32_t)(&handle);
227 params[2] = (uint32_t)(&signals);
228 params[3] = (uint32_t)(&deadline);
229 params[4] = (uint32_t)(signals_state);
230 params[5] = (uint32_t)(&result);
231 DoMojoCall(params, sizeof(params));
232 return result;
235 static MojoResult irt_MojoWaitMany(
236 const MojoHandle* handles,
237 const MojoHandleSignals* signals,
238 uint32_t num_handles,
239 MojoDeadline deadline,
240 uint32_t* result_index,
241 struct MojoHandleSignalsState* signals_states) {
242 uint32_t params[8];
243 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
244 params[0] = 14;
245 params[1] = (uint32_t)(handles);
246 params[2] = (uint32_t)(signals);
247 params[3] = (uint32_t)(&num_handles);
248 params[4] = (uint32_t)(&deadline);
249 params[5] = (uint32_t)(result_index);
250 params[6] = (uint32_t)(signals_states);
251 params[7] = (uint32_t)(&result);
252 DoMojoCall(params, sizeof(params));
253 return result;
256 static MojoResult irt_MojoCreateMessagePipe(
257 const struct MojoCreateMessagePipeOptions* options,
258 MojoHandle* message_pipe_handle0,
259 MojoHandle* message_pipe_handle1) {
260 uint32_t params[5];
261 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
262 params[0] = 15;
263 params[1] = (uint32_t)(options);
264 params[2] = (uint32_t)(message_pipe_handle0);
265 params[3] = (uint32_t)(message_pipe_handle1);
266 params[4] = (uint32_t)(&result);
267 DoMojoCall(params, sizeof(params));
268 return result;
271 static MojoResult irt_MojoWriteMessage(
272 MojoHandle message_pipe_handle,
273 const void* bytes,
274 uint32_t num_bytes,
275 const MojoHandle* handles,
276 uint32_t num_handles,
277 MojoWriteMessageFlags flags) {
278 uint32_t params[8];
279 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
280 params[0] = 16;
281 params[1] = (uint32_t)(&message_pipe_handle);
282 params[2] = (uint32_t)(bytes);
283 params[3] = (uint32_t)(&num_bytes);
284 params[4] = (uint32_t)(handles);
285 params[5] = (uint32_t)(&num_handles);
286 params[6] = (uint32_t)(&flags);
287 params[7] = (uint32_t)(&result);
288 DoMojoCall(params, sizeof(params));
289 return result;
292 static MojoResult irt_MojoReadMessage(
293 MojoHandle message_pipe_handle,
294 void* bytes,
295 uint32_t* num_bytes,
296 MojoHandle* handles,
297 uint32_t* num_handles,
298 MojoReadMessageFlags flags) {
299 uint32_t params[8];
300 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
301 params[0] = 17;
302 params[1] = (uint32_t)(&message_pipe_handle);
303 params[2] = (uint32_t)(bytes);
304 params[3] = (uint32_t)(num_bytes);
305 params[4] = (uint32_t)(handles);
306 params[5] = (uint32_t)(num_handles);
307 params[6] = (uint32_t)(&flags);
308 params[7] = (uint32_t)(&result);
309 DoMojoCall(params, sizeof(params));
310 return result;
313 static MojoResult irt__MojoGetInitialHandle(MojoHandle* handle) {
314 uint32_t params[3];
315 MojoResult result = MOJO_RESULT_INVALID_ARGUMENT;
316 params[0] = 18;
317 params[1] = (uint32_t)(handle);
318 params[2] = (uint32_t)(&result);
319 DoMojoCall(params, sizeof(params));
320 return result;
323 struct nacl_irt_mojo kIrtMojo = {
324 &irt_MojoCreateSharedBuffer,
325 &irt_MojoDuplicateBufferHandle,
326 &irt_MojoMapBuffer,
327 &irt_MojoUnmapBuffer,
328 &irt_MojoCreateDataPipe,
329 &irt_MojoWriteData,
330 &irt_MojoBeginWriteData,
331 &irt_MojoEndWriteData,
332 &irt_MojoReadData,
333 &irt_MojoBeginReadData,
334 &irt_MojoEndReadData,
335 &irt_MojoGetTimeTicksNow,
336 &irt_MojoClose,
337 &irt_MojoWait,
338 &irt_MojoWaitMany,
339 &irt_MojoCreateMessagePipe,
340 &irt_MojoWriteMessage,
341 &irt_MojoReadMessage,
342 &irt__MojoGetInitialHandle,
346 size_t mojo_irt_query(const char* interface_ident,
347 void* table,
348 size_t tablesize) {
349 static const size_t size = sizeof(kIrtMojo);
350 if (0 == strcmp(interface_ident, NACL_IRT_MOJO_v0_1)) {
351 if (size <= tablesize) {
352 memcpy(table, &kIrtMojo, size);
353 return size;
356 return 0;