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

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

Issue 1010183002: SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip: test fix 1 Created 5 years, 8 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
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_listener.h" 5 #include "components/nacl/loader/nacl_listener.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 269 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
270 bool handled = true; 270 bool handled = true;
271 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 271 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
272 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 272 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
273 IPC_MESSAGE_UNHANDLED(handled = false) 273 IPC_MESSAGE_UNHANDLED(handled = false)
274 IPC_END_MESSAGE_MAP() 274 IPC_END_MESSAGE_MAP()
275 return handled; 275 return handled;
276 } 276 }
277 277
278 bool NaClListener::OnOpenResource(
279 const IPC::Message& msg,
280 const std::string& key,
281 NaClIPCAdapter::OpenResourceReplyCallback cb) {
282 // This callback is executed only on |io_thread_| with NaClIPCAdapter's
283 // |lock_| not being held.
284 DCHECK(!cb.is_null());
285 PrefetchedResourceFilesMap::iterator it;
286
287 // TODO(yusukes): Remove the prefix check.
288 const std::string files_prefix = "files/";
289 if (key.find(files_prefix) == 0)
290 it = prefetched_resource_files_.find(key.substr(files_prefix.length()));
291 else
292 it = prefetched_resource_files_.find(key);
293
294 if (it != prefetched_resource_files_.end()) {
295 // Fast path for prefetched FDs.
296 IPC::PlatformFileForTransit file = it->second.first;
297 base::FilePath path = it->second.second;
298 prefetched_resource_files_.erase(it);
299 // A pre-opened resource descriptor is available. Run the reply callback
300 // and return true.
301 cb.Run(msg, file, path);
302 return true;
303 }
304
305 // Return false to fall back to the slow path. Let the IPC adapter issue an
306 // IPC to the renderer.
307 return false;
308 }
309
278 void NaClListener::OnStart(const nacl::NaClStartParams& params) { 310 void NaClListener::OnStart(const nacl::NaClStartParams& params) {
279 #if defined(OS_LINUX) || defined(OS_MACOSX) 311 #if defined(OS_LINUX) || defined(OS_MACOSX)
280 int urandom_fd = dup(base::GetUrandomFD()); 312 int urandom_fd = dup(base::GetUrandomFD());
281 if (urandom_fd < 0) { 313 if (urandom_fd < 0) {
282 LOG(ERROR) << "Failed to dup() the urandom FD"; 314 LOG(ERROR) << "Failed to dup() the urandom FD";
283 return; 315 return;
284 } 316 }
285 NaClChromeMainSetUrandomFd(urandom_fd); 317 NaClChromeMainSetUrandomFd(urandom_fd);
286 #endif 318 #endif
287 struct NaClApp* nap = NULL; 319 struct NaClApp* nap = NULL;
288 NaClChromeMainInit(); 320 NaClChromeMainInit();
289 321
290 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, 322 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle,
291 false)); 323 false));
292 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 324 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
293 NaClSetFatalErrorCallback(&FatalLogHandler); 325 NaClSetFatalErrorCallback(&FatalLogHandler);
294 326
295 nap = NaClAppCreate(); 327 nap = NaClAppCreate();
296 if (nap == NULL) { 328 if (nap == NULL) {
297 LOG(ERROR) << "NaClAppCreate() failed"; 329 LOG(ERROR) << "NaClAppCreate() failed";
298 return; 330 return;
299 } 331 }
300 332
301 IPC::ChannelHandle browser_handle; 333 IPC::ChannelHandle browser_handle;
302 IPC::ChannelHandle ppapi_renderer_handle; 334 IPC::ChannelHandle ppapi_renderer_handle;
303 IPC::ChannelHandle manifest_service_handle; 335 IPC::ChannelHandle manifest_service_handle;
304 336
337 for (size_t i = 0; i < params.prefetched_resource_files.size(); ++i) {
338 bool result = prefetched_resource_files_.insert(std::make_pair(
339 params.prefetched_resource_files[i].file_key,
340 std::make_pair(
341 params.prefetched_resource_files[i].file,
342 params.prefetched_resource_files[i].file_path_metadata))).second;
343 if (!result) {
344 DLOG(ERROR) << "Duplicated open_resource key: "
345 << params.prefetched_resource_files[i].file_key;
346 }
347 }
348
305 if (params.enable_ipc_proxy) { 349 if (params.enable_ipc_proxy) {
306 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 350 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
307 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 351 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
308 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 352 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
309 353
310 // Create the PPAPI IPC channels between the NaCl IRT and the host 354 // Create the PPAPI IPC channels between the NaCl IRT and the host
311 // (browser/renderer) processes. The IRT uses these channels to 355 // (browser/renderer) processes. The IRT uses these channels to
312 // communicate with the host and to initialize the IPC dispatchers. 356 // communicate with the host and to initialize the IPC dispatchers.
313 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), 357 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
314 nap, NACL_CHROME_DESC_BASE); 358 nap, NACL_CHROME_DESC_BASE);
315 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), 359 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(),
316 nap, NACL_CHROME_DESC_BASE + 1); 360 nap, NACL_CHROME_DESC_BASE + 1);
317 361
318 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter = 362 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter =
319 SetUpIPCAdapter(&manifest_service_handle, 363 SetUpIPCAdapter(&manifest_service_handle,
320 io_thread_.message_loop_proxy(), 364 io_thread_.message_loop_proxy(),
321 nap, 365 nap,
322 NACL_CHROME_DESC_BASE + 2); 366 NACL_CHROME_DESC_BASE + 2);
323 manifest_ipc_adapter->set_resolve_file_token_callback( 367 manifest_ipc_adapter->set_resolve_file_token_callback(
Mark Seaborn 2015/04/16 19:00:31 Yesterday we discussed doing a small cleanup refac
Yusuke Sato 2015/04/16 20:22:02 Done in https://codereview.chromium.org/1090043002
324 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this))); 368 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)));
369 manifest_ipc_adapter->set_open_resource_callback(
370 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)));
325 } 371 }
326 372
327 trusted_listener_ = new NaClTrustedListener( 373 trusted_listener_ = new NaClTrustedListener(
328 IPC::Channel::GenerateVerifiedChannelID("nacl"), 374 IPC::Channel::GenerateVerifiedChannelID("nacl"),
329 io_thread_.message_loop_proxy().get(), 375 io_thread_.message_loop_proxy().get(),
330 &shutdown_event_); 376 &shutdown_event_);
331 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 377 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
332 browser_handle, 378 browser_handle,
333 ppapi_renderer_handle, 379 ppapi_renderer_handle,
334 trusted_listener_->TakeClientChannelHandle(), 380 trusted_listener_->TakeClientChannelHandle(),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (params.enable_mojo) { 477 if (params.enable_mojo) {
432 // InjectMojo adds a file descriptor to the process that allows Mojo calls 478 // InjectMojo adds a file descriptor to the process that allows Mojo calls
433 // to use an implementation defined outside the NaCl sandbox. See 479 // to use an implementation defined outside the NaCl sandbox. See
434 // //mojo/nacl for implementation details. 480 // //mojo/nacl for implementation details.
435 InjectMojo(nap); 481 InjectMojo(nap);
436 } else { 482 } else {
437 // When Mojo isn't enabled, we inject a file descriptor that intentionally 483 // When Mojo isn't enabled, we inject a file descriptor that intentionally
438 // fails on any imc_sendmsg() call to make debugging easier. 484 // fails on any imc_sendmsg() call to make debugging easier.
439 InjectDisabledMojo(nap); 485 InjectDisabledMojo(nap);
440 } 486 }
441 // TODO(yusukes): Support pre-opening resource files.
442 CHECK(params.prefetched_resource_files.empty());
443 487
444 int exit_status; 488 int exit_status;
445 if (!NaClChromeMainStart(nap, args, &exit_status)) 489 if (!NaClChromeMainStart(nap, args, &exit_status))
446 NaClExit(1); 490 NaClExit(1);
447 491
448 // Report the plugin's exit status if the application started successfully. 492 // Report the plugin's exit status if the application started successfully.
449 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); 493 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status));
450 NaClExit(exit_status); 494 NaClExit(exit_status);
451 } 495 }
452 496
453 void NaClListener::ResolveFileToken( 497 void NaClListener::ResolveFileToken(
454 uint64_t token_lo, 498 uint64_t token_lo,
455 uint64_t token_hi, 499 uint64_t token_hi,
456 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { 500 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) {
457 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { 501 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) {
458 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); 502 cb.Run(IPC::PlatformFileForTransit(), base::FilePath());
459 return; 503 return;
460 } 504 }
461 resolved_cb_ = cb; 505 resolved_cb_ = cb;
462 } 506 }
463 507
464 void NaClListener::OnFileTokenResolved( 508 void NaClListener::OnFileTokenResolved(
465 uint64_t token_lo, 509 uint64_t token_lo,
466 uint64_t token_hi, 510 uint64_t token_hi,
467 IPC::PlatformFileForTransit ipc_fd, 511 IPC::PlatformFileForTransit ipc_fd,
468 base::FilePath file_path) { 512 base::FilePath file_path) {
469 resolved_cb_.Run(ipc_fd, file_path); 513 resolved_cb_.Run(ipc_fd, file_path);
470 resolved_cb_.Reset(); 514 resolved_cb_.Reset();
471 } 515 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/renderer/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698