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 "components/nacl/zygote/nacl_fork_delegate_linux.h" | 5 #include "components/nacl/zygote/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> |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 return false; | 99 return false; |
100 } | 100 } |
101 *reply_size = msg_len; | 101 *reply_size = msg_len; |
102 return true; | 102 return true; |
103 } | 103 } |
104 | 104 |
105 } // namespace. | 105 } // namespace. |
106 | 106 |
107 NaClForkDelegate::NaClForkDelegate() | 107 NaClForkDelegate::NaClForkDelegate() |
108 : status_(kNaClHelperUnused), | 108 : status_(kNaClHelperUnused), |
109 fd_(-1) {} | 109 fd_(-1), |
110 uses_nonsfi_mode_(false) {} | |
Mark Seaborn
2014/03/31 17:19:59
Not used
hamaji
2014/04/01 06:53:09
Oops, removed.
| |
110 | 111 |
111 void NaClForkDelegate::Init(const int sandboxdesc) { | 112 void NaClForkDelegate::Init(const int sandboxdesc) { |
112 VLOG(1) << "NaClForkDelegate::Init()"; | 113 VLOG(1) << "NaClForkDelegate::Init()"; |
113 int fds[2]; | 114 int fds[2]; |
114 | 115 |
115 // For communications between the NaCl loader process and | 116 // For communications between the NaCl loader process and |
116 // the SUID sandbox. | 117 // the SUID sandbox. |
117 int nacl_sandbox_descriptor = | 118 int nacl_sandbox_descriptor = |
118 base::GlobalDescriptors::kBaseDescriptor + kSandboxIPCChannel; | 119 base::GlobalDescriptors::kBaseDescriptor + kSandboxIPCChannel; |
119 // Confirm a hard-wired assumption. | 120 // Confirm a hard-wired assumption. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 if (status_ == kNaClHelperSuccess) { | 246 if (status_ == kNaClHelperSuccess) { |
246 if (IGNORE_EINTR(close(fd_)) != 0) | 247 if (IGNORE_EINTR(close(fd_)) != 0) |
247 LOG(ERROR) << "close(fd_) failed"; | 248 LOG(ERROR) << "close(fd_) failed"; |
248 } | 249 } |
249 } | 250 } |
250 | 251 |
251 bool NaClForkDelegate::CanHelp(const std::string& process_type, | 252 bool NaClForkDelegate::CanHelp(const std::string& process_type, |
252 std::string* uma_name, | 253 std::string* uma_name, |
253 int* uma_sample, | 254 int* uma_sample, |
254 int* uma_boundary_value) { | 255 int* uma_boundary_value) { |
255 if (process_type != switches::kNaClLoaderProcess) | 256 if (process_type != switches::kNaClLoaderProcess && |
257 process_type != switches::kNaClLoaderNonSfiProcess) | |
256 return false; | 258 return false; |
259 uses_nonsfi_mode_ = process_type == switches::kNaClLoaderNonSfiProcess; | |
Mark Seaborn
2014/03/31 17:19:59
Ditto
hamaji
2014/04/01 06:53:09
Done.
| |
257 *uma_name = "NaCl.Client.Helper.StateOnFork"; | 260 *uma_name = "NaCl.Client.Helper.StateOnFork"; |
258 *uma_sample = status_; | 261 *uma_sample = status_; |
259 *uma_boundary_value = kNaClHelperStatusBoundary; | 262 *uma_boundary_value = kNaClHelperStatusBoundary; |
260 return true; | 263 return true; |
261 } | 264 } |
262 | 265 |
263 pid_t NaClForkDelegate::Fork(const std::vector<int>& fds) { | 266 pid_t NaClForkDelegate::Fork(const std::string& process_type, |
267 const std::vector<int>& fds) { | |
264 VLOG(1) << "NaClForkDelegate::Fork"; | 268 VLOG(1) << "NaClForkDelegate::Fork"; |
265 | 269 |
266 DCHECK(fds.size() == kNumPassedFDs); | 270 DCHECK(fds.size() == kNumPassedFDs); |
267 | 271 |
268 if (status_ != kNaClHelperSuccess) { | 272 if (status_ != kNaClHelperSuccess) { |
269 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; | 273 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; |
270 return -1; | 274 return -1; |
271 } | 275 } |
272 | 276 |
273 // First, send a remote fork request. | 277 // First, send a remote fork request. |
274 Pickle write_pickle; | 278 Pickle write_pickle; |
275 write_pickle.WriteInt(nacl::kNaClForkRequest); | 279 write_pickle.WriteInt(nacl::kNaClForkRequest); |
280 // We decide whether we will use SFI mode or non-SFI based on the | |
Mark Seaborn
2014/03/31 17:19:59
This might be considered obvious from the code, so
hamaji
2014/04/01 06:53:09
Done.
| |
281 // process type. | |
282 // TODO(hamaji): When we split the helper binary for non-SFI mode | |
283 // from nacl_helper, stop sending this information. | |
284 const bool uses_nonsfi_mode = | |
285 process_type == switches::kNaClLoaderNonSfiProcess; | |
286 write_pickle.WriteBool(uses_nonsfi_mode); | |
276 | 287 |
277 char reply_buf[kNaClMaxIPCMessageLength]; | 288 char reply_buf[kNaClMaxIPCMessageLength]; |
278 ssize_t reply_size = 0; | 289 ssize_t reply_size = 0; |
279 bool got_reply = | 290 bool got_reply = |
280 SendIPCRequestAndReadReply(fd_, fds, write_pickle, | 291 SendIPCRequestAndReadReply(fd_, fds, write_pickle, |
281 reply_buf, sizeof(reply_buf), &reply_size); | 292 reply_buf, sizeof(reply_buf), &reply_size); |
282 if (!got_reply) { | 293 if (!got_reply) { |
283 LOG(ERROR) << "Could not perform remote fork."; | 294 LOG(ERROR) << "Could not perform remote fork."; |
284 return -1; | 295 return -1; |
285 } | 296 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 int remote_exit_code; | 353 int remote_exit_code; |
343 if (!iter.ReadInt(&remote_exit_code)) { | 354 if (!iter.ReadInt(&remote_exit_code)) { |
344 LOG(ERROR) << "GetTerminationStatus: pickle failed"; | 355 LOG(ERROR) << "GetTerminationStatus: pickle failed"; |
345 return false; | 356 return false; |
346 } | 357 } |
347 | 358 |
348 *status = static_cast<base::TerminationStatus>(termination_status); | 359 *status = static_cast<base::TerminationStatus>(termination_status); |
349 *exit_code = remote_exit_code; | 360 *exit_code = remote_exit_code; |
350 return true; | 361 return true; |
351 } | 362 } |
OLD | NEW |