OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <fcntl.h> |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" |
| 10 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" |
| 11 #include "mojo/public/c/system/main.h" |
| 12 #include "mojo/public/cpp/application/application_connection.h" |
| 13 #include "mojo/public/cpp/application/application_delegate.h" |
| 14 #include "mojo/public/cpp/application/application_runner.h" |
| 15 #include "mojo/public/cpp/application/interface_factory.h" |
| 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 17 #include "services/nacl/pnacl_compile.mojom.h" |
| 18 |
| 19 namespace mojo { |
| 20 namespace nacl { |
| 21 |
| 22 class PexeCompilerImpl : public PexeCompilerInit { |
| 23 public: |
| 24 void PexeCompilerStart(ScopedMessagePipeHandle handle) override { |
| 25 base::FilePath path; |
| 26 if (!PathService::Get(base::DIR_MODULE, &path)) |
| 27 LOG(FATAL) << "Could not find mojo root directory"; |
| 28 path = path.Append("pnacl_translation_files/pnacl-llc.nexe"); |
| 29 int nexe_fd = open(path.value().c_str(), O_RDONLY); |
| 30 if (nexe_fd < 0) |
| 31 LOG(FATAL) << "Could not open compiler nexe: " << path.value(); |
| 32 ::nacl::MojoLaunchNexeNonsfi(nexe_fd, |
| 33 handle.release().value(), |
| 34 true /* enable_translate_irt */); |
| 35 } |
| 36 }; |
| 37 |
| 38 class StrongBindingPexeCompilerImpl : public PexeCompilerImpl { |
| 39 public: |
| 40 explicit StrongBindingPexeCompilerImpl(InterfaceRequest<PexeCompilerInit> |
| 41 request) |
| 42 : strong_binding_(this, request.Pass()) {} |
| 43 |
| 44 private: |
| 45 StrongBinding<PexeCompilerInit> strong_binding_; |
| 46 }; |
| 47 |
| 48 class MultiPexeCompiler : public ApplicationDelegate, |
| 49 public InterfaceFactory<PexeCompilerInit> { |
| 50 public: |
| 51 MultiPexeCompiler() {} |
| 52 |
| 53 // From ApplicationDelegate |
| 54 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| 55 connection->AddService<PexeCompilerInit>(this); |
| 56 return true; |
| 57 } |
| 58 |
| 59 // From InterfaceFactory |
| 60 void Create(ApplicationConnection* connection, |
| 61 InterfaceRequest<PexeCompilerInit> request) override { |
| 62 new StrongBindingPexeCompilerImpl(request.Pass()); |
| 63 } |
| 64 }; |
| 65 |
| 66 } // namespace nacl |
| 67 } // namespace mojo |
| 68 |
| 69 MojoResult MojoMain(MojoHandle application_request) { |
| 70 base::AtExitManager at_exit; |
| 71 mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeCompiler()); |
| 72 return runner.Run(application_request); |
| 73 } |
OLD | NEW |