OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/nacl_host/nacl_process_host.h" | 7 #include "chrome/browser/nacl_host/nacl_process_host.h" |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 494 |
495 // Send over the IRT file handle. We don't close our own copy! | 495 // Send over the IRT file handle. We don't close our own copy! |
496 if (!SendHandleToSelLdr(handle(), irt_file, false, &handles_for_sel_ldr)) { | 496 if (!SendHandleToSelLdr(handle(), irt_file, false, &handles_for_sel_ldr)) { |
497 delete this; | 497 delete this; |
498 return; | 498 return; |
499 } | 499 } |
500 | 500 |
501 #if defined(OS_POSIX) | 501 #if defined(OS_POSIX) |
502 // For dynamic loading support, NaCl requires a file descriptor on an | 502 // For dynamic loading support, NaCl requires a file descriptor on an |
503 // anonymous file that can have PROT_EXEC applied to its mappings. | 503 // anonymous file that can have PROT_EXEC applied to its mappings. |
504 // Rather than requiring an extra IPC round trip out of the sandbox, | 504 // Rather than requiring an extra IPC round trip out of the sandbox, we |
505 // we create an FD here. | 505 // create an FD here. Note we're using nacl::CreateMemoryObject rather |
506 base::SharedMemory memory_buffer; | 506 // than base::SharedMemory here, because the former has code to handle |
507 if (!memory_buffer.CreateAnonymous(/* size= */ 1)) { | 507 // the Linux cases where shm_open yields objects that do not support |
| 508 // PROT_EXEC mappings. |
| 509 nacl::Handle fd = nacl::CreateMemoryObject(1, true); // size, executable |
| 510 if (fd == nacl::kInvalidHandle) { |
508 LOG(ERROR) << "Failed to allocate memory buffer"; | 511 LOG(ERROR) << "Failed to allocate memory buffer"; |
509 delete this; | 512 delete this; |
510 return; | 513 return; |
511 } | 514 } |
512 nacl::FileDescriptor memory_fd; | 515 nacl::FileDescriptor memory_fd(fd, true); |
513 memory_fd.fd = dup(memory_buffer.handle().fd); | |
514 if (memory_fd.fd < 0) { | |
515 LOG(ERROR) << "Failed to dup() a file descriptor"; | |
516 delete this; | |
517 return; | |
518 } | |
519 memory_fd.auto_close = true; | |
520 handles_for_sel_ldr.push_back(memory_fd); | 516 handles_for_sel_ldr.push_back(memory_fd); |
521 #endif | 517 #endif |
522 | 518 |
523 Send(new NaClProcessMsg_Start(handles_for_sel_ldr)); | 519 Send(new NaClProcessMsg_Start(handles_for_sel_ldr)); |
524 internal_->sockets_for_sel_ldr.clear(); | 520 internal_->sockets_for_sel_ldr.clear(); |
525 } | 521 } |
526 | 522 |
527 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { | 523 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { |
528 NOTREACHED() << "Invalid message with type = " << msg.type(); | 524 NOTREACHED() << "Invalid message with type = " << msg.type(); |
529 return false; | 525 return false; |
530 } | 526 } |
531 | 527 |
532 bool NaClProcessHost::CanShutdown() { | 528 bool NaClProcessHost::CanShutdown() { |
533 return true; | 529 return true; |
534 } | 530 } |
OLD | NEW |