| Index: ppapi/native_client/src/trusted/plugin/plugin.cc
|
| diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc
|
| index d497fb32cd9356618a628f9fa87f1e8a22f0555d..16e28e36a3b26be192516e79916deecc42cfbcca 100644
|
| --- a/ppapi/native_client/src/trusted/plugin/plugin.cc
|
| +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc
|
| @@ -286,78 +286,69 @@ void Plugin::HistogramHTTPStatusCode(const std::string& name,
|
| HistogramEnumerate(name, sample, 7, 6);
|
| }
|
|
|
| -bool Plugin::LoadNaClModuleCommon(nacl::DescWrapper* wrapper,
|
| - NaClSubprocess* subprocess,
|
| - const Manifest* manifest,
|
| - bool should_report_uma,
|
| - const SelLdrStartParams& params,
|
| - const pp::CompletionCallback& init_done_cb,
|
| - const pp::CompletionCallback& crash_cb) {
|
| - ErrorInfo error_info;
|
| - ServiceRuntime* new_service_runtime =
|
| - new ServiceRuntime(this, manifest, should_report_uma, init_done_cb,
|
| - crash_cb);
|
| - subprocess->set_service_runtime(new_service_runtime);
|
| +void Plugin::StartSelLdrOnMainThread(int32_t pp_error,
|
| + ServiceRuntime* service_runtime,
|
| + const SelLdrStartParams& params,
|
| + PP_CompletionCallback callback) {
|
| + service_runtime->StartSelLdr(params, callback);
|
| +}
|
| +
|
| +void Plugin::SignalStartSelLdrDone(int32_t pp_error,
|
| + ServiceRuntime* service_runtime) {
|
| + PLUGIN_PRINTF(("Plugin::SignalStartSelLdrDone (this=%p, pp_error=%"
|
| + NACL_PRId32 ")\n", static_cast<void*>(this), pp_error));
|
| + start_sel_ldr_success_ = (pp_error == PP_OK);
|
| + service_runtime->SignalStartSelLdrDone();
|
| +}
|
| +
|
| +bool Plugin::LoadNaClModuleFromBackgroundThread(
|
| + nacl::DescWrapper* wrapper,
|
| + NaClSubprocess* subprocess,
|
| + const Manifest* manifest,
|
| + const SelLdrStartParams& params) {
|
| + ServiceRuntime* service_runtime =
|
| + new ServiceRuntime(this, manifest, false, pp::BlockUntilComplete(),
|
| + pp::BlockUntilComplete());
|
| + subprocess->set_service_runtime(service_runtime);
|
| PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (service_runtime=%p)\n",
|
| - static_cast<void*>(new_service_runtime)));
|
| - if (should_report_uma && NULL == new_service_runtime) {
|
| - error_info.SetReport(
|
| - ERROR_SEL_LDR_INIT,
|
| - "sel_ldr init failure " + subprocess->description());
|
| - ReportLoadError(error_info);
|
| + static_cast<void*>(service_runtime)));
|
| + if (NULL == service_runtime) {
|
| return false;
|
| }
|
|
|
| // Now start the SelLdr instance. This must be created on the main thread.
|
| pp::Core* core = pp::Module::Get()->core();
|
| - bool service_runtime_started;
|
| - if (core->IsMainThread()) {
|
| - StartSelLdrOnMainThread(PP_OK, new_service_runtime, params,
|
| - &service_runtime_started);
|
| - } else {
|
| - pp::CompletionCallback callback =
|
| - callback_factory_.NewCallback(&Plugin::StartSelLdrOnMainThread,
|
| - new_service_runtime, params,
|
| - &service_runtime_started);
|
| - core->CallOnMainThread(0, callback, 0);
|
| - new_service_runtime->WaitForSelLdrStart();
|
| - }
|
| - PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (service_runtime_started=%d)\n",
|
| - service_runtime_started));
|
| - if (!service_runtime_started) {
|
| + pp::CompletionCallback connected_callback =
|
| + callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone,
|
| + service_runtime);
|
| + pp::CompletionCallback callback = callback_factory_.NewCallback(
|
| + &Plugin::StartSelLdrOnMainThread, service_runtime, params,
|
| + connected_callback.pp_completion_callback());
|
| + core->CallOnMainThread(0, callback, 0);
|
| + service_runtime->WaitForSelLdrStart();
|
| + if (!start_sel_ldr_success_) {
|
| return false;
|
| }
|
|
|
| // Now actually load the nexe, which can happen on a background thread.
|
| - bool nexe_loaded = new_service_runtime->LoadNexeAndStart(wrapper,
|
| - crash_cb);
|
| + bool nexe_loaded = service_runtime->LoadNexeAndStart(
|
| + wrapper, pp::BlockUntilComplete());
|
| PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (nexe_loaded=%d)\n",
|
| nexe_loaded));
|
| return nexe_loaded;
|
| }
|
|
|
| -void Plugin::StartSelLdrOnMainThread(int32_t pp_error,
|
| - ServiceRuntime* service_runtime,
|
| - const SelLdrStartParams& params,
|
| - bool* success) {
|
| - if (pp_error != PP_OK) {
|
| - PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg "
|
| - "-- SHOULD NOT HAPPEN\n"));
|
| - *success = false;
|
| - return;
|
| - }
|
| - *success = service_runtime->StartSelLdr(params);
|
| - // Signal outside of StartSelLdr here, so that the write to *success
|
| - // is done before signaling.
|
| - service_runtime->SignalStartSelLdrDone();
|
| -}
|
| -
|
| void Plugin::LoadNaClModule(nacl::DescWrapper* wrapper,
|
| bool enable_dyncode_syscalls,
|
| bool enable_exception_handling,
|
| bool enable_crash_throttling,
|
| const pp::CompletionCallback& init_done_cb,
|
| const pp::CompletionCallback& crash_cb) {
|
| + nacl::scoped_ptr<nacl::DescWrapper> scoped_wrapper(wrapper);
|
| + pp::Core* core = pp::Module::Get()->core();
|
| + DCHECK(core->IsMainThread());
|
| +
|
| + ErrorInfo error_info;
|
| // Before forking a new sel_ldr process, ensure that we do not leak
|
| // the ServiceRuntime object for an existing subprocess, and that any
|
| // associated listener threads do not go unjoined because if they
|
| @@ -370,11 +361,44 @@ void Plugin::LoadNaClModule(nacl::DescWrapper* wrapper,
|
| enable_dyncode_syscalls,
|
| enable_exception_handling,
|
| enable_crash_throttling);
|
| - if (LoadNaClModuleCommon(wrapper, &main_subprocess_, manifest_.get(),
|
| - true /* should_report_uma */,
|
| - params, init_done_cb, crash_cb)) {
|
| - PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n",
|
| - main_subprocess_.detailed_description().c_str()));
|
| + ServiceRuntime* service_runtime =
|
| + new ServiceRuntime(this, manifest_.get(), true, init_done_cb, crash_cb);
|
| + main_subprocess_.set_service_runtime(service_runtime);
|
| + PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n",
|
| + static_cast<void*>(service_runtime)));
|
| + if (NULL == service_runtime) {
|
| + error_info.SetReport(
|
| + ERROR_SEL_LDR_INIT,
|
| + "sel_ldr init failure " + main_subprocess_.description());
|
| + ReportLoadError(error_info);
|
| + return;
|
| + }
|
| +
|
| + pp::CompletionCallback callback = callback_factory_.NewCallback(
|
| + &Plugin::LoadNexeOnMainThread,
|
| + service_runtime, scoped_wrapper.release(), crash_cb);
|
| + StartSelLdrOnMainThread(PP_OK, service_runtime, params,
|
| + callback.pp_completion_callback());
|
| +}
|
| +
|
| +void Plugin::LoadNexeOnMainThread(int32_t pp_error,
|
| + ServiceRuntime* service_runtime,
|
| + nacl::DescWrapper* wrapper,
|
| + const pp::CompletionCallback& crash_cb) {
|
| + nacl::scoped_ptr<nacl::DescWrapper> scoped_wrapper(wrapper);
|
| + fprintf(stderr, "Plugin::LoadNexeOnMainThread\n");
|
| + ErrorInfo error_info;
|
| + if (pp_error != PP_OK) {
|
| + error_info.SetReport(
|
| + ERROR_SEL_LDR_INIT,
|
| + "sel_ldr start failure " + main_subprocess_.description());
|
| + ReportLoadError(error_info);
|
| + return;
|
| + }
|
| +
|
| + bool nexe_loaded = service_runtime->LoadNexeAndStart(wrapper, crash_cb);
|
| + if (nexe_loaded) {
|
| + PLUGIN_PRINTF(("Plugin::LoadNaClModule (nexe_loaded=%d)\n", nexe_loaded));
|
| }
|
| }
|
|
|
| @@ -419,6 +443,8 @@ bool Plugin::LoadNaClModuleContinuationIntern(ErrorInfo* error_info) {
|
| NaClSubprocess* Plugin::LoadHelperNaClModule(nacl::DescWrapper* wrapper,
|
| const Manifest* manifest,
|
| ErrorInfo* error_info) {
|
| + pp::Core* core = pp::Module::Get()->core();
|
| + DCHECK(!core->IsMainThread());
|
| nacl::scoped_ptr<NaClSubprocess> nacl_subprocess(
|
| new NaClSubprocess("helper module", NULL, NULL));
|
| if (NULL == nacl_subprocess.get()) {
|
| @@ -440,11 +466,10 @@ NaClSubprocess* Plugin::LoadHelperNaClModule(nacl::DescWrapper* wrapper,
|
| false /* enable_dyncode_syscalls */,
|
| false /* enable_exception_handling */,
|
| true /* enable_crash_throttling */);
|
| - if (!LoadNaClModuleCommon(wrapper, nacl_subprocess.get(), manifest,
|
| - false /* should_report_uma */,
|
| - params,
|
| - pp::BlockUntilComplete(),
|
| - pp::BlockUntilComplete())) {
|
| + if (!LoadNaClModuleFromBackgroundThread(wrapper,
|
| + nacl_subprocess.get(),
|
| + manifest,
|
| + params)) {
|
| return NULL;
|
| }
|
| // We need not wait for the init_done callback. We can block
|
| @@ -802,7 +827,7 @@ void Plugin::NexeFileDidOpen(int32_t pp_error) {
|
| wrapper(wrapper_factory()->MakeFileDesc(file_desc_ok_to_close, O_RDONLY));
|
| NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n");
|
| LoadNaClModule(
|
| - wrapper.get(),
|
| + wrapper.release(),
|
| true, /* enable_dyncode_syscalls */
|
| true, /* enable_exception_handling */
|
| false, /* enable_crash_throttling */
|
| @@ -919,7 +944,7 @@ void Plugin::BitcodeDidTranslate(int32_t pp_error) {
|
| nacl::scoped_ptr<nacl::DescWrapper>
|
| wrapper(pnacl_coordinator_.get()->ReleaseTranslatedFD());
|
| LoadNaClModule(
|
| - wrapper.get(),
|
| + wrapper.release(),
|
| false, /* enable_dyncode_syscalls */
|
| false, /* enable_exception_handling */
|
| true, /* enable_crash_throttling */
|
|
|