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

Side by Side Diff: components/nacl/loader/nacl_ipc_adapter.cc

Issue 897363002: NaCl: Clean up to use the public API for creating validation-cacheable descs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « components/nacl/loader/DEPS ('k') | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/loader/nacl_ipc_adapter.h" 5 #include "components/nacl/loader/nacl_ipc_adapter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "ipc/ipc_channel.h" 17 #include "ipc/ipc_channel.h"
18 #include "ipc/ipc_platform_file.h" 18 #include "ipc/ipc_platform_file.h"
19 #include "native_client/src/public/nacl_desc.h"
19 #include "native_client/src/trusted/desc/nacl_desc_base.h" 20 #include "native_client/src/trusted/desc/nacl_desc_base.h"
20 #include "native_client/src/trusted/desc/nacl_desc_custom.h" 21 #include "native_client/src/trusted/desc/nacl_desc_custom.h"
21 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h" 22 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h"
22 #include "native_client/src/trusted/desc/nacl_desc_io.h" 23 #include "native_client/src/trusted/desc/nacl_desc_io.h"
23 #include "native_client/src/trusted/desc/nacl_desc_quota.h" 24 #include "native_client/src/trusted/desc/nacl_desc_quota.h"
24 #include "native_client/src/trusted/desc/nacl_desc_quota_interface.h" 25 #include "native_client/src/trusted/desc/nacl_desc_quota_interface.h"
25 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h" 26 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h"
26 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
27 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 27 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
28 #include "native_client/src/trusted/validator/rich_file_info.h"
29 #include "ppapi/c/ppb_file_io.h" 28 #include "ppapi/c/ppb_file_io.h"
30 #include "ppapi/proxy/ppapi_messages.h" 29 #include "ppapi/proxy/ppapi_messages.h"
31 #include "ppapi/proxy/serialized_handle.h" 30 #include "ppapi/proxy/serialized_handle.h"
32 31
33 using ppapi::proxy::NaClMessageScanner; 32 using ppapi::proxy::NaClMessageScanner;
34 33
35 namespace { 34 namespace {
36 35
37 enum BufferSizeStatus { 36 enum BufferSizeStatus {
38 // The buffer contains a full message with no extra bytes. 37 // The buffer contains a full message with no extra bytes.
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 SaveMessage(*new_msg, rewritten_msg.get()); 657 SaveMessage(*new_msg, rewritten_msg.get());
659 cond_var_.Signal(); 658 cond_var_.Signal();
660 } 659 }
661 return; 660 return;
662 } 661 }
663 662
664 // The file token was sucessfully resolved. 663 // The file token was sucessfully resolved.
665 std::string file_path_str = file_path.AsUTF8Unsafe(); 664 std::string file_path_str = file_path.AsUTF8Unsafe();
666 base::PlatformFile handle = 665 base::PlatformFile handle =
667 IPC::PlatformFileForTransitToPlatformFile(ipc_fd); 666 IPC::PlatformFileForTransitToPlatformFile(ipc_fd);
668 // The file token was resolved successfully, so we populate the new
669 // NaClDesc with that information.
670 char* alloc_file_path = static_cast<char*>(
671 malloc(file_path_str.length() + 1));
672 strcpy(alloc_file_path, file_path_str.c_str());
673 scoped_ptr<NaClDescWrapper> desc_wrapper(new NaClDescWrapper(
674 NaClDescIoDescFromHandleAllocCtor(handle, NACL_ABI_O_RDONLY)));
675
676 // Mark the desc as OK for mapping as executable memory.
677 NaClDescMarkSafeForMmap(desc_wrapper->desc());
678
679 // Provide metadata for validation.
680 struct NaClRichFileInfo info;
681 NaClRichFileInfoCtor(&info);
682 info.known_file = 1;
683 info.file_path = alloc_file_path; // Takes ownership.
684 info.file_path_length =
685 static_cast<uint32_t>(file_path_str.length());
686 NaClSetFileOriginInfo(desc_wrapper->desc(), &info);
687 NaClRichFileInfoDtor(&info);
688 667
689 ppapi::proxy::SerializedHandle sh; 668 ppapi::proxy::SerializedHandle sh;
690 sh.set_file_handle(ipc_fd, PP_FILEOPENFLAG_READ, 0); 669 sh.set_file_handle(ipc_fd, PP_FILEOPENFLAG_READ, 0);
691 scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh); 670 scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh);
692 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); 671 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage);
693 672
694 rewritten_msg->AddDescriptor(desc_wrapper.release()); 673 struct NaClDesc* desc =
674 NaClDescCreateWithFilePathMetadata(handle, file_path_str.c_str());
675 rewritten_msg->AddDescriptor(new NaClDescWrapper(desc));
695 { 676 {
696 base::AutoLock lock(lock_); 677 base::AutoLock lock(lock_);
697 SaveMessage(*new_msg, rewritten_msg.get()); 678 SaveMessage(*new_msg, rewritten_msg.get());
698 cond_var_.Signal(); 679 cond_var_.Signal();
699 } 680 }
700 } 681 }
701 682
702 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { 683 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) {
703 } 684 }
704 685
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 header.flags = msg.flags(); 807 header.flags = msg.flags();
827 header.num_fds = static_cast<uint16>(rewritten_msg->desc_count()); 808 header.num_fds = static_cast<uint16>(rewritten_msg->desc_count());
828 809
829 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); 810 rewritten_msg->SetData(header, msg.payload(), msg.payload_size());
830 locked_data_.to_be_received_.push(rewritten_msg); 811 locked_data_.to_be_received_.push(rewritten_msg);
831 } 812 }
832 813
833 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { 814 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) {
834 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); 815 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags);
835 } 816 }
OLDNEW
« no previous file with comments | « components/nacl/loader/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698