| 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 "{{bindings_dir}}/mojo_syscall.h" | |
| 8 | |
| 9 #include <stdio.h> | |
| 10 | |
| 11 #include "{{bindings_dir}}/mojo_syscall_internal.h" | |
| 12 #include "mojo/public/c/system/buffer.h" | |
| 13 #include "mojo/public/c/system/data_pipe.h" | |
| 14 #include "mojo/public/c/system/handle.h" | |
| 15 #include "mojo/public/c/system/message_pipe.h" | |
| 16 #include "mojo/public/c/system/result.h" | |
| 17 #include "mojo/public/c/system/time.h" | |
| 18 #include "mojo/public/platform/native/system_impl_private.h" | |
| 19 #include "native_client/src/public/chrome_main.h" | |
| 20 #include "native_client/src/public/nacl_app.h" | |
| 21 #include "native_client/src/trusted/desc/nacl_desc_custom.h" | |
| 22 | |
| 23 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID; | |
| 24 MojoSystemImpl g_mojo_system = nullptr; | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 MojoResult _MojoGetInitialHandle(MojoHandle* handle) { | |
| 29 *handle = g_mojo_handle; | |
| 30 return MOJO_RESULT_OK; | |
| 31 } | |
| 32 | |
| 33 void MojoDescDestroy(void* handle) { | |
| 34 } | |
| 35 | |
| 36 ssize_t MojoDescSendMsg(void* handle, | |
| 37 const struct NaClImcTypedMsgHdr* msg, | |
| 38 int flags) { | |
| 39 struct NaClApp* nap = static_cast<struct NaClApp*>(handle); | |
| 40 | |
| 41 if (msg->iov_length != 1 || msg->ndesc_length != 0) { | |
| 42 return -1; | |
| 43 } | |
| 44 | |
| 45 uint32_t volatile* params = static_cast<uint32_t volatile*>(msg->iov[0].base); | |
| 46 size_t num_params = msg->iov[0].length / sizeof(*params); | |
| 47 | |
| 48 if (num_params < 1) { | |
| 49 return -1; | |
| 50 } | |
| 51 | |
| 52 uint32_t msg_type = params[0]; | |
| 53 switch (msg_type) { | |
| 54 {{body}} | |
| 55 } | |
| 56 | |
| 57 return -1; | |
| 58 } | |
| 59 | |
| 60 ssize_t MojoDescRecvMsg(void* handle, | |
| 61 struct NaClImcTypedMsgHdr* msg, | |
| 62 int flags) { | |
| 63 return -1; | |
| 64 } | |
| 65 | |
| 66 struct NaClDesc* MakeMojoDesc(struct NaClApp* nap) { | |
| 67 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER; | |
| 68 funcs.Destroy = MojoDescDestroy; | |
| 69 funcs.SendMsg = MojoDescSendMsg; | |
| 70 funcs.RecvMsg = MojoDescRecvMsg; | |
| 71 return NaClDescMakeCustomDesc(nap, &funcs); | |
| 72 } | |
| 73 | |
| 74 void MojoDisabledDescDestroy(void* handle) { | |
| 75 } | |
| 76 | |
| 77 ssize_t MojoDisabledDescSendMsg(void* handle, | |
| 78 const struct NaClImcTypedMsgHdr* msg, | |
| 79 int flags) { | |
| 80 fprintf(stderr, "Mojo is not currently supported."); | |
| 81 abort(); | |
| 82 } | |
| 83 | |
| 84 ssize_t MojoDisabledDescRecvMsg(void* handle, | |
| 85 struct NaClImcTypedMsgHdr* msg, | |
| 86 int flags) { | |
| 87 fprintf(stderr, "Mojo is not currently supported."); | |
| 88 abort(); | |
| 89 } | |
| 90 | |
| 91 struct NaClDesc* MakeDisabledMojoDesc(struct NaClApp* nap) { | |
| 92 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER; | |
| 93 funcs.Destroy = MojoDisabledDescDestroy; | |
| 94 funcs.SendMsg = MojoDisabledDescSendMsg; | |
| 95 funcs.RecvMsg = MojoDisabledDescRecvMsg; | |
| 96 return NaClDescMakeCustomDesc(nap, &funcs); | |
| 97 } | |
| 98 | |
| 99 } // namespace | |
| 100 | |
| 101 // The value for this FD must not conflict with uses inside Chromium. However, | |
| 102 // mojo/nacl doesn't depend on any Chromium headers, so we can't use a #define | |
| 103 // from there. | |
| 104 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3) | |
| 105 | |
| 106 MojoResult InjectMojo(struct NaClApp* nap, MojoHandle handle) { | |
| 107 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap)); | |
| 108 g_mojo_system = MojoSystemImplCreateImpl(); | |
| 109 return MojoSystemImplTransferHandle(MojoSystemImplGetDefaultImpl(), handle, | |
| 110 g_mojo_system, &g_mojo_handle); | |
| 111 } | |
| 112 | |
| 113 void InjectDisabledMojo(struct NaClApp* nap) { | |
| 114 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeDisabledMojoDesc(nap)); | |
| 115 } | |
| OLD | NEW |