Index: shell/out_of_process_native_runner.cc |
diff --git a/shell/out_of_process_native_runner.cc b/shell/out_of_process_native_runner.cc |
index 39cf1f7003abfef747ed59f21afdebf9d08b04ab..4100b48293ef99134a82305e6ac751e7443000d2 100644 |
--- a/shell/out_of_process_native_runner.cc |
+++ b/shell/out_of_process_native_runner.cc |
@@ -4,10 +4,14 @@ |
#include "shell/out_of_process_native_runner.h" |
+#include <elf.h> |
+#include <string> |
+ |
#include "base/bind.h" |
#include "base/callback_helpers.h" |
#include "base/files/file_util.h" |
#include "base/logging.h" |
+#include "base/strings/string_util.h" |
#include "shell/child_controller.mojom.h" |
#include "shell/child_process_host.h" |
#include "shell/in_process_native_runner.h" |
@@ -27,6 +31,27 @@ OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { |
} |
} |
+// Determines if content handler must be run as 32 bit application |
+// based on elf header. Returns false on error. |
+bool Require32Bit(const base::FilePath& app_path) { |
Mark Seaborn
2015/09/15 22:25:43
This could go in an anon namespace.
Sean Klein
2015/09/15 22:56:05
Done.
|
+#if defined(ARCH_CPU_32_BITS) |
Mark Seaborn
2015/09/15 22:25:43
You could use "if (sizeof(void *) == 4)". This wa
Sean Klein
2015/09/15 22:56:05
Using "sizeof(void *) == 4", along with a comment.
|
+ return true; |
+#else |
+ bool require_32_bit = false; |
+ char data[EI_NIDENT]; |
+ // Read e_ident from the elf file |
+ if (EI_NIDENT != ReadFile(app_path, data, sizeof(data))) |
Mark Seaborn
2015/09/15 22:25:43
Nit: Also "EI_NIDENT" -> "sizeof(data)" (as before
Sean Klein
2015/09/15 22:56:05
Done.
|
+ return false; |
+ // Check the magic elf number |
+ if (memcmp(data, ELFMAG, SELFMAG)) |
+ return false; |
+ // Identify the architecture required |
+ if (data[EI_CLASS] == ELFCLASS32) |
Mark Seaborn
2015/09/15 22:25:43
Can simplify to:
return data[EI_CLASS] == ELFCLASS
Sean Klein
2015/09/15 22:56:05
Done.
|
+ require_32_bit = true; |
+ return require_32_bit; |
+#endif |
+} |
+ |
void OutOfProcessNativeRunner::Start( |
const base::FilePath& app_path, |
mojo::InterfaceRequest<mojo::Application> application_request, |
@@ -37,7 +62,7 @@ void OutOfProcessNativeRunner::Start( |
app_completed_callback_ = app_completed_callback; |
child_process_host_.reset(new ChildProcessHost(context_)); |
- child_process_host_->Start(); |
+ child_process_host_->Start(Require32Bit(app_path)); |
// TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. |
child_process_host_->StartApp( |