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

Unified Diff: services/nacl/pnacl_compile.cc

Issue 1382713002: Creating a pexe content handler to translate and run pexes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Added Mojom interface to communicate with translation nexes 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 side-by-side diff with in-line comments
Download patch
Index: services/nacl/pnacl_compile.cc
diff --git a/services/nacl/pnacl_compile.cc b/services/nacl/pnacl_compile.cc
new file mode 100644
index 0000000000000000000000000000000000000000..468ee860edf89282e3aa1449e0bdc203b5b00c95
--- /dev/null
+++ b/services/nacl/pnacl_compile.cc
@@ -0,0 +1,69 @@
+// 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_compile.mojom.h"
+
+namespace mojo {
+namespace nacl {
+
+class PexeCompilerImpl : public PexeCompilerInit {
+ public:
+ void PexeCompilerStart(ScopedMessagePipeHandle handle) override {
+ char path[] = "native_client/toolchain/linux_x86/pnacl_translator"
Mark Seaborn 2015/10/27 17:30:21 You want "static const char kPath[]". "char path[
Sean Klein 2015/10/28 17:02:41 Done.
+ "/translator/x86-32-nonsfi/bin/pnacl-llc.nexe";
Petr Hosek 2015/10/27 15:07:52 Hardcoding this path makes it difficult to test or
Sean Klein 2015/10/28 17:02:41 I totally agree -- Updated irt_mojo_nonsfi, pnacl_
+ int nexe_fd = open(path, O_RDONLY);
+ if (nexe_fd < 0)
+ LOG(FATAL) << "Could not open compiler nexe: " << path;
+ ::nacl::MojoLaunchNexeNonsfi(nexe_fd,
+ handle.release().value(),
+ true /* enable_translate_irt */);
+ }
+};
+
+class StrongBindingPexeCompilerImpl : public PexeCompilerImpl {
+ public:
+ explicit StrongBindingPexeCompilerImpl(InterfaceRequest<PexeCompilerInit>
+ request)
+ : strong_binding_(this, request.Pass()) {}
+
+ private:
+ StrongBinding<PexeCompilerInit> strong_binding_;
+};
+
+class MultiPexeCompiler : public mojo::ApplicationDelegate,
+ public mojo::InterfaceFactory<PexeCompilerInit> {
+ public:
+ MultiPexeCompiler() {}
+
+ // From ApplicationDelegate
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) override {
+ connection->AddService<PexeCompilerInit>(this);
+ return true;
+ }
+
+ // From InterfaceFactory
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<PexeCompilerInit> request) override {
+ new StrongBindingPexeCompilerImpl(request.Pass());
+ }
+};
+
+} // namespace nacl
+} // namespace mojo
+
+MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeCompiler());
+ return runner.Run(application_request);
+}

Powered by Google App Engine
This is Rietveld 408576698