Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Side by Side Diff: nacl_bindings_generator/mojo_syscall.cc.tmpl

Issue 1398213003: Refactored Non-SFI and SFI NaCl into separate directories. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nacl_bindings_generator/mojo_irt.h.tmpl ('k') | services/nacl/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "mojo/public/c/system/core.h"
12 #include "mojo/public/platform/native/system_impl_private.h"
13 #include "{{bindings_dir}}/mojo_syscall_internal.h"
14 #include "native_client/src/public/chrome_main.h"
15 #include "native_client/src/public/nacl_app.h"
16 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
17
18 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID;
19 MojoSystemImpl g_mojo_system = nullptr;
20
21 namespace {
22
23 MojoResult _MojoGetInitialHandle(MojoHandle* handle) {
24 *handle = g_mojo_handle;
25 return MOJO_RESULT_OK;
26 }
27
28 void MojoDescDestroy(void* handle) {
29 }
30
31 ssize_t MojoDescSendMsg(void* handle,
32 const struct NaClImcTypedMsgHdr* msg,
33 int flags) {
34 struct NaClApp* nap = static_cast<struct NaClApp*>(handle);
35
36 if (msg->iov_length != 1 || msg->ndesc_length != 0) {
37 return -1;
38 }
39
40 uint32_t volatile* params = static_cast<uint32_t volatile*>(msg->iov[0].base);
41 size_t num_params = msg->iov[0].length / sizeof(*params);
42
43 if (num_params < 1) {
44 return -1;
45 }
46
47 uint32_t msg_type = params[0];
48 switch (msg_type) {
49 {{body}}
50 }
51
52 return -1;
53 }
54
55 ssize_t MojoDescRecvMsg(void* handle,
56 struct NaClImcTypedMsgHdr* msg,
57 int flags) {
58 return -1;
59 }
60
61 struct NaClDesc* MakeMojoDesc(struct NaClApp* nap) {
62 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
63 funcs.Destroy = MojoDescDestroy;
64 funcs.SendMsg = MojoDescSendMsg;
65 funcs.RecvMsg = MojoDescRecvMsg;
66 return NaClDescMakeCustomDesc(nap, &funcs);
67 }
68
69 void MojoDisabledDescDestroy(void* handle) {
70 }
71
72 ssize_t MojoDisabledDescSendMsg(void* handle,
73 const struct NaClImcTypedMsgHdr* msg,
74 int flags) {
75 fprintf(stderr, "Mojo is not currently supported.");
76 abort();
77 }
78
79 ssize_t MojoDisabledDescRecvMsg(void* handle,
80 struct NaClImcTypedMsgHdr* msg,
81 int flags) {
82 fprintf(stderr, "Mojo is not currently supported.");
83 abort();
84 }
85
86 struct NaClDesc* MakeDisabledMojoDesc(struct NaClApp* nap) {
87 struct NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER;
88 funcs.Destroy = MojoDisabledDescDestroy;
89 funcs.SendMsg = MojoDisabledDescSendMsg;
90 funcs.RecvMsg = MojoDisabledDescRecvMsg;
91 return NaClDescMakeCustomDesc(nap, &funcs);
92 }
93
94 } // namespace
95
96 // The value for this FD must not conflict with uses inside Chromium. However,
97 // mojo/nacl doesn't depend on any Chromium headers, so we can't use a #define
98 // from there.
99 #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3)
100
101 MojoResult InjectMojo(struct NaClApp* nap, MojoHandle handle) {
102 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeMojoDesc(nap));
103 g_mojo_system = MojoSystemImplCreateImpl();
104 return MojoSystemImplTransferHandle(MojoSystemImplGetDefaultImpl(), handle,
105 g_mojo_system, &g_mojo_handle);
106 }
107
108 void InjectDisabledMojo(struct NaClApp* nap) {
109 NaClAppSetDesc(nap, NACL_MOJO_DESC, MakeDisabledMojoDesc(nap));
110 }
OLDNEW
« no previous file with comments | « nacl_bindings_generator/mojo_irt.h.tmpl ('k') | services/nacl/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698