Chromium Code Reviews| 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_(false) {} | |
| 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::kNaClNonSfiLoaderProcess) | |
| 256 return false; | 258 return false; |
| 259 // We decide whether we will use SFI mode or non-SFI for the next | |
| 260 // run based on the process type here. | |
| 261 // TODO(hamaji): Have two helpers in content::Zygote and each | |
| 262 // NaClForkDelegate should focus on a single mode. This must be done | |
| 263 // when we split the helper binary for non-SFI mode from | |
| 264 // nacl_helper. Once this has been done, we can remove this check | |
| 265 // and uses_nonsfi_ field. | |
| 266 uses_nonsfi_ = process_type == switches::kNaClNonSfiLoaderProcess; | |
|
hamaji
2014/03/14 12:46:23
This would be probably the most doubtful change in
| |
| 257 *uma_name = "NaCl.Client.Helper.StateOnFork"; | 267 *uma_name = "NaCl.Client.Helper.StateOnFork"; |
| 258 *uma_sample = status_; | 268 *uma_sample = status_; |
| 259 *uma_boundary_value = kNaClHelperStatusBoundary; | 269 *uma_boundary_value = kNaClHelperStatusBoundary; |
| 260 return true; | 270 return true; |
| 261 } | 271 } |
| 262 | 272 |
| 263 pid_t NaClForkDelegate::Fork(const std::vector<int>& fds) { | 273 pid_t NaClForkDelegate::Fork(const std::vector<int>& fds) { |
| 264 VLOG(1) << "NaClForkDelegate::Fork"; | 274 VLOG(1) << "NaClForkDelegate::Fork"; |
| 265 | 275 |
| 266 DCHECK(fds.size() == kNumPassedFDs); | 276 DCHECK(fds.size() == kNumPassedFDs); |
| 267 | 277 |
| 268 if (status_ != kNaClHelperSuccess) { | 278 if (status_ != kNaClHelperSuccess) { |
| 269 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; | 279 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; |
| 270 return -1; | 280 return -1; |
| 271 } | 281 } |
| 272 | 282 |
| 273 // First, send a remote fork request. | 283 // First, send a remote fork request. |
| 274 Pickle write_pickle; | 284 Pickle write_pickle; |
| 275 write_pickle.WriteInt(nacl::kNaClForkRequest); | 285 write_pickle.WriteInt(nacl::kNaClForkRequest); |
| 286 // Tell nacl_helper whether it should use SFI mode or non-SFI mode. | |
| 287 // TODO(hamaji): Remove this once we have splitted nacl_helper into | |
| 288 // two helper binaries. See the comment in CanHelp as well. | |
| 289 write_pickle.WriteBool(uses_nonsfi_); | |
| 276 | 290 |
| 277 char reply_buf[kNaClMaxIPCMessageLength]; | 291 char reply_buf[kNaClMaxIPCMessageLength]; |
| 278 ssize_t reply_size = 0; | 292 ssize_t reply_size = 0; |
| 279 bool got_reply = | 293 bool got_reply = |
| 280 SendIPCRequestAndReadReply(fd_, fds, write_pickle, | 294 SendIPCRequestAndReadReply(fd_, fds, write_pickle, |
| 281 reply_buf, sizeof(reply_buf), &reply_size); | 295 reply_buf, sizeof(reply_buf), &reply_size); |
| 282 if (!got_reply) { | 296 if (!got_reply) { |
| 283 LOG(ERROR) << "Could not perform remote fork."; | 297 LOG(ERROR) << "Could not perform remote fork."; |
| 284 return -1; | 298 return -1; |
| 285 } | 299 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 int remote_exit_code; | 356 int remote_exit_code; |
| 343 if (!iter.ReadInt(&remote_exit_code)) { | 357 if (!iter.ReadInt(&remote_exit_code)) { |
| 344 LOG(ERROR) << "GetTerminationStatus: pickle failed"; | 358 LOG(ERROR) << "GetTerminationStatus: pickle failed"; |
| 345 return false; | 359 return false; |
| 346 } | 360 } |
| 347 | 361 |
| 348 *status = static_cast<base::TerminationStatus>(termination_status); | 362 *status = static_cast<base::TerminationStatus>(termination_status); |
| 349 *exit_code = remote_exit_code; | 363 *exit_code = remote_exit_code; |
| 350 return true; | 364 return true; |
| 351 } | 365 } |
| OLD | NEW |