Commit 88df4926 authored by mseaborn's avatar mseaborn Committed by Commit bot

NaCl: Clean up to use the public API for creating validation-cacheable descs

Use the API that's defined in native_client/src/public/.  That is
already used by nacl_listener.cc, but the code in nacl_ipc_adapter.cc
was written earlier, before the API in public/ was added.

NaClDescCreateWithFilePathMetadata() does the same as the code we're
replacing here.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=4073
TEST=browser_tests

Review URL: https://codereview.chromium.org/897363002

Cr-Commit-Position: refs/heads/master@{#315049}
parent b700b43d
......@@ -16,7 +16,6 @@ include_rules = [
"+native_client/src/trusted/desc",
"+native_client/src/trusted/service_runtime/include",
"+native_client/src/trusted/service_runtime/nacl_error_code.h",
"+native_client/src/trusted/validator/rich_file_info.h",
"+native_client/src/trusted/validator/validation_cache.h",
"+native_client/src/untrusted/irt/irt.h",
......
......@@ -16,6 +16,7 @@
#include "build/build_config.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_platform_file.h"
#include "native_client/src/public/nacl_desc.h"
#include "native_client/src/trusted/desc/nacl_desc_base.h"
#include "native_client/src/trusted/desc/nacl_desc_custom.h"
#include "native_client/src/trusted/desc/nacl_desc_imc_shm.h"
......@@ -23,9 +24,7 @@
#include "native_client/src/trusted/desc/nacl_desc_quota.h"
#include "native_client/src/trusted/desc/nacl_desc_quota_interface.h"
#include "native_client/src/trusted/desc/nacl_desc_sync_socket.h"
#include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
#include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
#include "native_client/src/trusted/validator/rich_file_info.h"
#include "ppapi/c/ppb_file_io.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_handle.h"
......@@ -665,33 +664,15 @@ void NaClIPCAdapter::OnFileTokenResolved(const IPC::Message& orig_msg,
std::string file_path_str = file_path.AsUTF8Unsafe();
base::PlatformFile handle =
IPC::PlatformFileForTransitToPlatformFile(ipc_fd);
// The file token was resolved successfully, so we populate the new
// NaClDesc with that information.
char* alloc_file_path = static_cast<char*>(
malloc(file_path_str.length() + 1));
strcpy(alloc_file_path, file_path_str.c_str());
scoped_ptr<NaClDescWrapper> desc_wrapper(new NaClDescWrapper(
NaClDescIoDescFromHandleAllocCtor(handle, NACL_ABI_O_RDONLY)));
// Mark the desc as OK for mapping as executable memory.
NaClDescMarkSafeForMmap(desc_wrapper->desc());
// Provide metadata for validation.
struct NaClRichFileInfo info;
NaClRichFileInfoCtor(&info);
info.known_file = 1;
info.file_path = alloc_file_path; // Takes ownership.
info.file_path_length =
static_cast<uint32_t>(file_path_str.length());
NaClSetFileOriginInfo(desc_wrapper->desc(), &info);
NaClRichFileInfoDtor(&info);
ppapi::proxy::SerializedHandle sh;
sh.set_file_handle(ipc_fd, PP_FILEOPENFLAG_READ, 0);
scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh);
scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage);
rewritten_msg->AddDescriptor(desc_wrapper.release());
struct NaClDesc* desc =
NaClDescCreateWithFilePathMetadata(handle, file_path_str.c_str());
rewritten_msg->AddDescriptor(new NaClDescWrapper(desc));
{
base::AutoLock lock(lock_);
SaveMessage(*new_msg, rewritten_msg.get());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment