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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (process_type != switches::kNaClLoaderProcess && | 256 if (process_type != switches::kNaClLoaderProcess && |
257 process_type != switches::kNaClLoaderNonSfiProcess) | 257 process_type != switches::kNaClLoaderNonSfiProcess) |
258 return false; | 258 return false; |
259 *uma_name = "NaCl.Client.Helper.StateOnFork"; | 259 *uma_name = "NaCl.Client.Helper.StateOnFork"; |
260 *uma_sample = status_; | 260 *uma_sample = status_; |
261 *uma_boundary_value = kNaClHelperStatusBoundary; | 261 *uma_boundary_value = kNaClHelperStatusBoundary; |
262 return true; | 262 return true; |
263 } | 263 } |
264 | 264 |
265 pid_t NaClForkDelegate::Fork(const std::string& process_type, | 265 pid_t NaClForkDelegate::Fork(const std::string& process_type, |
266 const std::vector<int>& fds) { | 266 const std::vector<int>& fds, |
| 267 const std::string& channel_id) { |
267 VLOG(1) << "NaClForkDelegate::Fork"; | 268 VLOG(1) << "NaClForkDelegate::Fork"; |
268 | 269 |
269 DCHECK(fds.size() == kNumPassedFDs); | 270 DCHECK(fds.size() == kNumPassedFDs); |
270 | 271 |
271 if (status_ != kNaClHelperSuccess) { | 272 if (status_ != kNaClHelperSuccess) { |
272 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; | 273 LOG(ERROR) << "Cannot launch NaCl process: nacl_helper failed to start"; |
273 return -1; | 274 return -1; |
274 } | 275 } |
275 | 276 |
276 // First, send a remote fork request. | 277 // First, send a remote fork request. |
277 Pickle write_pickle; | 278 Pickle write_pickle; |
278 write_pickle.WriteInt(nacl::kNaClForkRequest); | 279 write_pickle.WriteInt(nacl::kNaClForkRequest); |
279 // TODO(hamaji): When we split the helper binary for non-SFI mode | 280 // TODO(hamaji): When we split the helper binary for non-SFI mode |
280 // from nacl_helper, stop sending this information. | 281 // from nacl_helper, stop sending this information. |
281 const bool uses_nonsfi_mode = | 282 const bool uses_nonsfi_mode = |
282 process_type == switches::kNaClLoaderNonSfiProcess; | 283 process_type == switches::kNaClLoaderNonSfiProcess; |
283 write_pickle.WriteBool(uses_nonsfi_mode); | 284 write_pickle.WriteBool(uses_nonsfi_mode); |
| 285 write_pickle.WriteString(channel_id); |
284 | 286 |
285 char reply_buf[kNaClMaxIPCMessageLength]; | 287 char reply_buf[kNaClMaxIPCMessageLength]; |
286 ssize_t reply_size = 0; | 288 ssize_t reply_size = 0; |
287 bool got_reply = | 289 bool got_reply = |
288 SendIPCRequestAndReadReply(fd_, fds, write_pickle, | 290 SendIPCRequestAndReadReply(fd_, fds, write_pickle, |
289 reply_buf, sizeof(reply_buf), &reply_size); | 291 reply_buf, sizeof(reply_buf), &reply_size); |
290 if (!got_reply) { | 292 if (!got_reply) { |
291 LOG(ERROR) << "Could not perform remote fork."; | 293 LOG(ERROR) << "Could not perform remote fork."; |
292 return -1; | 294 return -1; |
293 } | 295 } |
294 | 296 |
295 // Now see if the other end managed to fork. | 297 // Now see if the other end managed to fork. |
296 Pickle reply_pickle(reply_buf, reply_size); | 298 Pickle reply_pickle(reply_buf, reply_size); |
297 PickleIterator iter(reply_pickle); | 299 PickleIterator iter(reply_pickle); |
298 pid_t nacl_child; | 300 pid_t nacl_child; |
299 if (!iter.ReadInt(&nacl_child)) { | 301 if (!iter.ReadInt(&nacl_child)) { |
300 LOG(ERROR) << "NaClForkDelegate::Fork: pickle failed"; | 302 LOG(ERROR) << "NaClForkDelegate::Fork: pickle failed"; |
301 return -1; | 303 return -1; |
302 } | 304 } |
303 VLOG(1) << "nacl_child is " << nacl_child; | 305 VLOG(1) << "nacl_child is " << nacl_child; |
304 return nacl_child; | 306 return nacl_child; |
305 } | 307 } |
306 | 308 |
307 bool NaClForkDelegate::AckChild(const int fd, const std::string& channel_id) { | |
308 ssize_t nwritten = | |
309 HANDLE_EINTR(write(fd, channel_id.c_str(), channel_id.length())); | |
310 if (static_cast<size_t>(nwritten) != channel_id.length()) { | |
311 return false; | |
312 } | |
313 return true; | |
314 } | |
315 | |
316 bool NaClForkDelegate::GetTerminationStatus(pid_t pid, bool known_dead, | 309 bool NaClForkDelegate::GetTerminationStatus(pid_t pid, bool known_dead, |
317 base::TerminationStatus* status, | 310 base::TerminationStatus* status, |
318 int* exit_code) { | 311 int* exit_code) { |
319 VLOG(1) << "NaClForkDelegate::GetTerminationStatus"; | 312 VLOG(1) << "NaClForkDelegate::GetTerminationStatus"; |
320 DCHECK(status); | 313 DCHECK(status); |
321 DCHECK(exit_code); | 314 DCHECK(exit_code); |
322 | 315 |
323 Pickle write_pickle; | 316 Pickle write_pickle; |
324 write_pickle.WriteInt(nacl::kNaClGetTerminationStatusRequest); | 317 write_pickle.WriteInt(nacl::kNaClGetTerminationStatusRequest); |
325 write_pickle.WriteInt(pid); | 318 write_pickle.WriteInt(pid); |
(...skipping 23 matching lines...) Expand all Loading... |
349 int remote_exit_code; | 342 int remote_exit_code; |
350 if (!iter.ReadInt(&remote_exit_code)) { | 343 if (!iter.ReadInt(&remote_exit_code)) { |
351 LOG(ERROR) << "GetTerminationStatus: pickle failed"; | 344 LOG(ERROR) << "GetTerminationStatus: pickle failed"; |
352 return false; | 345 return false; |
353 } | 346 } |
354 | 347 |
355 *status = static_cast<base::TerminationStatus>(termination_status); | 348 *status = static_cast<base::TerminationStatus>(termination_status); |
356 *exit_code = remote_exit_code; | 349 *exit_code = remote_exit_code; |
357 return true; | 350 return true; |
358 } | 351 } |
OLD | NEW |