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

Side by Side Diff: shell/out_of_process_native_runner.cc

Issue 1341873002: Enabling 64-bit mojo shell to launch 32-bit child to handle nonsfi content. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Anonymous namespaces and modified target names Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « shell/child_process_host_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "shell/out_of_process_native_runner.h" 5 #include "shell/out_of_process_native_runner.h"
6 6
7 #include <elf.h>
8 #include <string>
9
7 #include "base/bind.h" 10 #include "base/bind.h"
8 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
9 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
10 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_util.h"
11 #include "shell/child_controller.mojom.h" 15 #include "shell/child_controller.mojom.h"
12 #include "shell/child_process_host.h" 16 #include "shell/child_process_host.h"
13 #include "shell/in_process_native_runner.h" 17 #include "shell/in_process_native_runner.h"
14 18
19 namespace {
20
21 // Determines if content handler must be run as 32 bit application
22 // based on elf header. Returns false on error.
23 bool Require32Bit(const base::FilePath& app_path) {
24 if (sizeof(void*) == 4) {
25 // CPU arch is already 32 bits
26 return true;
27 } else {
28 char data[EI_NIDENT];
29 // Read e_ident from the elf file
30 if (sizeof(data) != ReadFile(app_path, data, sizeof(data))) {
31 DCHECK(false);
32 return false;
33 }
34 // Check the magic elf number
35 if (memcmp(data, ELFMAG, SELFMAG)) {
36 DCHECK(false);
37 return false;
38 }
39 // Identify the architecture required
40 return data[EI_CLASS] == ELFCLASS32;
41 }
42 }
43
44 } // namespace
45
15 namespace shell { 46 namespace shell {
16 47
17 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context) 48 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context)
18 : context_(context) { 49 : context_(context) {
19 } 50 }
20 51
21 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { 52 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() {
22 if (child_process_host_) { 53 if (child_process_host_) {
23 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been 54 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been
24 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may 55 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may
25 // not have a child process to wait on.) Probably we should fix |Join()|. 56 // not have a child process to wait on.) Probably we should fix |Join()|.
26 child_process_host_->Join(); 57 child_process_host_->Join();
27 } 58 }
28 } 59 }
29 60
30 void OutOfProcessNativeRunner::Start( 61 void OutOfProcessNativeRunner::Start(
31 const base::FilePath& app_path, 62 const base::FilePath& app_path,
32 mojo::InterfaceRequest<mojo::Application> application_request, 63 mojo::InterfaceRequest<mojo::Application> application_request,
33 const base::Closure& app_completed_callback) { 64 const base::Closure& app_completed_callback) {
34 app_path_ = app_path; 65 app_path_ = app_path;
35 66
36 DCHECK(app_completed_callback_.is_null()); 67 DCHECK(app_completed_callback_.is_null());
37 app_completed_callback_ = app_completed_callback; 68 app_completed_callback_ = app_completed_callback;
38 69
39 child_process_host_.reset(new ChildProcessHost(context_)); 70 child_process_host_.reset(new ChildProcessHost(context_));
40 child_process_host_->Start(); 71 child_process_host_->Start(Require32Bit(app_path));
41 72
42 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. 73 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe.
43 child_process_host_->StartApp( 74 child_process_host_->StartApp(
44 app_path.AsUTF8Unsafe(), application_request.Pass(), 75 app_path.AsUTF8Unsafe(), application_request.Pass(),
45 base::Bind(&OutOfProcessNativeRunner::AppCompleted, 76 base::Bind(&OutOfProcessNativeRunner::AppCompleted,
46 base::Unretained(this))); 77 base::Unretained(this)));
47 } 78 }
48 79
49 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { 80 void OutOfProcessNativeRunner::AppCompleted(int32_t result) {
50 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; 81 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")";
(...skipping 10 matching lines...) Expand all
61 92
62 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( 93 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create(
63 const Options& options) { 94 const Options& options) {
64 if (options.force_in_process) 95 if (options.force_in_process)
65 return make_scoped_ptr(new InProcessNativeRunner(context_)); 96 return make_scoped_ptr(new InProcessNativeRunner(context_));
66 97
67 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); 98 return make_scoped_ptr(new OutOfProcessNativeRunner(context_));
68 } 99 }
69 100
70 } // namespace shell 101 } // namespace shell
OLDNEW
« no previous file with comments | « shell/child_process_host_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698