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

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: 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
« services/nacl/BUILD.gn ('K') | « 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
15 namespace shell { 19 namespace shell {
16 20
17 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context) 21 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context)
18 : context_(context) { 22 : context_(context) {
19 } 23 }
20 24
21 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { 25 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() {
22 if (child_process_host_) { 26 if (child_process_host_) {
23 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been 27 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been
24 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may 28 // 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()|. 29 // not have a child process to wait on.) Probably we should fix |Join()|.
26 child_process_host_->Join(); 30 child_process_host_->Join();
27 } 31 }
28 } 32 }
29 33
34 // Determines if content handler must be run as 32 bit application
35 // based on elf header. Returns false on error.
36 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.
37 #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.
38 return true;
39 #else
40 bool require_32_bit = false;
41 char data[EI_NIDENT];
42 // Read e_ident from the elf file
43 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.
44 return false;
45 // Check the magic elf number
46 if (memcmp(data, ELFMAG, SELFMAG))
47 return false;
48 // Identify the architecture required
49 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.
50 require_32_bit = true;
51 return require_32_bit;
52 #endif
53 }
54
30 void OutOfProcessNativeRunner::Start( 55 void OutOfProcessNativeRunner::Start(
31 const base::FilePath& app_path, 56 const base::FilePath& app_path,
32 mojo::InterfaceRequest<mojo::Application> application_request, 57 mojo::InterfaceRequest<mojo::Application> application_request,
33 const base::Closure& app_completed_callback) { 58 const base::Closure& app_completed_callback) {
34 app_path_ = app_path; 59 app_path_ = app_path;
35 60
36 DCHECK(app_completed_callback_.is_null()); 61 DCHECK(app_completed_callback_.is_null());
37 app_completed_callback_ = app_completed_callback; 62 app_completed_callback_ = app_completed_callback;
38 63
39 child_process_host_.reset(new ChildProcessHost(context_)); 64 child_process_host_.reset(new ChildProcessHost(context_));
40 child_process_host_->Start(); 65 child_process_host_->Start(Require32Bit(app_path));
41 66
42 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. 67 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe.
43 child_process_host_->StartApp( 68 child_process_host_->StartApp(
44 app_path.AsUTF8Unsafe(), application_request.Pass(), 69 app_path.AsUTF8Unsafe(), application_request.Pass(),
45 base::Bind(&OutOfProcessNativeRunner::AppCompleted, 70 base::Bind(&OutOfProcessNativeRunner::AppCompleted,
46 base::Unretained(this))); 71 base::Unretained(this)));
47 } 72 }
48 73
49 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { 74 void OutOfProcessNativeRunner::AppCompleted(int32_t result) {
50 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; 75 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")";
(...skipping 10 matching lines...) Expand all
61 86
62 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( 87 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create(
63 const Options& options) { 88 const Options& options) {
64 if (options.force_in_process) 89 if (options.force_in_process)
65 return make_scoped_ptr(new InProcessNativeRunner(context_)); 90 return make_scoped_ptr(new InProcessNativeRunner(context_));
66 91
67 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); 92 return make_scoped_ptr(new OutOfProcessNativeRunner(context_));
68 } 93 }
69 94
70 } // namespace shell 95 } // namespace shell
OLDNEW
« services/nacl/BUILD.gn ('K') | « shell/child_process_host_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698