OLD | NEW |
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/app/nacl_fork_delegate_linux.h" | 5 #include "chrome/app/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/path_service.h" |
17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
19 #include "content/common/unix_domain_socket_posix.h" | 19 #include "content/common/unix_domain_socket_posix.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/nacl_helper_linux.h" | 22 #include "chrome/common/nacl_helper_linux.h" |
23 | 23 |
24 NaClForkDelegate::NaClForkDelegate() | 24 NaClForkDelegate::NaClForkDelegate() |
25 : status_(kNaClHelperUnused), | 25 : status_(kNaClHelperUnused), |
26 sandboxed_(false), | 26 sandboxed_(false), |
27 fd_(-1) {} | 27 fd_(-1) {} |
28 | 28 |
| 29 /* |
| 30 * Note these need to match up with their counterparts in nacl_helper_linux.c |
| 31 * and nacl_helper_bootstrap_linux.c. |
| 32 */ |
29 const char kNaClHelperAtZero[] = "--at-zero"; | 33 const char kNaClHelperAtZero[] = "--at-zero"; |
| 34 const char kNaClHelperRDebug[] = "--r_debug=0xXXXXXXXXXXXXXXXX"; |
30 | 35 |
31 void NaClForkDelegate::Init(const bool sandboxed, | 36 void NaClForkDelegate::Init(const bool sandboxed, |
32 const int browserdesc, | 37 const int browserdesc, |
33 const int sandboxdesc) { | 38 const int sandboxdesc) { |
34 VLOG(1) << "NaClForkDelegate::Init()"; | 39 VLOG(1) << "NaClForkDelegate::Init()"; |
35 int fds[2]; | 40 int fds[2]; |
36 | 41 |
37 sandboxed_ = sandboxed; | 42 sandboxed_ = sandboxed; |
38 // Confirm a couple hard-wired assumptions. | 43 // Confirm a couple hard-wired assumptions. |
39 // The NaCl constants are from chrome/nacl/nacl_linux_helper.h | 44 // The NaCl constants are from chrome/nacl/nacl_linux_helper.h |
(...skipping 12 matching lines...) Expand all Loading... |
52 status_ = kNaClHelperMissing; | 57 status_ = kNaClHelperMissing; |
53 } else if (!PathService::Get(chrome::FILE_NACL_HELPER_BOOTSTRAP, | 58 } else if (!PathService::Get(chrome::FILE_NACL_HELPER_BOOTSTRAP, |
54 &helper_bootstrap_exe)) { | 59 &helper_bootstrap_exe)) { |
55 status_ = kNaClHelperBootstrapMissing; | 60 status_ = kNaClHelperBootstrapMissing; |
56 } else if (RunningOnValgrind()) { | 61 } else if (RunningOnValgrind()) { |
57 status_ = kNaClHelperValgrind; | 62 status_ = kNaClHelperValgrind; |
58 } else { | 63 } else { |
59 CommandLine cmd_line(helper_bootstrap_exe); | 64 CommandLine cmd_line(helper_bootstrap_exe); |
60 cmd_line.AppendArgPath(helper_exe); | 65 cmd_line.AppendArgPath(helper_exe); |
61 cmd_line.AppendArgNative(kNaClHelperAtZero); | 66 cmd_line.AppendArgNative(kNaClHelperAtZero); |
| 67 cmd_line.AppendArgNative(kNaClHelperRDebug); |
62 base::LaunchOptions options; | 68 base::LaunchOptions options; |
63 options.fds_to_remap = &fds_to_map; | 69 options.fds_to_remap = &fds_to_map; |
64 options.clone_flags = CLONE_FS | SIGCHLD; | 70 options.clone_flags = CLONE_FS | SIGCHLD; |
65 if (!base::LaunchProcess(cmd_line.argv(), options, NULL)) | 71 if (!base::LaunchProcess(cmd_line.argv(), options, NULL)) |
66 status_ = kNaClHelperLaunchFailed; | 72 status_ = kNaClHelperLaunchFailed; |
67 // parent and error cases are handled below | 73 // parent and error cases are handled below |
68 } | 74 } |
69 if (HANDLE_EINTR(close(fds[1])) != 0) | 75 if (HANDLE_EINTR(close(fds[1])) != 0) |
70 LOG(ERROR) << "close(fds[1]) failed"; | 76 LOG(ERROR) << "close(fds[1]) failed"; |
71 if (status_ == kNaClHelperUnused) { | 77 if (status_ == kNaClHelperUnused) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 147 |
142 bool NaClForkDelegate::AckChild(const int fd, | 148 bool NaClForkDelegate::AckChild(const int fd, |
143 const std::string& channel_switch) { | 149 const std::string& channel_switch) { |
144 int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(), | 150 int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(), |
145 channel_switch.length())); | 151 channel_switch.length())); |
146 if (nwritten != static_cast<int>(channel_switch.length())) { | 152 if (nwritten != static_cast<int>(channel_switch.length())) { |
147 return false; | 153 return false; |
148 } | 154 } |
149 return true; | 155 return true; |
150 } | 156 } |
OLD | NEW |