OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
8 #endif | 8 #endif |
9 | 9 |
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
11 | 11 |
12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "native_client/src/include/nacl_base.h" | 19 #include "native_client/src/include/nacl_base.h" |
20 #include "native_client/src/include/nacl_macros.h" | 20 #include "native_client/src/include/nacl_macros.h" |
21 #include "native_client/src/include/nacl_scoped_ptr.h" | 21 #include "native_client/src/include/nacl_scoped_ptr.h" |
22 #include "native_client/src/include/nacl_string.h" | 22 #include "native_client/src/include/nacl_string.h" |
23 #include "native_client/src/include/portability.h" | 23 #include "native_client/src/include/portability.h" |
24 #include "native_client/src/include/portability_io.h" | 24 #include "native_client/src/include/portability_io.h" |
25 #include "native_client/src/include/portability_string.h" | 25 #include "native_client/src/include/portability_string.h" |
26 #include "native_client/src/public/nacl_file_info.h" | |
26 #include "native_client/src/shared/platform/nacl_check.h" | 27 #include "native_client/src/shared/platform/nacl_check.h" |
27 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 28 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
28 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 29 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
29 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 30 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
30 | 31 |
31 #include "ppapi/c/pp_errors.h" | 32 #include "ppapi/c/pp_errors.h" |
32 #include "ppapi/c/ppb_var.h" | 33 #include "ppapi/c/ppb_var.h" |
33 #include "ppapi/c/private/ppb_nacl_private.h" | 34 #include "ppapi/c/private/ppb_nacl_private.h" |
34 #include "ppapi/cpp/dev/url_util_dev.h" | 35 #include "ppapi/cpp/dev/url_util_dev.h" |
35 #include "ppapi/cpp/module.h" | 36 #include "ppapi/cpp/module.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 callback_factory_.Initialize(this); | 369 callback_factory_.Initialize(this); |
369 nacl_interface_ = GetNaClInterface(); | 370 nacl_interface_ = GetNaClInterface(); |
370 CHECK(nacl_interface_ != NULL); | 371 CHECK(nacl_interface_ != NULL); |
371 | 372 |
372 // Notify PPB_NaCl_Private that the instance is created before altering any | 373 // Notify PPB_NaCl_Private that the instance is created before altering any |
373 // state that it tracks. | 374 // state that it tracks. |
374 nacl_interface_->InstanceCreated(pp_instance); | 375 nacl_interface_->InstanceCreated(pp_instance); |
375 // We call set_exit_status() here to ensure that the 'exitStatus' property is | 376 // We call set_exit_status() here to ensure that the 'exitStatus' property is |
376 // set. This can only be called when nacl_interface_ is not NULL. | 377 // set. This can only be called when nacl_interface_ is not NULL. |
377 set_exit_status(-1); | 378 set_exit_status(-1); |
379 memset(&nexe_file_info_, 0, sizeof nexe_file_info_); | |
380 nexe_file_info_.desc = -1; | |
378 } | 381 } |
379 | 382 |
380 | 383 |
381 Plugin::~Plugin() { | 384 Plugin::~Plugin() { |
382 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); | 385 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); |
383 | 386 |
384 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p)\n", | 387 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p)\n", |
385 static_cast<void*>(this))); | 388 static_cast<void*>(this))); |
386 // Destroy the coordinator while the rest of the data is still there | 389 // Destroy the coordinator while the rest of the data is still there |
387 pnacl_coordinator_.reset(NULL); | 390 pnacl_coordinator_.reset(NULL); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 static_cast<void*>(this))); | 442 static_cast<void*>(this))); |
440 // We don't know if the plugin will handle the document load, but return | 443 // We don't know if the plugin will handle the document load, but return |
441 // true in order to give it a chance to respond once the proxy is started. | 444 // true in order to give it a chance to respond once the proxy is started. |
442 return true; | 445 return true; |
443 } | 446 } |
444 | 447 |
445 void Plugin::NexeFileDidOpen(int32_t pp_error) { | 448 void Plugin::NexeFileDidOpen(int32_t pp_error) { |
446 if (pp_error != PP_OK) | 449 if (pp_error != PP_OK) |
447 return; | 450 return; |
448 | 451 |
449 int32_t desc = ConvertFileDescriptor(nexe_handle_); | 452 nexe_file_info_.desc = ConvertFileDescriptor(nexe_handle_); |
teravest
2014/05/21 16:49:42
I'm a little confused why nexe_file_info_ needs to
jvoung (off chromium)
2014/05/21 21:10:56
It was mostly to avoid heap allocating the NaClFil
| |
450 nexe_handle_ = PP_kInvalidFileHandle; // Clear out nexe handle. | 453 nexe_handle_ = PP_kInvalidFileHandle; // Clear out nexe handle. |
451 | 454 |
455 NaClDesc *desc = NaClDescIoFromFileInfo(nexe_file_info_, O_RDONLY); | |
456 if (desc == NULL) | |
457 return; | |
458 // nexe_file_info_ is handed to desc, clear out old copy. | |
459 memset(&nexe_file_info_, 0, sizeof nexe_file_info_); | |
460 nexe_file_info_.desc = -1; | |
452 nacl::scoped_ptr<nacl::DescWrapper> | 461 nacl::scoped_ptr<nacl::DescWrapper> |
453 wrapper(wrapper_factory()->MakeFileDesc(desc, O_RDONLY)); | 462 wrapper(wrapper_factory()->MakeGenericCleanup(desc)); |
454 NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n"); | 463 NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n"); |
455 LoadNaClModule( | 464 LoadNaClModule( |
456 wrapper.release(), | 465 wrapper.release(), |
457 uses_nonsfi_mode_, | 466 uses_nonsfi_mode_, |
458 true, /* enable_dyncode_syscalls */ | 467 true, /* enable_dyncode_syscalls */ |
459 true, /* enable_exception_handling */ | 468 true, /* enable_exception_handling */ |
460 false, /* enable_crash_throttling */ | 469 false, /* enable_crash_throttling */ |
461 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation), | 470 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation), |
462 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); | 471 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); |
463 } | 472 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 pnacl_options, | 576 pnacl_options, |
568 translate_callback)); | 577 translate_callback)); |
569 return; | 578 return; |
570 } else { | 579 } else { |
571 pp::CompletionCallback open_callback = | 580 pp::CompletionCallback open_callback = |
572 callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); | 581 callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); |
573 // Will always call the callback on success or failure. | 582 // Will always call the callback on success or failure. |
574 nacl_interface_->DownloadNexe(pp_instance(), | 583 nacl_interface_->DownloadNexe(pp_instance(), |
575 program_url_.c_str(), | 584 program_url_.c_str(), |
576 &nexe_handle_, | 585 &nexe_handle_, |
586 &nexe_file_info_.file_token.lo, | |
587 &nexe_file_info_.file_token.hi, | |
577 open_callback.pp_completion_callback()); | 588 open_callback.pp_completion_callback()); |
578 return; | 589 return; |
579 } | 590 } |
580 } | 591 } |
581 } | 592 } |
582 | 593 |
583 void Plugin::RequestNaClManifest(const nacl::string& url) { | 594 void Plugin::RequestNaClManifest(const nacl::string& url) { |
584 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str())); | 595 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str())); |
585 pp::CompletionCallback open_callback = | 596 pp::CompletionCallback open_callback = |
586 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen); | 597 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 | 823 |
813 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 824 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
814 int exit_status) { | 825 int exit_status) { |
815 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 826 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
816 DCHECK(nacl_interface_); | 827 DCHECK(nacl_interface_); |
817 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 828 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
818 } | 829 } |
819 | 830 |
820 | 831 |
821 } // namespace plugin | 832 } // namespace plugin |
OLD | NEW |