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 <fcntl.h> | 5 #include <fcntl.h> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" | 10 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" |
11 #include "mojo/public/cpp/bindings/array.h" | 11 #include "mojo/public/cpp/bindings/array.h" |
12 #include "mojo/public/cpp/bindings/string.h" | 12 #include "mojo/public/cpp/bindings/string.h" |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
14 #include "mojo/public/cpp/utility/run_loop.h" | 14 #include "mojo/public/cpp/utility/run_loop.h" |
15 #include "native_client/src/untrusted/irt/irt_dev.h" | 15 #include "native_client/src/untrusted/irt/irt_dev.h" |
16 #include "services/nacl/nonsfi/pnacl_compile.mojom.h" | 16 #include "services/nacl/nonsfi/pnacl_compile.mojom.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Implements a mojom interface which allows the content handler to communicate | 20 // Implements a mojom interface which allows the content handler to communicate |
21 // with the nexe compiler service. | 21 // with the nexe compiler service. |
22 class PexeCompilerImpl : public mojo::nacl::PexeCompiler { | 22 class PexeCompilerImpl : public mojo::nacl::PexeCompiler { |
23 public: | 23 public: |
24 PexeCompilerImpl(mojo::ScopedMessagePipeHandle handle, | 24 PexeCompilerImpl( |
25 const struct nacl_irt_pnacl_compile_funcs* funcs) | 25 mojo::InterfaceRequest<mojo::nacl::PexeCompiler> compiler_request, |
26 : funcs_(funcs), strong_binding_(this, handle.Pass()) {} | 26 const struct nacl_irt_pnacl_compile_funcs* funcs) |
| 27 : funcs_(funcs), strong_binding_(this, compiler_request.Pass()) {} |
27 void PexeCompile(const mojo::String& pexe_file_name, const | 28 void PexeCompile(const mojo::String& pexe_file_name, const |
28 mojo::Callback<void(mojo::Array<mojo::String>)>& callback) | 29 mojo::Callback<void(mojo::Array<mojo::String>)>& callback) |
29 override { | 30 override { |
30 const static uint32_t num_threads = 4; | 31 const static uint32_t num_threads = 4; |
31 #if defined(ARCH_CPU_ARM_FAMILY) | 32 #if defined(ARCH_CPU_ARM_FAMILY) |
32 // pnacl-llc supports split modules. | 33 // pnacl-llc supports split modules. |
33 const size_t obj_file_count = num_threads; | 34 const size_t obj_file_count = num_threads; |
34 #else | 35 #else |
35 // subzero does need split modules. | 36 // subzero does need split modules. |
36 const size_t obj_file_count = 1; | 37 const size_t obj_file_count = 1; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 111 |
111 void ServeTranslateRequest(const struct nacl_irt_pnacl_compile_funcs* funcs) { | 112 void ServeTranslateRequest(const struct nacl_irt_pnacl_compile_funcs* funcs) { |
112 // Acquire the handle -- this is our mechanism to contact the | 113 // Acquire the handle -- this is our mechanism to contact the |
113 // content handler which called us. | 114 // content handler which called us. |
114 MojoHandle handle; | 115 MojoHandle handle; |
115 nacl::MojoGetInitialHandle(&handle); | 116 nacl::MojoGetInitialHandle(&handle); |
116 | 117 |
117 // Convert the MojoHandle into a ScopedMessagePipeHandle, and use that to | 118 // Convert the MojoHandle into a ScopedMessagePipeHandle, and use that to |
118 // implement the PexeCompiler interface. | 119 // implement the PexeCompiler interface. |
119 PexeCompilerImpl impl( | 120 PexeCompilerImpl impl( |
120 mojo::ScopedMessagePipeHandle(mojo::MessagePipeHandle(handle)).Pass(), | 121 mojo::MakeRequest<mojo::nacl::PexeCompiler>( |
| 122 mojo::ScopedMessagePipeHandle(mojo::MessagePipeHandle(handle))), |
121 funcs); | 123 funcs); |
122 mojo::RunLoop::current()->Run(); | 124 mojo::RunLoop::current()->Run(); |
123 } | 125 } |
124 | 126 |
125 } // namespace anonymous | 127 } // namespace anonymous |
126 | 128 |
127 namespace nacl { | 129 namespace nacl { |
128 | 130 |
129 const struct nacl_irt_private_pnacl_translator_compile | 131 const struct nacl_irt_private_pnacl_translator_compile |
130 nacl_irt_private_pnacl_translator_compile = { | 132 nacl_irt_private_pnacl_translator_compile = { |
131 ServeTranslateRequest | 133 ServeTranslateRequest |
132 }; | 134 }; |
133 | 135 |
134 } // namespace nacl | 136 } // namespace nacl |
OLD | NEW |