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"
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;
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
,
35 struct NaClApp
* nap
= static_cast<struct NaClApp
*>(handle
);
37 if (msg
->iov_length
!= 1 || msg
->ndesc_length
!= 0) {
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
);
48 uint32_t msg_type
= params
[0];
51 if (num_params
!= 5) {
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
)) {
65 if (!ConvertScalarInput(nap
, params
[2], &num_bytes_value
)) {
68 if (!ConvertScalarInOut(nap
, params
[3], false,
69 &shared_buffer_handle_value
,
70 &shared_buffer_handle_ptr
)) {
73 if (!ConvertScalarOutput(nap
, params
[4], false, &result_ptr
)) {
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
;
90 if (num_params
!= 5) {
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
)) {
104 if (!ConvertExtensibleStructInput(nap
, params
[2], true, &options
)) {
107 if (!ConvertScalarInOut(nap
, params
[3], false, &new_buffer_handle_value
,
108 &new_buffer_handle_ptr
)) {
111 if (!ConvertScalarOutput(nap
, params
[4], false, &result_ptr
)) {
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
;
129 fprintf(stderr
, "MojoMapBuffer not implemented\n");
132 fprintf(stderr
, "MojoUnmapBuffer not implemented\n");
135 if (num_params
!= 5) {
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
)) {
150 if (!ConvertScalarInOut(nap
, params
[2], false,
151 &data_pipe_producer_handle_value
,
152 &data_pipe_producer_handle_ptr
)) {
155 if (!ConvertScalarInOut(nap
, params
[3], false,
156 &data_pipe_consumer_handle_value
,
157 &data_pipe_consumer_handle_ptr
)) {
160 if (!ConvertScalarOutput(nap
, params
[4], false, &result_ptr
)) {
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
;
179 if (num_params
!= 6) {
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
)) {
195 if (!ConvertScalarInOut(nap
, params
[3], false, &num_bytes_value
,
199 if (!ConvertScalarInput(nap
, params
[4], &flags_value
)) {
202 if (!ConvertScalarOutput(nap
, params
[5], false, &result_ptr
)) {
205 if (!ConvertArray(nap
, params
[2], num_bytes_value
, 1, false,
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
;
224 fprintf(stderr
, "MojoBeginWriteData not implemented\n");
227 if (num_params
!= 4) {
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
)) {
240 if (!ConvertScalarInput(nap
, params
[2], &num_bytes_written_value
)) {
243 if (!ConvertScalarOutput(nap
, params
[3], false, &result_ptr
)) {
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
;
260 if (num_params
!= 6) {
263 MojoHandle data_pipe_consumer_handle_value
;
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
)) {
276 if (!ConvertScalarInOut(nap
, params
[3], false, &num_bytes_value
,
280 if (!ConvertScalarInput(nap
, params
[4], &flags_value
)) {
283 if (!ConvertScalarOutput(nap
, params
[5], false, &result_ptr
)) {
286 if (!ConvertArray(nap
, params
[2], num_bytes_value
, 1, false,
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
;
305 fprintf(stderr
, "MojoBeginReadData not implemented\n");
308 if (num_params
!= 4) {
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
)) {
321 if (!ConvertScalarInput(nap
, params
[2], &num_bytes_read_value
)) {
324 if (!ConvertScalarOutput(nap
, params
[3], false, &result_ptr
)) {
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
;
340 if (num_params
!= 2) {
343 MojoTimeTicks
volatile* result_ptr
;
344 MojoTimeTicks result_value
;
346 ScopedCopyLock
copy_lock(nap
);
347 if (!ConvertScalarOutput(nap
, params
[1], false, &result_ptr
)) {
352 result_value
= MojoSystemImplGetTimeTicksNow(g_mojo_system
);
355 ScopedCopyLock
copy_lock(nap
);
356 *result_ptr
= result_value
;
362 if (num_params
!= 3) {
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
)) {
373 if (!ConvertScalarOutput(nap
, params
[2], false, &result_ptr
)) {
378 result_value
= MojoSystemImplClose(g_mojo_system
, handle_value
);
381 ScopedCopyLock
copy_lock(nap
);
382 *result_ptr
= result_value
;
388 if (num_params
!= 6) {
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
)) {
403 if (!ConvertScalarInput(nap
, params
[2], &signals_value
)) {
406 if (!ConvertScalarInput(nap
, params
[3], &deadline_value
)) {
409 if (!ConvertScalarOutput(nap
, params
[4], true, &signals_state_ptr
)) {
412 if (!ConvertScalarOutput(nap
, params
[5], false, &result_ptr
)) {
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
;
433 if (num_params
!= 8) {
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
)) {
450 if (!ConvertScalarInput(nap
, params
[4], &deadline_value
)) {
453 if (!ConvertScalarInOut(nap
, params
[5], true, &result_index_value
,
454 &result_index_ptr
)) {
457 if (!ConvertScalarOutput(nap
, params
[7], false, &result_ptr
)) {
460 if (!ConvertArray(nap
, params
[1], num_handles_value
, sizeof(*handles
),
464 if (!ConvertArray(nap
, params
[2], num_handles_value
, sizeof(*signals
),
468 if (!ConvertArray(nap
, params
[6], num_handles_value
,
469 sizeof(*signals_states
), true, &signals_states
)) {
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
;
489 if (num_params
!= 5) {
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
)) {
504 if (!ConvertScalarInOut(nap
, params
[2], false,
505 &message_pipe_handle0_value
,
506 &message_pipe_handle0_ptr
)) {
509 if (!ConvertScalarInOut(nap
, params
[3], false,
510 &message_pipe_handle1_value
,
511 &message_pipe_handle1_ptr
)) {
514 if (!ConvertScalarOutput(nap
, params
[4], false, &result_ptr
)) {
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
;
533 if (num_params
!= 8) {
536 MojoHandle message_pipe_handle_value
;
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
)) {
549 if (!ConvertScalarInput(nap
, params
[3], &num_bytes_value
)) {
552 if (!ConvertScalarInput(nap
, params
[5], &num_handles_value
)) {
555 if (!ConvertScalarInput(nap
, params
[6], &flags_value
)) {
558 if (!ConvertScalarOutput(nap
, params
[7], false, &result_ptr
)) {
561 if (!ConvertArray(nap
, params
[2], num_bytes_value
, 1, true, &bytes
)) {
564 if (!ConvertArray(nap
, params
[4], num_handles_value
, sizeof(*handles
),
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
;
582 if (num_params
!= 8) {
585 MojoHandle message_pipe_handle_value
;
587 uint32_t volatile* num_bytes_ptr
;
588 uint32_t num_bytes_value
;
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
)) {
600 if (!ConvertScalarInOut(nap
, params
[3], true, &num_bytes_value
,
604 if (!ConvertScalarInOut(nap
, params
[5], true, &num_handles_value
,
608 if (!ConvertScalarInput(nap
, params
[6], &flags_value
)) {
611 if (!ConvertScalarOutput(nap
, params
[7], false, &result_ptr
)) {
614 if (!ConvertArray(nap
, params
[2], num_bytes_value
, 1, true, &bytes
)) {
617 if (!ConvertArray(nap
, params
[4], num_handles_value
, sizeof(*handles
),
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
;
642 if (num_params
!= 3) {
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
,
655 if (!ConvertScalarOutput(nap
, params
[2], false, &result_ptr
)) {
660 result_value
= _MojoGetInitialHandle(&handle_value
);
663 ScopedCopyLock
copy_lock(nap
);
664 *handle_ptr
= handle_value
;
665 *result_ptr
= result_value
;
675 ssize_t
MojoDescRecvMsg(void* handle
,
676 struct NaClImcTypedMsgHdr
* msg
,
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
,
695 fprintf(stderr
, "Mojo is not currently supported.");
699 ssize_t
MojoDisabledDescRecvMsg(void* handle
,
700 struct NaClImcTypedMsgHdr
* msg
,
702 fprintf(stderr
, "Mojo is not currently supported.");
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
);
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
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
));