Chromium Code Reviews| 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 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 5 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 PP_NaClFileInfo info; | 104 PP_NaClFileInfo info; |
| 105 info.handle = file_handle; | 105 info.handle = file_handle; |
| 106 info.token_lo = 0; | 106 info.token_lo = 0; |
| 107 info.token_hi = 0; | 107 info.token_hi = 0; |
| 108 | 108 |
| 109 // Now actually load the nexe, which can happen on a background thread. | 109 // Now actually load the nexe, which can happen on a background thread. |
| 110 // | 110 // |
| 111 // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we | 111 // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we |
| 112 // have to roll our own blocking logic, similar to WaitForSelLdrStart() | 112 // have to roll our own blocking logic, similar to WaitForSelLdrStart() |
| 113 // above, except without timeout logic. | 113 // above, except without timeout logic. |
| 114 bool nexe_started = false; | |
| 115 pp::CompletionCallback nexe_started_callback = callback_factory_.NewCallback( | |
| 116 &Plugin::SignalNexeStarted, &nexe_started, service_runtime); | |
| 117 pp::Module::Get()->core()->CallOnMainThread( | 114 pp::Module::Get()->core()->CallOnMainThread( |
| 118 0, | 115 0, |
| 119 callback_factory_.NewCallback( | 116 callback_factory_.NewCallback( |
| 120 &Plugin::LoadNexeAndStart, | 117 &Plugin::LoadNexeAndStart, |
| 121 service_runtime, info, nexe_started_callback)); | 118 service_runtime, |
| 122 service_runtime->WaitForNexeStart(); | 119 info |
|
hidehiko
2014/06/18 05:07:04
nit: )); should be in this line.
There is no speci
Nick Bray (chromium)
2014/06/18 18:29:44
Done.
| |
| 123 | 120 ) |
| 124 return nexe_started; | 121 ); |
| 122 return service_runtime->WaitForNexeStart(); | |
| 125 } | 123 } |
| 126 | 124 |
| 127 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, | 125 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, |
| 128 ServiceRuntime* service_runtime, | 126 ServiceRuntime* service_runtime, |
| 129 const SelLdrStartParams& params, | 127 const SelLdrStartParams& params, |
| 130 pp::CompletionCallback callback) { | 128 pp::CompletionCallback callback) { |
| 131 if (pp_error != PP_OK) { | 129 if (pp_error != PP_OK) { |
| 132 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " | 130 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " |
| 133 "-- SHOULD NOT HAPPEN\n")); | 131 "-- SHOULD NOT HAPPEN\n")); |
| 134 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error); | 132 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error); |
| 135 return; | 133 return; |
| 136 } | 134 } |
| 137 service_runtime->StartSelLdr(params, callback); | 135 service_runtime->StartSelLdr(params, callback); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void Plugin::SignalStartSelLdrDone(int32_t pp_error, | 138 void Plugin::SignalStartSelLdrDone(int32_t pp_error, |
| 141 bool* started, | 139 bool* started, |
| 142 ServiceRuntime* service_runtime) { | 140 ServiceRuntime* service_runtime) { |
| 143 *started = (pp_error == PP_OK); | 141 *started = (pp_error == PP_OK); |
| 144 service_runtime->SignalStartSelLdrDone(); | 142 service_runtime->SignalStartSelLdrDone(); |
| 145 } | 143 } |
| 146 | 144 |
| 147 void Plugin::SignalNexeStarted(int32_t pp_error, | |
| 148 bool* started, | |
| 149 ServiceRuntime* service_runtime) { | |
| 150 *started = (pp_error == PP_OK); | |
| 151 service_runtime->SignalNexeStarted(); | |
| 152 } | |
| 153 | |
| 154 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, | 145 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, |
| 155 bool uses_nonsfi_mode, | 146 bool uses_nonsfi_mode, |
| 156 bool enable_dyncode_syscalls, | 147 bool enable_dyncode_syscalls, |
| 157 bool enable_exception_handling, | 148 bool enable_exception_handling, |
| 158 bool enable_crash_throttling, | 149 bool enable_crash_throttling, |
| 159 const pp::CompletionCallback& init_done_cb, | 150 const pp::CompletionCallback& init_done_cb, |
| 160 const pp::CompletionCallback& crash_cb) { | 151 const pp::CompletionCallback& crash_cb) { |
| 161 CHECK(pp::Module::Get()->core()->IsMainThread()); | 152 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 162 // Before forking a new sel_ldr process, ensure that we do not leak | 153 // Before forking a new sel_ldr process, ensure that we do not leak |
| 163 // the ServiceRuntime object for an existing subprocess, and that any | 154 // the ServiceRuntime object for an existing subprocess, and that any |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 185 error_info.SetReport( | 176 error_info.SetReport( |
| 186 PP_NACL_ERROR_SEL_LDR_INIT, | 177 PP_NACL_ERROR_SEL_LDR_INIT, |
| 187 "sel_ldr init failure " + main_subprocess_.description()); | 178 "sel_ldr init failure " + main_subprocess_.description()); |
| 188 ReportLoadError(error_info); | 179 ReportLoadError(error_info); |
| 189 return; | 180 return; |
| 190 } | 181 } |
| 191 | 182 |
| 192 // We don't take any action once nexe loading has completed, so pass an empty | 183 // We don't take any action once nexe loading has completed, so pass an empty |
| 193 // callback here for |callback|. | 184 // callback here for |callback|. |
| 194 pp::CompletionCallback callback = callback_factory_.NewCallback( | 185 pp::CompletionCallback callback = callback_factory_.NewCallback( |
| 195 &Plugin::LoadNexeAndStart, | 186 &Plugin::LoadNexeAndStart, service_runtime, file_info); |
| 196 service_runtime, file_info, pp::CompletionCallback()); | |
| 197 StartSelLdrOnMainThread( | 187 StartSelLdrOnMainThread( |
| 198 static_cast<int32_t>(PP_OK), service_runtime, params, callback); | 188 static_cast<int32_t>(PP_OK), service_runtime, params, callback); |
| 199 } | 189 } |
| 200 | 190 |
| 201 void Plugin::LoadNexeAndStart(int32_t pp_error, | 191 void Plugin::LoadNexeAndStart(int32_t pp_error, |
| 202 ServiceRuntime* service_runtime, | 192 ServiceRuntime* service_runtime, |
| 203 PP_NaClFileInfo file_info, | 193 PP_NaClFileInfo file_info) { |
| 204 const pp::CompletionCallback& callback) { | |
| 205 CHECK(pp::Module::Get()->core()->IsMainThread()); | 194 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 206 if (pp_error != PP_OK) | 195 if (pp_error != PP_OK) |
| 207 return; | 196 return; |
| 208 service_runtime->LoadNexeAndStart(file_info, callback); | 197 service_runtime->LoadNexeAndStart(file_info); |
| 209 } | 198 } |
| 210 | 199 |
| 211 bool Plugin::LoadNaClModuleContinuationIntern() { | 200 bool Plugin::LoadNaClModuleContinuationIntern() { |
| 212 ErrorInfo error_info; | 201 ErrorInfo error_info; |
| 213 if (!uses_nonsfi_mode_) { | 202 if (!uses_nonsfi_mode_) { |
| 214 if (!main_subprocess_.StartSrpcServices()) { | 203 if (!main_subprocess_.StartSrpcServices()) { |
| 215 // The NaCl process probably crashed. On Linux, a crash causes this | 204 // The NaCl process probably crashed. On Linux, a crash causes this |
| 216 // error, while on other platforms, the error is detected below, when we | 205 // error, while on other platforms, the error is detected below, when we |
| 217 // attempt to start the proxy. Report a module initialization error here, | 206 // attempt to start the proxy. Report a module initialization error here, |
| 218 // to make it less confusing for developers. | 207 // to make it less confusing for developers. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 518 |
| 530 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 519 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
| 531 int exit_status) { | 520 int exit_status) { |
| 532 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 521 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
| 533 DCHECK(nacl_interface_); | 522 DCHECK(nacl_interface_); |
| 534 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 523 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
| 535 } | 524 } |
| 536 | 525 |
| 537 | 526 |
| 538 } // namespace plugin | 527 } // namespace plugin |
| OLD | NEW |