Chromium Code Reviews| Index: mojo/monacl/gen/mojo_syscall.cc.template |
| diff --git a/mojo/monacl/gen/mojo_syscall.cc.template b/mojo/monacl/gen/mojo_syscall.cc.template |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..496f9e9e0699a8ec2551ae2b0fa2df33ed87b59d |
| --- /dev/null |
| +++ b/mojo/monacl/gen/mojo_syscall.cc.template |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// WARNING this file was generated by $script_name |
| +// Do not edit by hand. |
| + |
| +#include "mojo/monacl/mojo_syscall.h" |
| + |
| +#include <stdio.h> |
| + |
| +#include "mojo/public/c/system/core.h" |
| +#include "native_client/src/public/nacl_app.h" |
| +#include "native_client/src/shared/platform/nacl_log.h" |
| +#include "native_client/src/trusted/desc/nacl_desc_custom.h" |
| +#include "native_client/src/trusted/service_runtime/nacl_copy.h" |
| +#include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| + |
| +static INLINE uintptr_t NaClUserToSysAddrArray( |
| + struct NaClApp *nap, |
| + uintptr_t uaddr, |
| + size_t count, |
| + size_t size) { |
| + // TODO overflow checking |
| + size_t range = count * size; |
| + return NaClUserToSysAddrRange(nap, uaddr, range); |
| +} |
| + |
| +void MojoDescDestroy(void *handle) { |
| + UNREFERENCED_PARAMETER(handle); |
| + NaClLog(LOG_ERROR, "Called destroy...\n"); |
| +} |
| + |
| +ssize_t MojoDescSendMsg(void *handle, |
| + const struct NaClImcTypedMsgHdr *msg, |
| + int flags) { |
| + UNREFERENCED_PARAMETER(flags); |
| + |
| + struct NaClApp *nap = static_cast<struct NaClApp*>(handle); |
| + |
| + if (msg->iov_length != 1 || msg->iov[0].length < 8 || msg->ndesc_length != 0) { |
| + NaClLog(LOG_ERROR, "Malformed message.\n"); |
| + return -1; |
| + } |
| + |
| + uint32_t *params = static_cast<uint32_t*>(msg->iov[0].base); |
| + uint32_t numParams = msg->iov[0].length / sizeof(*params); |
| + |
| + uint32_t msgType = params[0]; |
| + //printf("Message: %d.\n", msgType); |
| + switch (msgType) { |
| +$body |
| + default: |
| + return -1; |
| + } |
| + |
| + return -1; |
| +} |
| + |
| +ssize_t MojoDescRecvMsg(void *handle, |
| + struct NaClImcTypedMsgHdr *msg, |
| + int flags) { |
| + UNREFERENCED_PARAMETER(handle); |
| + UNREFERENCED_PARAMETER(msg); |
| + UNREFERENCED_PARAMETER(flags); |
| + |
| + NaClLog(LOG_FATAL, "MojoDescRecvMsg: Not implemented\n"); |
|
Mark Seaborn
2014/07/21 16:31:39
Don't introduce more Chrome-side uses of NaClLog()
Nick Bray (chromium)
2014/07/21 22:38:36
sel_ldr.h included for range checks. sel_ldr incl
Mark Seaborn
2014/07/21 23:25:44
Right -- that kind of conflict is the reason why y
|
| + return 0; |
| +} |
| + |
| +struct NaClDesc *MakeMojoDesc(struct NaClApp *nap) { |
| + struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER; |
| + funcs.Destroy = MojoDescDestroy; |
| + funcs.SendMsg = MojoDescSendMsg; |
| + funcs.RecvMsg = MojoDescRecvMsg; |
| + return NaClDescMakeCustomDesc(nap, &funcs); |
| +} |
| + |
| +#define NACL_MOJO_DESC 5 |
| + |
| +void InjectMojo(struct NaClApp *nap) { |
| + NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap)); |
| +} |