Refactored launching of nexes to separate file.
This CL should be useful for the translation steps, as each of
1) Translating
2) Linking, and
3) Launching the translated nexe
will require a new nexe launching step. Ideally the communication
between the content handler and any necessary child nexes can occur
through the MojoHandle.
BUG=https://github.com/domokit/mojo/issues/396
R=mseaborn@chromium.org
Review URL: https://codereview.chromium.org/1371413003 .
diff --git a/mojo/nacl/BUILD.gn b/mojo/nacl/BUILD.gn
index 22d8849..0a89622 100644
--- a/mojo/nacl/BUILD.gn
+++ b/mojo/nacl/BUILD.gn
@@ -93,9 +93,11 @@
sources = [
"irt_mojo_nonsfi.cc",
"irt_mojo_nonsfi.h",
+ "nexe_launcher_nonsfi.cc",
]
deps = [
+ "//base",
"//mojo/public/c/system",
"//mojo/public/platform/nacl:mojo_irt_header",
"//native_client/src/nonsfi/irt:irt_interfaces",
diff --git a/mojo/nacl/nexe_launcher_nonsfi.cc b/mojo/nacl/nexe_launcher_nonsfi.cc
new file mode 100644
index 0000000..c76b0a1
--- /dev/null
+++ b/mojo/nacl/nexe_launcher_nonsfi.cc
@@ -0,0 +1,30 @@
+// 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 "mojo/nacl/nexe_launcher_nonsfi.h"
+
+#include "base/files/file_util.h"
+#include "mojo/nacl/irt_mojo_nonsfi.h"
+#include "mojo/public/c/system/types.h"
+#include "native_client/src/public/irt_core.h"
+#include "native_client/src/public/nonsfi/elf_loader.h"
+
+namespace nacl {
+
+void MojoLaunchNexeNonsfi(int nexe_fd, MojoHandle initial_handle) {
+ // Run -- also, closes the nexe_fd, removing the temp file.
+ uintptr_t entry = NaClLoadElfFile(nexe_fd);
+
+ MojoSetInitialHandle(initial_handle);
+ int argc = 1;
+ char* argvp = const_cast<char*>("NaClMain");
+ char* envp = nullptr;
+ nacl_irt_nonsfi_entry(argc, &argvp, &envp,
+ reinterpret_cast<nacl_entry_func_t>(entry),
+ MojoIrtNonsfiQuery);
+ abort();
+ NOTREACHED();
+}
+
+} // namespace nacl
diff --git a/mojo/nacl/nexe_launcher_nonsfi.h b/mojo/nacl/nexe_launcher_nonsfi.h
new file mode 100644
index 0000000..97b7274
--- /dev/null
+++ b/mojo/nacl/nexe_launcher_nonsfi.h
@@ -0,0 +1,20 @@
+// 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.
+
+#ifndef MOJO_NACL_NEXE_LAUNCHER_NONSFI_H_
+#define MOJO_NACL_NEXE_LAUNCHER_NONSFI_H_
+
+#include "mojo/public/c/system/types.h"
+
+namespace nacl {
+
+/**
+ * Takes a fd to a nexe, and launches the nexe with the given
+ * MojoHandle.
+ */
+void MojoLaunchNexeNonsfi(int nexe_fd, MojoHandle initial_handle);
+
+} // namespace nacl
+
+#endif // MOJO_NACL_NEXE_LAUNCHER_NONSFI_H_
diff --git a/services/nacl/content_handler_main_nonsfi.cc b/services/nacl/content_handler_main_nonsfi.cc
index 62a907d..9c9a9b9 100644
--- a/services/nacl/content_handler_main_nonsfi.cc
+++ b/services/nacl/content_handler_main_nonsfi.cc
@@ -9,11 +9,9 @@
#include "mojo/application/content_handler_factory.h"
#include "mojo/data_pipe_utils/data_pipe_utils.h"
#include "mojo/message_pump/message_pump_mojo.h"
-#include "mojo/nacl/irt_mojo_nonsfi.h"
+#include "mojo/nacl/nexe_launcher_nonsfi.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl.h"
-#include "native_client/src/public/irt_core.h"
-#include "native_client/src/public/nonsfi/elf_loader.h"
namespace nacl {
namespace content_handler {
@@ -59,19 +57,10 @@
LOG(FATAL) << "Failed to close temp file";
}
- // Run -- also, closes the fd, removing the temp file.
- uintptr_t entry = NaClLoadElfFile(fd);
-
- MojoSetInitialHandle(
- application_request.PassMessagePipe().release().value());
- int argc = 1;
- char* argvp = const_cast<char*>("NaClMain");
- char* envp = nullptr;
- nacl_irt_nonsfi_entry(argc, &argvp, &envp,
- reinterpret_cast<nacl_entry_func_t>(entry),
- MojoIrtNonsfiQuery);
- abort();
- NOTREACHED();
+ MojoHandle handle =
+ application_request.PassMessagePipe().release().value();
+ // MojoLaunchNexeNonsfi takes ownership of the fd.
+ MojoLaunchNexeNonsfi(fd, handle);
}
mojo::ContentHandlerFactory content_handler_factory_;