Fixes for Android GN build input/outputs
[chromium-blink-merge.git] / third_party / mojo / src / nacl_bindings / mojo_syscall.cc
blob13397539dca29dcf183c170d946862fff0c6ecf5
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
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 "nacl_bindings/mojo_syscall.h"
10 #include <stdio.h>
12 #include "mojo/public/c/system/core.h"
13 #include "mojo/public/platform/native/system_impl_private.h"
14 #include "nacl_bindings/mojo_syscall_internal.h"
15 #include "native_client/src/public/chrome_main.h"
16 #include "native_client/src/public/nacl_app.h"
17 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
19 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID;
20 MojoSystemImpl g_mojo_system = nullptr;
22 namespace {
24 MojoResult _MojoGetInitialHandle(MojoHandle* handle) {
25 *handle = g_mojo_handle;
26 return MOJO_RESULT_OK;
29 void MojoDescDestroy(void* handle) {
32 ssize_t MojoDescSendMsg(void* handle,
33 const struct NaClImcTypedMsgHdr* msg,
34 int flags) {
35 struct NaClApp* nap = static_cast<struct NaClApp*>(handle);
37 if (msg->iov_length != 1 || msg->ndesc_length != 0) {
38 return -1;
41 uint32_t volatile* params = static_cast<uint32_t volatile*>(msg->iov[0].base);
42 size_t num_params = msg->iov[0].length / sizeof(*params);
44 if (num_params < 1) {
45 return -1;
48 uint32_t msg_type = params[0];
49 switch (msg_type) {
50 case 0: {
51 if (num_params != 5) {
52 return -1;
54 const struct MojoCreateSharedBufferOptions* options;
55 uint64_t num_bytes_value;
56 MojoHandle volatile* shared_buffer_handle_ptr;
57 MojoHandle shared_buffer_handle_value;
58 MojoResult volatile* result_ptr;
59 MojoResult result_value;
61 ScopedCopyLock copy_lock(nap);
62 if (!ConvertExtensibleStructInput(nap, params[1], true, &options)) {
63 return -1;
65 if (!ConvertScalarInput(nap, params[2], &num_bytes_value)) {
66 return -1;
68 if (!ConvertScalarInOut(nap, params[3], false,
69 &shared_buffer_handle_value,
70 &shared_buffer_handle_ptr)) {
71 return -1;
73 if (!ConvertScalarOutput(nap, params[4], false, &result_ptr)) {
74 return -1;
78 result_value = MojoSystemImplCreateSharedBuffer(
79 g_mojo_system, options, num_bytes_value, &shared_buffer_handle_value);
82 ScopedCopyLock copy_lock(nap);
83 *shared_buffer_handle_ptr = shared_buffer_handle_value;
84 *result_ptr = result_value;
87 return 0;
89 case 1: {
90 if (num_params != 5) {
91 return -1;
93 MojoHandle buffer_handle_value;
94 const struct MojoDuplicateBufferHandleOptions* options;
95 MojoHandle volatile* new_buffer_handle_ptr;
96 MojoHandle new_buffer_handle_value;
97 MojoResult volatile* result_ptr;
98 MojoResult result_value;
100 ScopedCopyLock copy_lock(nap);
101 if (!ConvertScalarInput(nap, params[1], &buffer_handle_value)) {
102 return -1;
104 if (!ConvertExtensibleStructInput(nap, params[2], true, &options)) {
105 return -1;
107 if (!ConvertScalarInOut(nap, params[3], false, &new_buffer_handle_value,
108 &new_buffer_handle_ptr)) {
109 return -1;
111 if (!ConvertScalarOutput(nap, params[4], false, &result_ptr)) {
112 return -1;
116 result_value = MojoSystemImplDuplicateBufferHandle(
117 g_mojo_system, buffer_handle_value, options,
118 &new_buffer_handle_value);
121 ScopedCopyLock copy_lock(nap);
122 *new_buffer_handle_ptr = new_buffer_handle_value;
123 *result_ptr = result_value;
126 return 0;
128 case 2:
129 fprintf(stderr, "MojoMapBuffer not implemented\n");
130 return -1;
131 case 3:
132 fprintf(stderr, "MojoUnmapBuffer not implemented\n");
133 return -1;
134 case 4: {
135 if (num_params != 5) {
136 return -1;
138 const struct MojoCreateDataPipeOptions* options;
139 MojoHandle volatile* data_pipe_producer_handle_ptr;
140 MojoHandle data_pipe_producer_handle_value;
141 MojoHandle volatile* data_pipe_consumer_handle_ptr;
142 MojoHandle data_pipe_consumer_handle_value;
143 MojoResult volatile* result_ptr;
144 MojoResult result_value;
146 ScopedCopyLock copy_lock(nap);
147 if (!ConvertExtensibleStructInput(nap, params[1], true, &options)) {
148 return -1;
150 if (!ConvertScalarInOut(nap, params[2], false,
151 &data_pipe_producer_handle_value,
152 &data_pipe_producer_handle_ptr)) {
153 return -1;
155 if (!ConvertScalarInOut(nap, params[3], false,
156 &data_pipe_consumer_handle_value,
157 &data_pipe_consumer_handle_ptr)) {
158 return -1;
160 if (!ConvertScalarOutput(nap, params[4], false, &result_ptr)) {
161 return -1;
165 result_value = MojoSystemImplCreateDataPipe(
166 g_mojo_system, options, &data_pipe_producer_handle_value,
167 &data_pipe_consumer_handle_value);
170 ScopedCopyLock copy_lock(nap);
171 *data_pipe_producer_handle_ptr = data_pipe_producer_handle_value;
172 *data_pipe_consumer_handle_ptr = data_pipe_consumer_handle_value;
173 *result_ptr = result_value;
176 return 0;
178 case 5: {
179 if (num_params != 6) {
180 return -1;
182 MojoHandle data_pipe_producer_handle_value;
183 const void* elements;
184 uint32_t volatile* num_bytes_ptr;
185 uint32_t num_bytes_value;
186 MojoWriteDataFlags flags_value;
187 MojoResult volatile* result_ptr;
188 MojoResult result_value;
190 ScopedCopyLock copy_lock(nap);
191 if (!ConvertScalarInput(nap, params[1],
192 &data_pipe_producer_handle_value)) {
193 return -1;
195 if (!ConvertScalarInOut(nap, params[3], false, &num_bytes_value,
196 &num_bytes_ptr)) {
197 return -1;
199 if (!ConvertScalarInput(nap, params[4], &flags_value)) {
200 return -1;
202 if (!ConvertScalarOutput(nap, params[5], false, &result_ptr)) {
203 return -1;
205 if (!ConvertArray(nap, params[2], num_bytes_value, 1, false,
206 &elements)) {
207 return -1;
211 result_value = MojoSystemImplWriteData(
212 g_mojo_system, data_pipe_producer_handle_value, elements,
213 &num_bytes_value, flags_value);
216 ScopedCopyLock copy_lock(nap);
217 *num_bytes_ptr = num_bytes_value;
218 *result_ptr = result_value;
221 return 0;
223 case 6:
224 fprintf(stderr, "MojoBeginWriteData not implemented\n");
225 return -1;
226 case 7: {
227 if (num_params != 4) {
228 return -1;
230 MojoHandle data_pipe_producer_handle_value;
231 uint32_t num_bytes_written_value;
232 MojoResult volatile* result_ptr;
233 MojoResult result_value;
235 ScopedCopyLock copy_lock(nap);
236 if (!ConvertScalarInput(nap, params[1],
237 &data_pipe_producer_handle_value)) {
238 return -1;
240 if (!ConvertScalarInput(nap, params[2], &num_bytes_written_value)) {
241 return -1;
243 if (!ConvertScalarOutput(nap, params[3], false, &result_ptr)) {
244 return -1;
248 result_value = MojoSystemImplEndWriteData(g_mojo_system,
249 data_pipe_producer_handle_value,
250 num_bytes_written_value);
253 ScopedCopyLock copy_lock(nap);
254 *result_ptr = result_value;
257 return 0;
259 case 8: {
260 if (num_params != 6) {
261 return -1;
263 MojoHandle data_pipe_consumer_handle_value;
264 void* elements;
265 uint32_t volatile* num_bytes_ptr;
266 uint32_t num_bytes_value;
267 MojoReadDataFlags flags_value;
268 MojoResult volatile* result_ptr;
269 MojoResult result_value;
271 ScopedCopyLock copy_lock(nap);
272 if (!ConvertScalarInput(nap, params[1],
273 &data_pipe_consumer_handle_value)) {
274 return -1;
276 if (!ConvertScalarInOut(nap, params[3], false, &num_bytes_value,
277 &num_bytes_ptr)) {
278 return -1;
280 if (!ConvertScalarInput(nap, params[4], &flags_value)) {
281 return -1;
283 if (!ConvertScalarOutput(nap, params[5], false, &result_ptr)) {
284 return -1;
286 if (!ConvertArray(nap, params[2], num_bytes_value, 1, false,
287 &elements)) {
288 return -1;
292 result_value =
293 MojoSystemImplReadData(g_mojo_system, data_pipe_consumer_handle_value,
294 elements, &num_bytes_value, flags_value);
297 ScopedCopyLock copy_lock(nap);
298 *num_bytes_ptr = num_bytes_value;
299 *result_ptr = result_value;
302 return 0;
304 case 9:
305 fprintf(stderr, "MojoBeginReadData not implemented\n");
306 return -1;
307 case 10: {
308 if (num_params != 4) {
309 return -1;
311 MojoHandle data_pipe_consumer_handle_value;
312 uint32_t num_bytes_read_value;
313 MojoResult volatile* result_ptr;
314 MojoResult result_value;
316 ScopedCopyLock copy_lock(nap);
317 if (!ConvertScalarInput(nap, params[1],
318 &data_pipe_consumer_handle_value)) {
319 return -1;
321 if (!ConvertScalarInput(nap, params[2], &num_bytes_read_value)) {
322 return -1;
324 if (!ConvertScalarOutput(nap, params[3], false, &result_ptr)) {
325 return -1;
329 result_value = MojoSystemImplEndReadData(
330 g_mojo_system, data_pipe_consumer_handle_value, num_bytes_read_value);
333 ScopedCopyLock copy_lock(nap);
334 *result_ptr = result_value;
337 return 0;
339 case 11: {
340 if (num_params != 2) {
341 return -1;
343 MojoTimeTicks volatile* result_ptr;
344 MojoTimeTicks result_value;
346 ScopedCopyLock copy_lock(nap);
347 if (!ConvertScalarOutput(nap, params[1], false, &result_ptr)) {
348 return -1;
352 result_value = MojoSystemImplGetTimeTicksNow(g_mojo_system);
355 ScopedCopyLock copy_lock(nap);
356 *result_ptr = result_value;
359 return 0;
361 case 12: {
362 if (num_params != 3) {
363 return -1;
365 MojoHandle handle_value;
366 MojoResult volatile* result_ptr;
367 MojoResult result_value;
369 ScopedCopyLock copy_lock(nap);
370 if (!ConvertScalarInput(nap, params[1], &handle_value)) {
371 return -1;
373 if (!ConvertScalarOutput(nap, params[2], false, &result_ptr)) {
374 return -1;
378 result_value = MojoSystemImplClose(g_mojo_system, handle_value);
381 ScopedCopyLock copy_lock(nap);
382 *result_ptr = result_value;
385 return 0;
387 case 13: {
388 if (num_params != 6) {
389 return -1;
391 MojoHandle handle_value;
392 MojoHandleSignals signals_value;
393 MojoDeadline deadline_value;
394 MojoHandleSignalsState volatile* signals_state_ptr;
395 MojoHandleSignalsState signals_state_value;
396 MojoResult volatile* result_ptr;
397 MojoResult result_value;
399 ScopedCopyLock copy_lock(nap);
400 if (!ConvertScalarInput(nap, params[1], &handle_value)) {
401 return -1;
403 if (!ConvertScalarInput(nap, params[2], &signals_value)) {
404 return -1;
406 if (!ConvertScalarInput(nap, params[3], &deadline_value)) {
407 return -1;
409 if (!ConvertScalarOutput(nap, params[4], true, &signals_state_ptr)) {
410 return -1;
412 if (!ConvertScalarOutput(nap, params[5], false, &result_ptr)) {
413 return -1;
417 result_value = MojoSystemImplWait(
418 g_mojo_system, handle_value, signals_value, deadline_value,
419 signals_state_ptr ? &signals_state_value : NULL);
422 ScopedCopyLock copy_lock(nap);
423 if (signals_state_ptr != NULL) {
424 memcpy_volatile_out(signals_state_ptr, &signals_state_value,
425 sizeof(MojoHandleSignalsState));
427 *result_ptr = result_value;
430 return 0;
432 case 14: {
433 if (num_params != 8) {
434 return -1;
436 const MojoHandle* handles;
437 const MojoHandleSignals* signals;
438 uint32_t num_handles_value;
439 MojoDeadline deadline_value;
440 uint32_t volatile* result_index_ptr;
441 uint32_t result_index_value;
442 struct MojoHandleSignalsState* signals_states;
443 MojoResult volatile* result_ptr;
444 MojoResult result_value;
446 ScopedCopyLock copy_lock(nap);
447 if (!ConvertScalarInput(nap, params[3], &num_handles_value)) {
448 return -1;
450 if (!ConvertScalarInput(nap, params[4], &deadline_value)) {
451 return -1;
453 if (!ConvertScalarInOut(nap, params[5], true, &result_index_value,
454 &result_index_ptr)) {
455 return -1;
457 if (!ConvertScalarOutput(nap, params[7], false, &result_ptr)) {
458 return -1;
460 if (!ConvertArray(nap, params[1], num_handles_value, sizeof(*handles),
461 false, &handles)) {
462 return -1;
464 if (!ConvertArray(nap, params[2], num_handles_value, sizeof(*signals),
465 false, &signals)) {
466 return -1;
468 if (!ConvertArray(nap, params[6], num_handles_value,
469 sizeof(*signals_states), true, &signals_states)) {
470 return -1;
474 result_value = MojoSystemImplWaitMany(
475 g_mojo_system, handles, signals, num_handles_value, deadline_value,
476 result_index_ptr ? &result_index_value : NULL, signals_states);
479 ScopedCopyLock copy_lock(nap);
480 if (result_index_ptr != NULL) {
481 *result_index_ptr = result_index_value;
483 *result_ptr = result_value;
486 return 0;
488 case 15: {
489 if (num_params != 5) {
490 return -1;
492 const struct MojoCreateMessagePipeOptions* options;
493 MojoHandle volatile* message_pipe_handle0_ptr;
494 MojoHandle message_pipe_handle0_value;
495 MojoHandle volatile* message_pipe_handle1_ptr;
496 MojoHandle message_pipe_handle1_value;
497 MojoResult volatile* result_ptr;
498 MojoResult result_value;
500 ScopedCopyLock copy_lock(nap);
501 if (!ConvertExtensibleStructInput(nap, params[1], true, &options)) {
502 return -1;
504 if (!ConvertScalarInOut(nap, params[2], false,
505 &message_pipe_handle0_value,
506 &message_pipe_handle0_ptr)) {
507 return -1;
509 if (!ConvertScalarInOut(nap, params[3], false,
510 &message_pipe_handle1_value,
511 &message_pipe_handle1_ptr)) {
512 return -1;
514 if (!ConvertScalarOutput(nap, params[4], false, &result_ptr)) {
515 return -1;
519 result_value = MojoSystemImplCreateMessagePipe(
520 g_mojo_system, options, &message_pipe_handle0_value,
521 &message_pipe_handle1_value);
524 ScopedCopyLock copy_lock(nap);
525 *message_pipe_handle0_ptr = message_pipe_handle0_value;
526 *message_pipe_handle1_ptr = message_pipe_handle1_value;
527 *result_ptr = result_value;
530 return 0;
532 case 16: {
533 if (num_params != 8) {
534 return -1;
536 MojoHandle message_pipe_handle_value;
537 const void* bytes;
538 uint32_t num_bytes_value;
539 const MojoHandle* handles;
540 uint32_t num_handles_value;
541 MojoWriteMessageFlags flags_value;
542 MojoResult volatile* result_ptr;
543 MojoResult result_value;
545 ScopedCopyLock copy_lock(nap);
546 if (!ConvertScalarInput(nap, params[1], &message_pipe_handle_value)) {
547 return -1;
549 if (!ConvertScalarInput(nap, params[3], &num_bytes_value)) {
550 return -1;
552 if (!ConvertScalarInput(nap, params[5], &num_handles_value)) {
553 return -1;
555 if (!ConvertScalarInput(nap, params[6], &flags_value)) {
556 return -1;
558 if (!ConvertScalarOutput(nap, params[7], false, &result_ptr)) {
559 return -1;
561 if (!ConvertArray(nap, params[2], num_bytes_value, 1, true, &bytes)) {
562 return -1;
564 if (!ConvertArray(nap, params[4], num_handles_value, sizeof(*handles),
565 true, &handles)) {
566 return -1;
570 result_value = MojoSystemImplWriteMessage(
571 g_mojo_system, message_pipe_handle_value, bytes, num_bytes_value,
572 handles, num_handles_value, flags_value);
575 ScopedCopyLock copy_lock(nap);
576 *result_ptr = result_value;
579 return 0;
581 case 17: {
582 if (num_params != 8) {
583 return -1;
585 MojoHandle message_pipe_handle_value;
586 void* bytes;
587 uint32_t volatile* num_bytes_ptr;
588 uint32_t num_bytes_value;
589 MojoHandle* handles;
590 uint32_t volatile* num_handles_ptr;
591 uint32_t num_handles_value;
592 MojoReadMessageFlags flags_value;
593 MojoResult volatile* result_ptr;
594 MojoResult result_value;
596 ScopedCopyLock copy_lock(nap);
597 if (!ConvertScalarInput(nap, params[1], &message_pipe_handle_value)) {
598 return -1;
600 if (!ConvertScalarInOut(nap, params[3], true, &num_bytes_value,
601 &num_bytes_ptr)) {
602 return -1;
604 if (!ConvertScalarInOut(nap, params[5], true, &num_handles_value,
605 &num_handles_ptr)) {
606 return -1;
608 if (!ConvertScalarInput(nap, params[6], &flags_value)) {
609 return -1;
611 if (!ConvertScalarOutput(nap, params[7], false, &result_ptr)) {
612 return -1;
614 if (!ConvertArray(nap, params[2], num_bytes_value, 1, true, &bytes)) {
615 return -1;
617 if (!ConvertArray(nap, params[4], num_handles_value, sizeof(*handles),
618 true, &handles)) {
619 return -1;
623 result_value = MojoSystemImplReadMessage(
624 g_mojo_system, message_pipe_handle_value, bytes,
625 num_bytes_ptr ? &num_bytes_value : NULL, handles,
626 num_handles_ptr ? &num_handles_value : NULL, flags_value);
629 ScopedCopyLock copy_lock(nap);
630 if (num_bytes_ptr != NULL) {
631 *num_bytes_ptr = num_bytes_value;
633 if (num_handles_ptr != NULL) {
634 *num_handles_ptr = num_handles_value;
636 *result_ptr = result_value;
639 return 0;
641 case 18: {
642 if (num_params != 3) {
643 return -1;
645 MojoHandle volatile* handle_ptr;
646 MojoHandle handle_value;
647 MojoResult volatile* result_ptr;
648 MojoResult result_value;
650 ScopedCopyLock copy_lock(nap);
651 if (!ConvertScalarInOut(nap, params[1], false, &handle_value,
652 &handle_ptr)) {
653 return -1;
655 if (!ConvertScalarOutput(nap, params[2], false, &result_ptr)) {
656 return -1;
660 result_value = _MojoGetInitialHandle(&handle_value);
663 ScopedCopyLock copy_lock(nap);
664 *handle_ptr = handle_value;
665 *result_ptr = result_value;
668 return 0;
672 return -1;
675 ssize_t MojoDescRecvMsg(void* handle,
676 struct NaClImcTypedMsgHdr* msg,
677 int flags) {
678 return -1;
681 struct NaClDesc* MakeMojoDesc(struct NaClApp* nap) {
682 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
683 funcs.Destroy = MojoDescDestroy;
684 funcs.SendMsg = MojoDescSendMsg;
685 funcs.RecvMsg = MojoDescRecvMsg;
686 return NaClDescMakeCustomDesc(nap, &funcs);
689 void MojoDisabledDescDestroy(void* handle) {
692 ssize_t MojoDisabledDescSendMsg(void* handle,
693 const struct NaClImcTypedMsgHdr* msg,
694 int flags) {
695 fprintf(stderr, "Mojo is not currently supported.");
696 abort();
699 ssize_t MojoDisabledDescRecvMsg(void* handle,
700 struct NaClImcTypedMsgHdr* msg,
701 int flags) {
702 fprintf(stderr, "Mojo is not currently supported.");
703 abort();
706 struct NaClDesc* MakeDisabledMojoDesc(struct NaClApp* nap) {
707 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
708 funcs.Destroy = MojoDisabledDescDestroy;
709 funcs.SendMsg = MojoDisabledDescSendMsg;
710 funcs.RecvMsg = MojoDisabledDescRecvMsg;
711 return NaClDescMakeCustomDesc(nap, &funcs);
714 } // namespace
716 // The value for this FD must not conflict with uses inside Chromium. However,
717 // mojo/nacl doesn't depend on any Chromium headers, so we can't use a #define
718 // from there.
719 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3)
721 MojoResult InjectMojo(struct NaClApp* nap, MojoHandle handle) {
722 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap));
723 g_mojo_system = MojoSystemImplCreateImpl();
724 return MojoSystemImplTransferHandle(MojoSystemImplGetDefaultImpl(), handle,
725 g_mojo_system, &g_mojo_handle);
728 void InjectDisabledMojo(struct NaClApp* nap) {
729 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeDisabledMojoDesc(nap));