Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 8574065: Use nacl::CreateMemoryObject to create dynamic code shared memory object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698