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

Side by Side Diff: chrome/nacl/nacl_fork_delegate_linux.cc

Issue 7655010: Reserve 1GB at the base of the address space of linux nacl_helper for Native Client module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/nacl.gypi ('k') | chrome/nacl/nacl_helper_bootstrap_linux.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/nacl_fork_delegate_linux.h" 5 #include "chrome/common/nacl_fork_delegate_linux.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/eintr_wrapper.h" 13 #include "base/eintr_wrapper.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/path_service.h"
16 #include "base/process_util.h" 17 #include "base/process_util.h"
17 #include "content/common/unix_domain_socket_posix.h" 18 #include "content/common/unix_domain_socket_posix.h"
18 #include "content/common/zygote_fork_delegate_linux.h" 19 #include "content/common/zygote_fork_delegate_linux.h"
20 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/nacl_helper_linux.h" 22 #include "chrome/common/nacl_helper_linux.h"
21 23
22 NaClForkDelegate::NaClForkDelegate() 24 NaClForkDelegate::NaClForkDelegate()
23 : ready_(false), 25 : ready_(false),
24 sandboxed_(false), 26 sandboxed_(false),
25 fd_(-1) {} 27 fd_(-1) {}
26 28
27 void NaClForkDelegate::Init(const bool sandboxed, 29 void NaClForkDelegate::Init(const bool sandboxed,
28 const int browserdesc, 30 const int browserdesc,
29 const int sandboxdesc) { 31 const int sandboxdesc) {
30 VLOG(1) << "NaClForkDelegate::Init()"; 32 VLOG(1) << "NaClForkDelegate::Init()";
31 int fds[2]; 33 int fds[2];
32 34
33 sandboxed_ = sandboxed; 35 sandboxed_ = sandboxed;
34 // Confirm a couple hard-wired assumptions. 36 // Confirm a couple hard-wired assumptions.
35 // The NaCl constants are from chrome/nacl/nacl_linux_helper.h 37 // The NaCl constants are from chrome/nacl/nacl_linux_helper.h
36 DCHECK(kNaClBrowserDescriptor == browserdesc); 38 DCHECK(kNaClBrowserDescriptor == browserdesc);
37 DCHECK(kNaClSandboxDescriptor == sandboxdesc); 39 DCHECK(kNaClSandboxDescriptor == sandboxdesc);
38 40
39 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); 41 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0);
40 base::file_handle_mapping_vector fds_to_map; 42 base::file_handle_mapping_vector fds_to_map;
41 fds_to_map.push_back(std::make_pair(fds[1], kNaClZygoteDescriptor)); 43 fds_to_map.push_back(std::make_pair(fds[1], kNaClZygoteDescriptor));
42 fds_to_map.push_back(std::make_pair(sandboxdesc, kNaClSandboxDescriptor)); 44 fds_to_map.push_back(std::make_pair(sandboxdesc, kNaClSandboxDescriptor));
43 // TODO(bradchen): Before making this the default for release builds, 45 // TODO(bradchen): To make this the default for release builds,
44 // replace command line switch with PathService::Get(). 46 // remove command line switch.
45 const std::string nacl_zygote_exe =
46 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
47 switches::kNaClLinuxHelper);
48 ready_ = false; 47 ready_ = false;
49 if (nacl_zygote_exe.length() != 0) { 48 const bool use_helper = CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kNaClLinuxHelper);
50 FilePath helper_exe;
51 if (use_helper && PathService::Get(chrome::FILE_NACL_HELPER, &helper_exe)) {
50 CommandLine::StringVector argv = CommandLine::ForCurrentProcess()->argv(); 52 CommandLine::StringVector argv = CommandLine::ForCurrentProcess()->argv();
51 argv[0] = nacl_zygote_exe; 53 argv[0] = helper_exe.value();
52 base::LaunchOptions options; 54 base::LaunchOptions options;
53 options.fds_to_remap = &fds_to_map; 55 options.fds_to_remap = &fds_to_map;
54 options.clone_flags = CLONE_FS | SIGCHLD; 56 options.clone_flags = CLONE_FS | SIGCHLD;
57 // LD_BIND_NOW forces non-lazy binding in the dynamic linker, to
58 // prevent the linker from trying to look at the text of the nacl_helper
59 // program after it has been replaced by the nacl module.
60 base::environment_vector env;
61 env.push_back(std::make_pair("LD_BIND_NOW", "1"));
62 options.environ = &env;
55 ready_ = base::LaunchProcess(argv, options, NULL); 63 ready_ = base::LaunchProcess(argv, options, NULL);
56 // parent and error cases are handled below 64 // parent and error cases are handled below
57 } 65 }
58 if (HANDLE_EINTR(close(fds[1])) != 0) 66 if (HANDLE_EINTR(close(fds[1])) != 0)
59 LOG(ERROR) << "close(fds[1]) failed"; 67 LOG(ERROR) << "close(fds[1]) failed";
60 if (ready_) { 68 if (ready_) {
61 const ssize_t kExpectedLength = strlen(kNaClHelperStartupAck); 69 const ssize_t kExpectedLength = strlen(kNaClHelperStartupAck);
62 char buf[kExpectedLength]; 70 char buf[kExpectedLength];
63 71
64 // Wait for ack from nacl_helper, indicating it is ready to help 72 // Wait for ack from nacl_helper, indicating it is ready to help
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 120
113 bool NaClForkDelegate::AckChild(const int fd, 121 bool NaClForkDelegate::AckChild(const int fd,
114 const std::string& channel_switch) { 122 const std::string& channel_switch) {
115 int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(), 123 int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(),
116 channel_switch.length())); 124 channel_switch.length()));
117 if (nwritten != static_cast<int>(channel_switch.length())) { 125 if (nwritten != static_cast<int>(channel_switch.length())) {
118 return false; 126 return false;
119 } 127 }
120 return true; 128 return true;
121 } 129 }
OLDNEW
« no previous file with comments | « chrome/nacl.gypi ('k') | chrome/nacl/nacl_helper_bootstrap_linux.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698