Chromium Code Reviews| Index: services/nacl/pnacl_link.cc |
| diff --git a/services/nacl/pnacl_link.cc b/services/nacl/pnacl_link.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e6ba9e53e522cb28e80b1770c275816bbd95f35 |
| --- /dev/null |
| +++ b/services/nacl/pnacl_link.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2015 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. |
| + |
| +#include <fcntl.h> |
| + |
| +#include "base/files/file_util.h" |
| +#include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" |
| +#include "mojo/public/c/system/main.h" |
| +#include "mojo/public/cpp/application/application_connection.h" |
| +#include "mojo/public/cpp/application/application_delegate.h" |
| +#include "mojo/public/cpp/application/application_runner.h" |
| +#include "mojo/public/cpp/application/interface_factory.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "services/nacl/pnacl_link.mojom.h" |
| + |
| +namespace mojo { |
| +namespace nacl { |
| + |
| +class PexeLinkerImpl : public PexeLinkerInit { |
| + public: |
| + void PexeLinkerStart(ScopedMessagePipeHandle handle) override { |
| + char path[] = "native_client/toolchain/linux_x86/pnacl_translator" |
| + "/translator/x86-32-nonsfi/bin/ld.nexe"; |
|
Petr Hosek
2015/10/27 15:07:52
ditto
Sean Klein
2015/10/28 17:02:41
Done.
|
| + int nexe_fd = open(path, O_RDONLY); |
| + if (nexe_fd < 0) |
| + LOG(FATAL) << "Could not open linker nexe: " << path; |
| + ::nacl::MojoLaunchNexeNonsfi(nexe_fd, |
| + handle.release().value(), |
| + true /* enable_translate_irt */); |
| + } |
| +}; |
| + |
| +class StrongBindingPexeLinkerImpl : public PexeLinkerImpl { |
| + public: |
| + explicit StrongBindingPexeLinkerImpl(InterfaceRequest<PexeLinkerInit> request) |
| + : strong_binding_(this, request.Pass()) {} |
| + |
| + private: |
| + StrongBinding<PexeLinkerInit> strong_binding_; |
| +}; |
| + |
| +class MultiPexeLinker : public mojo::ApplicationDelegate, |
| + public mojo::InterfaceFactory<PexeLinkerInit> { |
| + public: |
| + MultiPexeLinker() {} |
| + |
| + // From ApplicationDelegate |
| + bool ConfigureIncomingConnection( |
| + mojo::ApplicationConnection* connection) override { |
| + connection->AddService<PexeLinkerInit>(this); |
| + return true; |
| + } |
| + |
| + // From InterfaceFactory |
| + void Create(mojo::ApplicationConnection* connection, |
| + mojo::InterfaceRequest<PexeLinkerInit> request) override { |
| + new StrongBindingPexeLinkerImpl(request.Pass()); |
| + } |
| +}; |
| + |
| +} // namespace nacl |
| +} // namespace mojo |
| + |
| +MojoResult MojoMain(MojoHandle application_request) { |
| + mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeLinker()); |
| + return runner.Run(application_request); |
| +} |