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.
7 #include "mojo/nacl/mojo_syscall.h"
11 #include "mojo/nacl/mojo_syscall_internal.h"
12 #include "mojo/public/c/system/core.h"
13 #include "native_client/src/public/chrome_main.h"
14 #include "native_client/src/public/nacl_app.h"
15 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
17 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID;
21 MojoResult _MojoGetInitialHandle(MojoHandle* handle) {
22 *handle = g_mojo_handle;
23 return MOJO_RESULT_OK;
26 void MojoDescDestroy(void* handle) {
29 ssize_t MojoDescSendMsg(void* handle,
30 const struct NaClImcTypedMsgHdr* msg,
32 struct NaClApp* nap = static_cast<struct NaClApp*>(handle);
34 if (msg->iov_length != 1 || msg->ndesc_length != 0) {
38 uint32_t volatile* params = static_cast<uint32_t volatile*>(msg->iov[0].base);
39 size_t num_params = msg->iov[0].length / sizeof(*params);
45 uint32_t msg_type = params[0];
53 ssize_t MojoDescRecvMsg(void* handle,
54 struct NaClImcTypedMsgHdr* msg,
59 struct NaClDesc* MakeMojoDesc(struct NaClApp* nap) {
60 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
61 funcs.Destroy = MojoDescDestroy;
62 funcs.SendMsg = MojoDescSendMsg;
63 funcs.RecvMsg = MojoDescRecvMsg;
64 return NaClDescMakeCustomDesc(nap, &funcs);
67 void MojoDisabledDescDestroy(void* handle) {
70 ssize_t MojoDisabledDescSendMsg(void* handle,
71 const struct NaClImcTypedMsgHdr* msg,
73 fprintf(stderr, "Mojo is not currently supported.");
77 ssize_t MojoDisabledDescRecvMsg(void* handle,
78 struct NaClImcTypedMsgHdr* msg,
80 fprintf(stderr, "Mojo is not currently supported.");
84 struct NaClDesc* MakeDisabledMojoDesc(struct NaClApp* nap) {
85 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
86 funcs.Destroy = MojoDisabledDescDestroy;
87 funcs.SendMsg = MojoDisabledDescSendMsg;
88 funcs.RecvMsg = MojoDisabledDescRecvMsg;
89 return NaClDescMakeCustomDesc(nap, &funcs);
94 // The value for this FD must not conflict with uses inside Chromium. However,
95 // mojo/nacl doesn't depend on any Chromium headers, so we can't use a #define
97 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3)
99 void InjectMojo(struct NaClApp* nap) {
100 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap));
101 g_mojo_handle = MOJO_HANDLE_INVALID;
104 void InjectMojo(struct NaClApp* nap, MojoHandle handle) {
105 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap));
106 g_mojo_handle = handle;
109 void InjectDisabledMojo(struct NaClApp* nap) {
110 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeDisabledMojoDesc(nap));