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. 4 5 {{generator_warning}} 6 7 #include "mojo/nacl/mojo_syscall.h" 8 9 #include <stdio.h> 10 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" 16 17 namespace { 18 19 void MojoDescDestroy(void* handle) { 20 } 21 22 ssize_t MojoDescSendMsg(void* handle, 23 const struct NaClImcTypedMsgHdr* msg, 24 int flags) { 25 struct NaClApp* nap = static_cast<struct NaClApp*>(handle); 26 27 if (msg->iov_length != 1 || msg->ndesc_length != 0) { 28 return -1; 29 } 30 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); 33 34 if (num_params < 1) { 35 return -1; 36 } 37 38 uint32_t msg_type = params[0]; 39 switch (msg_type) { 40 {{body}} 41 } 42 43 return -1; 44 } 45 46 ssize_t MojoDescRecvMsg(void* handle, 47 struct NaClImcTypedMsgHdr* msg, 48 int flags) { 49 return -1; 50 } 51 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); 58 } 59 60 } // namespace 61 62 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 2) 63 64 void InjectMojo(struct NaClApp* nap) { 65 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap)); 66 } 67