| OLD | NEW |
| (Empty) |
| 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 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 MojoResult _MojoGetInitialHandle(MojoHandle* handle) { | |
| 22 *handle = g_mojo_handle; | |
| 23 return MOJO_RESULT_OK; | |
| 24 } | |
| 25 | |
| 26 void MojoDescDestroy(void* handle) { | |
| 27 } | |
| 28 | |
| 29 ssize_t MojoDescSendMsg(void* handle, | |
| 30 const struct NaClImcTypedMsgHdr* msg, | |
| 31 int flags) { | |
| 32 struct NaClApp* nap = static_cast<struct NaClApp*>(handle); | |
| 33 | |
| 34 if (msg->iov_length != 1 || msg->ndesc_length != 0) { | |
| 35 return -1; | |
| 36 } | |
| 37 | |
| 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); | |
| 40 | |
| 41 if (num_params < 1) { | |
| 42 return -1; | |
| 43 } | |
| 44 | |
| 45 uint32_t msg_type = params[0]; | |
| 46 switch (msg_type) { | |
| 47 {{body}} | |
| 48 } | |
| 49 | |
| 50 return -1; | |
| 51 } | |
| 52 | |
| 53 ssize_t MojoDescRecvMsg(void* handle, | |
| 54 struct NaClImcTypedMsgHdr* msg, | |
| 55 int flags) { | |
| 56 return -1; | |
| 57 } | |
| 58 | |
| 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); | |
| 65 } | |
| 66 | |
| 67 void MojoDisabledDescDestroy(void* handle) { | |
| 68 } | |
| 69 | |
| 70 ssize_t MojoDisabledDescSendMsg(void* handle, | |
| 71 const struct NaClImcTypedMsgHdr* msg, | |
| 72 int flags) { | |
| 73 fprintf(stderr, "Mojo is not currently supported."); | |
| 74 abort(); | |
| 75 } | |
| 76 | |
| 77 ssize_t MojoDisabledDescRecvMsg(void* handle, | |
| 78 struct NaClImcTypedMsgHdr* msg, | |
| 79 int flags) { | |
| 80 fprintf(stderr, "Mojo is not currently supported."); | |
| 81 abort(); | |
| 82 } | |
| 83 | |
| 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); | |
| 90 } | |
| 91 | |
| 92 } // namespace | |
| 93 | |
| 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 | |
| 96 // from there. | |
| 97 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3) | |
| 98 | |
| 99 void InjectMojo(struct NaClApp* nap) { | |
| 100 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap)); | |
| 101 g_mojo_handle = MOJO_HANDLE_INVALID; | |
| 102 } | |
| 103 | |
| 104 void InjectMojo(struct NaClApp* nap, MojoHandle handle) { | |
| 105 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap)); | |
| 106 g_mojo_handle = handle; | |
| 107 } | |
| 108 | |
| 109 void InjectDisabledMojo(struct NaClApp* nap) { | |
| 110 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeDisabledMojoDesc(nap)); | |
| 111 } | |
| OLD | NEW |