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"
19 void MojoDescDestroy(void* handle) {
22 ssize_t MojoDescSendMsg(void* handle,
23 const struct NaClImcTypedMsgHdr* msg,
25 struct NaClApp* nap = static_cast<struct NaClApp*>(handle);
27 if (msg->iov_length != 1 || msg->ndesc_length != 0) {
31 uint32_t volatile* params = static_cast<uint32_t volatile*>(msg->iov[0].base);
32 size_t num_params = msg->iov[0].length / sizeof(*params);
38 uint32_t msg_type = params[0];
46 ssize_t MojoDescRecvMsg(void* handle,
47 struct NaClImcTypedMsgHdr* msg,
52 struct NaClDesc* MakeMojoDesc(struct NaClApp* nap) {
53 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
54 funcs.Destroy = MojoDescDestroy;
55 funcs.SendMsg = MojoDescSendMsg;
56 funcs.RecvMsg = MojoDescRecvMsg;
57 return NaClDescMakeCustomDesc(nap, &funcs);
62 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 2)
64 void InjectMojo(struct NaClApp* nap) {
65 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap));