| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (msg_len <= 0) { | 101 if (msg_len <= 0) { |
| 102 LOG(ERROR) << "SendIPCRequestAndReadReply: RecvMsg failed"; | 102 LOG(ERROR) << "SendIPCRequestAndReadReply: RecvMsg failed"; |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 *reply_size = msg_len; | 105 *reply_size = msg_len; |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace. | 109 } // namespace. |
| 110 | 110 |
| 111 NaClForkDelegate::NaClForkDelegate() | 111 NaClForkDelegate::NaClForkDelegate(bool nonsfi_mode) |
| 112 : status_(kNaClHelperUnused), | 112 : nonsfi_mode_(nonsfi_mode), status_(kNaClHelperUnused), fd_(-1) { |
| 113 fd_(-1) {} | 113 } |
| 114 | 114 |
| 115 void NaClForkDelegate::Init(const int sandboxdesc, | 115 void NaClForkDelegate::Init(const int sandboxdesc, |
| 116 const bool enable_layer1_sandbox) { | 116 const bool enable_layer1_sandbox) { |
| 117 VLOG(1) << "NaClForkDelegate::Init()"; | 117 VLOG(1) << "NaClForkDelegate::Init()"; |
| 118 int fds[2]; | 118 int fds[2]; |
| 119 | 119 |
| 120 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client( | 120 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client( |
| 121 sandbox::SetuidSandboxClient::Create()); | 121 sandbox::SetuidSandboxClient::Create()); |
| 122 | 122 |
| 123 // For communications between the NaCl loader process and | 123 // For communications between the NaCl loader process and |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // TODO(bradchen): Make this LOG(ERROR) when the NaCl helper | 255 // TODO(bradchen): Make this LOG(ERROR) when the NaCl helper |
| 256 // becomes the default. | 256 // becomes the default. |
| 257 fd_ = -1; | 257 fd_ = -1; |
| 258 if (IGNORE_EINTR(close(fds[0])) != 0) | 258 if (IGNORE_EINTR(close(fds[0])) != 0) |
| 259 LOG(ERROR) << "close(fds[0]) failed"; | 259 LOG(ERROR) << "close(fds[0]) failed"; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void NaClForkDelegate::InitialUMA(std::string* uma_name, | 262 void NaClForkDelegate::InitialUMA(std::string* uma_name, |
| 263 int* uma_sample, | 263 int* uma_sample, |
| 264 int* uma_boundary_value) { | 264 int* uma_boundary_value) { |
| 265 *uma_name = "NaCl.Client.Helper.InitState"; | 265 *uma_name = nonsfi_mode_ ? "NaCl.Client.HelperNonSFI.InitState" |
| 266 : "NaCl.Client.Helper.InitState"; |
| 266 *uma_sample = status_; | 267 *uma_sample = status_; |
| 267 *uma_boundary_value = kNaClHelperStatusBoundary; | 268 *uma_boundary_value = kNaClHelperStatusBoundary; |
| 268 } | 269 } |
| 269 | 270 |
| 270 NaClForkDelegate::~NaClForkDelegate() { | 271 NaClForkDelegate::~NaClForkDelegate() { |
| 271 // side effect of close: delegate process will terminate | 272 // side effect of close: delegate process will terminate |
| 272 if (status_ == kNaClHelperSuccess) { | 273 if (status_ == kNaClHelperSuccess) { |
| 273 if (IGNORE_EINTR(close(fd_)) != 0) | 274 if (IGNORE_EINTR(close(fd_)) != 0) |
| 274 LOG(ERROR) << "close(fd_) failed"; | 275 LOG(ERROR) << "close(fd_) failed"; |
| 275 } | 276 } |
| 276 } | 277 } |
| 277 | 278 |
| 278 bool NaClForkDelegate::CanHelp(const std::string& process_type, | 279 bool NaClForkDelegate::CanHelp(const std::string& process_type, |
| 279 std::string* uma_name, | 280 std::string* uma_name, |
| 280 int* uma_sample, | 281 int* uma_sample, |
| 281 int* uma_boundary_value) { | 282 int* uma_boundary_value) { |
| 282 if (process_type != switches::kNaClLoaderProcess && | 283 // We can only help with a specific process type depending on nonsfi_mode_. |
| 283 process_type != switches::kNaClLoaderNonSfiProcess) | 284 const char* helpable_process_type = nonsfi_mode_ |
| 285 ? switches::kNaClLoaderNonSfiProcess |
| 286 : switches::kNaClLoaderProcess; |
| 287 if (process_type != helpable_process_type) |
| 284 return false; | 288 return false; |
| 285 *uma_name = "NaCl.Client.Helper.StateOnFork"; | 289 *uma_name = nonsfi_mode_ ? "NaCl.Client.HelperNonSFI.StateOnFork" |
| 290 : "NaCl.Client.Helper.StateOnFork"; |
| 286 *uma_sample = status_; | 291 *uma_sample = status_; |
| 287 *uma_boundary_value = kNaClHelperStatusBoundary; | 292 *uma_boundary_value = kNaClHelperStatusBoundary; |
| 288 return true; | 293 return true; |
| 289 } | 294 } |
| 290 | 295 |
| 291 pid_t NaClForkDelegate::Fork(const std::string& process_type, | 296 pid_t NaClForkDelegate::Fork(const std::string& process_type, |
| 292 const std::vector<int>& fds, | 297 const std::vector<int>& fds, |
| 293 const std::string& channel_id) { | 298 const std::string& channel_id) { |
| 294 VLOG(1) << "NaClForkDelegate::Fork"; | 299 VLOG(1) << "NaClForkDelegate::Fork"; |
| 295 | 300 |
| 296 DCHECK(fds.size() == kNumPassedFDs); | 301 DCHECK(fds.size() == kNumPassedFDs); |
| 297 | 302 |
| 298 if (status_ != kNaClHelperSuccess) { | 303 if (status_ != kNaClHelperSuccess) { |
| 299 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; | 304 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; |
| 300 return -1; | 305 return -1; |
| 301 } | 306 } |
| 302 | 307 |
| 303 // First, send a remote fork request. | 308 // First, send a remote fork request. |
| 304 Pickle write_pickle; | 309 Pickle write_pickle; |
| 305 write_pickle.WriteInt(nacl::kNaClForkRequest); | 310 write_pickle.WriteInt(nacl::kNaClForkRequest); |
| 306 // TODO(hamaji): When we split the helper binary for non-SFI mode | 311 write_pickle.WriteBool(nonsfi_mode_); |
| 307 // from nacl_helper, stop sending this information. | |
| 308 const bool uses_nonsfi_mode = | |
| 309 process_type == switches::kNaClLoaderNonSfiProcess; | |
| 310 write_pickle.WriteBool(uses_nonsfi_mode); | |
| 311 write_pickle.WriteString(channel_id); | 312 write_pickle.WriteString(channel_id); |
| 312 | 313 |
| 313 char reply_buf[kNaClMaxIPCMessageLength]; | 314 char reply_buf[kNaClMaxIPCMessageLength]; |
| 314 ssize_t reply_size = 0; | 315 ssize_t reply_size = 0; |
| 315 bool got_reply = | 316 bool got_reply = |
| 316 SendIPCRequestAndReadReply(fd_, fds, write_pickle, | 317 SendIPCRequestAndReadReply(fd_, fds, write_pickle, |
| 317 reply_buf, sizeof(reply_buf), &reply_size); | 318 reply_buf, sizeof(reply_buf), &reply_size); |
| 318 if (!got_reply) { | 319 if (!got_reply) { |
| 319 LOG(ERROR) << "Could not perform remote fork."; | 320 LOG(ERROR) << "Could not perform remote fork."; |
| 320 return -1; | 321 return -1; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 int remote_exit_code; | 369 int remote_exit_code; |
| 369 if (!iter.ReadInt(&remote_exit_code)) { | 370 if (!iter.ReadInt(&remote_exit_code)) { |
| 370 LOG(ERROR) << "GetTerminationStatus: pickle failed"; | 371 LOG(ERROR) << "GetTerminationStatus: pickle failed"; |
| 371 return false; | 372 return false; |
| 372 } | 373 } |
| 373 | 374 |
| 374 *status = static_cast<base::TerminationStatus>(termination_status); | 375 *status = static_cast<base::TerminationStatus>(termination_status); |
| 375 *exit_code = remote_exit_code; | 376 *exit_code = remote_exit_code; |
| 376 return true; | 377 return true; |
| 377 } | 378 } |
| OLD | NEW |