OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/nacl/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/resource.h> | 9 #include <sys/resource.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
11 | 11 |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/posix/eintr_wrapper.h" | 19 #include "base/posix/eintr_wrapper.h" |
20 #include "base/posix/unix_domain_socket_linux.h" | 20 #include "base/posix/unix_domain_socket_linux.h" |
21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
23 #include "chrome/common/chrome_paths.h" | 23 #include "components/nacl/common/nacl_delegate.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "components/nacl/common/nacl_helper_linux.h" |
25 #include "chrome/common/nacl_helper_linux.h" | 25 #include "components/nacl/common/nacl_paths.h" |
| 26 #include "components/nacl/common/nacl_switches.h" |
26 | 27 |
27 NaClForkDelegate::NaClForkDelegate() | 28 NaClForkDelegate::NaClForkDelegate() |
28 : status_(kNaClHelperUnused), | 29 : status_(kNaClHelperUnused), |
29 fd_(-1) {} | 30 fd_(-1) {} |
30 | 31 |
31 // Note these need to match up with their counterparts in nacl_helper_linux.c | 32 // Note these need to match up with their counterparts in nacl_helper_linux.c |
32 // and nacl_helper_bootstrap_linux.c. | 33 // and nacl_helper_bootstrap_linux.c. |
33 const char kNaClHelperReservedAtZero[] = | 34 const char kNaClHelperReservedAtZero[] = |
34 "--reserved_at_zero=0xXXXXXXXXXXXXXXXX"; | 35 "--reserved_at_zero=0xXXXXXXXXXXXXXXXX"; |
35 const char kNaClHelperRDebug[] = "--r_debug=0xXXXXXXXXXXXXXXXX"; | 36 const char kNaClHelperRDebug[] = "--r_debug=0xXXXXXXXXXXXXXXXX"; |
36 | 37 |
37 void NaClForkDelegate::Init(const int sandboxdesc) { | 38 void NaClForkDelegate::Init(const int sandboxdesc) { |
38 VLOG(1) << "NaClForkDelegate::Init()"; | 39 VLOG(1) << "NaClForkDelegate::Init()"; |
39 int fds[2]; | 40 int fds[2]; |
40 | 41 |
41 // Confirm a hard-wired assumption. | 42 // Confirm a hard-wired assumption. |
42 // The NaCl constant is from chrome/nacl/nacl_linux_helper.h | 43 // The NaCl constant is from components/nacl/loader/nacl_linux_helper.h |
43 DCHECK(kNaClSandboxDescriptor == sandboxdesc); | 44 DCHECK(kNaClSandboxDescriptor == sandboxdesc); |
44 | 45 |
45 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); | 46 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); |
46 base::FileHandleMappingVector fds_to_map; | 47 base::FileHandleMappingVector fds_to_map; |
47 fds_to_map.push_back(std::make_pair(fds[1], kNaClZygoteDescriptor)); | 48 fds_to_map.push_back(std::make_pair(fds[1], kNaClZygoteDescriptor)); |
48 fds_to_map.push_back(std::make_pair(sandboxdesc, kNaClSandboxDescriptor)); | 49 fds_to_map.push_back(std::make_pair(sandboxdesc, kNaClSandboxDescriptor)); |
49 | 50 |
50 status_ = kNaClHelperUnused; | 51 status_ = kNaClHelperUnused; |
51 base::FilePath helper_exe; | 52 base::FilePath helper_exe; |
52 base::FilePath helper_bootstrap_exe; | 53 base::FilePath helper_bootstrap_exe; |
53 if (!PathService::Get(chrome::FILE_NACL_HELPER, &helper_exe)) { | 54 if (!PathService::Get(nacl::FILE_NACL_HELPER, &helper_exe)) { |
54 status_ = kNaClHelperMissing; | 55 status_ = kNaClHelperMissing; |
55 } else if (!PathService::Get(chrome::FILE_NACL_HELPER_BOOTSTRAP, | 56 } else if (!PathService::Get(nacl::FILE_NACL_HELPER_BOOTSTRAP, |
56 &helper_bootstrap_exe)) { | 57 &helper_bootstrap_exe)) { |
57 status_ = kNaClHelperBootstrapMissing; | 58 status_ = kNaClHelperBootstrapMissing; |
58 } else if (RunningOnValgrind()) { | 59 } else if (RunningOnValgrind()) { |
59 status_ = kNaClHelperValgrind; | 60 status_ = kNaClHelperValgrind; |
60 } else { | 61 } else { |
61 CommandLine cmd_line(helper_bootstrap_exe); | 62 CommandLine cmd_line(helper_bootstrap_exe); |
62 cmd_line.AppendArgPath(helper_exe); | 63 cmd_line.AppendArgPath(helper_exe); |
63 cmd_line.AppendArgNative(kNaClHelperReservedAtZero); | 64 cmd_line.AppendArgNative(kNaClHelperReservedAtZero); |
64 cmd_line.AppendArgNative(kNaClHelperRDebug); | 65 cmd_line.AppendArgNative(kNaClHelperRDebug); |
65 base::LaunchOptions options; | 66 base::LaunchOptions options; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 156 |
156 bool NaClForkDelegate::AckChild(const int fd, | 157 bool NaClForkDelegate::AckChild(const int fd, |
157 const std::string& channel_switch) { | 158 const std::string& channel_switch) { |
158 int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(), | 159 int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(), |
159 channel_switch.length())); | 160 channel_switch.length())); |
160 if (nwritten != static_cast<int>(channel_switch.length())) { | 161 if (nwritten != static_cast<int>(channel_switch.length())) { |
161 return false; | 162 return false; |
162 } | 163 } |
163 return true; | 164 return true; |
164 } | 165 } |
OLD | NEW |