OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" | 5 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" |
6 | 6 |
7 #include "mojo/public/c/system/functions.h" | 7 #include "mojo/public/c/system/functions.h" |
8 #include "mojo/public/platform/nacl/mgl_irt.h" | 8 #include "mojo/public/platform/nacl/mgl_irt.h" |
9 #include "mojo/public/platform/nacl/mojo_irt.h" | 9 #include "mojo/public/platform/nacl/mojo_irt.h" |
10 #include "native_client/src/public/irt_core.h" | 10 #include "native_client/src/public/irt_core.h" |
11 #include "native_client/src/untrusted/irt/irt_dev.h" | |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID; | 15 MojoHandle g_mojo_handle = MOJO_HANDLE_INVALID; |
15 | 16 bool g_running_translator = false; |
16 MojoResult _MojoGetInitialHandle(MojoHandle* handle) { | |
17 *handle = g_mojo_handle; | |
18 return MOJO_RESULT_OK; | |
19 } | |
20 | 17 |
21 const struct nacl_irt_mojo kIrtMojo = { | 18 const struct nacl_irt_mojo kIrtMojo = { |
22 MojoCreateSharedBuffer, | 19 MojoCreateSharedBuffer, |
23 MojoDuplicateBufferHandle, | 20 MojoDuplicateBufferHandle, |
24 MojoMapBuffer, | 21 MojoMapBuffer, |
25 MojoUnmapBuffer, | 22 MojoUnmapBuffer, |
26 MojoCreateDataPipe, | 23 MojoCreateDataPipe, |
27 MojoWriteData, | 24 MojoWriteData, |
28 MojoBeginWriteData, | 25 MojoBeginWriteData, |
29 MojoEndWriteData, | 26 MojoEndWriteData, |
30 MojoReadData, | 27 MojoReadData, |
31 MojoBeginReadData, | 28 MojoBeginReadData, |
32 MojoEndReadData, | 29 MojoEndReadData, |
33 MojoGetTimeTicksNow, | 30 MojoGetTimeTicksNow, |
34 MojoClose, | 31 MojoClose, |
35 MojoWait, | 32 MojoWait, |
36 MojoWaitMany, | 33 MojoWaitMany, |
37 MojoCreateMessagePipe, | 34 MojoCreateMessagePipe, |
38 MojoWriteMessage, | 35 MojoWriteMessage, |
39 MojoReadMessage, | 36 MojoReadMessage, |
40 _MojoGetInitialHandle, | 37 nacl::MojoGetInitialHandle, |
41 }; | 38 }; |
42 | 39 |
43 const struct nacl_irt_mgl kIrtMGL = { | 40 const struct nacl_irt_mgl kIrtMGL = { |
44 MGLCreateContext, | 41 MGLCreateContext, |
45 MGLDestroyContext, | 42 MGLDestroyContext, |
46 MGLMakeCurrent, | 43 MGLMakeCurrent, |
47 MGLGetCurrentContext, | 44 MGLGetCurrentContext, |
48 MGLGetProcAddress, | 45 MGLGetProcAddress, |
49 }; | 46 }; |
50 | 47 |
51 const struct nacl_irt_mgl_onscreen kIrtMGLOnScreen = { | 48 const struct nacl_irt_mgl_onscreen kIrtMGLOnScreen = { |
52 MGLResizeSurface, | 49 MGLResizeSurface, |
53 MGLSwapBuffers, | 50 MGLSwapBuffers, |
54 }; | 51 }; |
55 | 52 |
56 const struct nacl_irt_mgl_signal_sync_point kIrtMGLSignalSyncPoint = { | 53 const struct nacl_irt_mgl_signal_sync_point kIrtMGLSignalSyncPoint = { |
57 MGLSignalSyncPoint, | 54 MGLSignalSyncPoint, |
58 }; | 55 }; |
59 | 56 |
57 int not_pnacl_filter(void) { | |
Mark Seaborn
2015/10/27 17:30:20
Naming nit: NotPNaClFilter().
Also can use "()" i
Sean Klein
2015/10/28 17:02:41
Done.
| |
58 if (g_running_translator) { | |
Mark Seaborn
2015/10/27 17:30:20
Just "return g_running_translator"?
Sean Klein
2015/10/28 17:02:40
Done.
| |
59 return 1; | |
60 } | |
61 return 0; | |
62 } | |
63 | |
60 const struct nacl_irt_interface kIrtInterfaces[] = { | 64 const struct nacl_irt_interface kIrtInterfaces[] = { |
61 {NACL_IRT_MOJO_v0_1, &kIrtMojo, sizeof(kIrtMojo), nullptr}, | 65 // Interface to call Mojo functions |
66 { NACL_IRT_MOJO_v0_1, | |
67 &kIrtMojo, | |
68 sizeof(kIrtMojo), | |
69 nullptr }, | |
70 // Interface to call PNaCl translation | |
71 { NACL_IRT_PRIVATE_PNACL_TRANSLATOR_COMPILE_v0_1, | |
72 &nacl::nacl_irt_private_pnacl_translator_compile, | |
73 sizeof(nacl_irt_private_pnacl_translator_compile), | |
74 not_pnacl_filter }, | |
75 // Interface to call PNaCl linking | |
76 { NACL_IRT_PRIVATE_PNACL_TRANSLATOR_LINK_v0_1, | |
77 &nacl::nacl_irt_private_pnacl_translator_link, | |
78 sizeof(nacl_irt_private_pnacl_translator_link), | |
79 not_pnacl_filter }, | |
80 // Adds mechanism for opening object files, like crtbegin.o | |
81 { NACL_IRT_RESOURCE_OPEN_v0_1, | |
82 &nacl::nacl_irt_resource_open, | |
83 sizeof(nacl_irt_resource_open), | |
84 not_pnacl_filter }, | |
62 {NACL_IRT_MGL_v0_1, &kIrtMGL, sizeof(kIrtMGL), nullptr}, | 85 {NACL_IRT_MGL_v0_1, &kIrtMGL, sizeof(kIrtMGL), nullptr}, |
63 {NACL_IRT_MGL_ONSCREEN_v0_1, &kIrtMGLOnScreen, sizeof(kIrtMGLOnScreen), | 86 {NACL_IRT_MGL_ONSCREEN_v0_1, &kIrtMGLOnScreen, sizeof(kIrtMGLOnScreen), |
64 nullptr}, | 87 nullptr}, |
Petr Hosek
2015/10/27 15:07:52
Could you reformat all items to be consistent?
Sean Klein
2015/10/28 17:02:40
Done. Also, added comments for GPU-related IRT int
| |
65 {NACL_IRT_MGL_SIGNAL_SYNC_POINT_v0_1, &kIrtMGLSignalSyncPoint, | 88 {NACL_IRT_MGL_SIGNAL_SYNC_POINT_v0_1, &kIrtMGLSignalSyncPoint, |
66 sizeof(kIrtMGLSignalSyncPoint), nullptr}, | 89 sizeof(kIrtMGLSignalSyncPoint), nullptr}, |
67 }; | 90 }; |
68 | 91 |
69 } // namespace | 92 } // namespace |
70 | 93 |
71 namespace nacl { | 94 namespace nacl { |
72 | 95 |
96 MojoResult MojoGetInitialHandle(MojoHandle* handle) { | |
97 *handle = g_mojo_handle; | |
98 return MOJO_RESULT_OK; | |
99 } | |
100 | |
73 void MojoSetInitialHandle(MojoHandle handle) { | 101 void MojoSetInitialHandle(MojoHandle handle) { |
74 g_mojo_handle = handle; | 102 g_mojo_handle = handle; |
75 } | 103 } |
76 | 104 |
105 void MojoPnaclTranslatorEnable() { | |
106 g_running_translator = true; | |
107 } | |
108 | |
77 size_t MojoIrtNonsfiQuery(const char* interface_ident, | 109 size_t MojoIrtNonsfiQuery(const char* interface_ident, |
78 void* table, | 110 void* table, |
79 size_t tablesize) { | 111 size_t tablesize) { |
80 size_t result = nacl_irt_query_list(interface_ident, table, tablesize, | 112 size_t result = nacl_irt_query_list(interface_ident, table, tablesize, |
81 kIrtInterfaces, sizeof(kIrtInterfaces)); | 113 kIrtInterfaces, sizeof(kIrtInterfaces)); |
82 if (result != 0) | 114 if (result != 0) |
83 return result; | 115 return result; |
84 return nacl_irt_query_core(interface_ident, table, tablesize); | 116 return nacl_irt_query_core(interface_ident, table, tablesize); |
85 } | 117 } |
86 | 118 |
87 } // namespace nacl | 119 } // namespace nacl |
OLD | NEW |