OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #define NACL_LOG_MODULE_NAME "Plugin_ServiceRuntime" | 7 #define NACL_LOG_MODULE_NAME "Plugin_ServiceRuntime" |
8 | 8 |
9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | 9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 namespace plugin { | 52 namespace plugin { |
53 | 53 |
54 OpenManifestEntryResource::~OpenManifestEntryResource() { | 54 OpenManifestEntryResource::~OpenManifestEntryResource() { |
55 } | 55 } |
56 | 56 |
57 PluginReverseInterface::PluginReverseInterface( | 57 PluginReverseInterface::PluginReverseInterface( |
58 nacl::WeakRefAnchor* anchor, | 58 nacl::WeakRefAnchor* anchor, |
59 PP_Instance pp_instance, | 59 PP_Instance pp_instance, |
60 ServiceRuntime* service_runtime, | 60 ServiceRuntime* service_runtime, |
61 pp::CompletionCallback init_done_cb, | 61 pp::CompletionCallback init_done_cb) |
62 pp::CompletionCallback crash_cb) | |
63 : anchor_(anchor), | 62 : anchor_(anchor), |
64 pp_instance_(pp_instance), | 63 pp_instance_(pp_instance), |
65 service_runtime_(service_runtime), | 64 service_runtime_(service_runtime), |
66 shutting_down_(false), | 65 shutting_down_(false), |
67 init_done_cb_(init_done_cb), | 66 init_done_cb_(init_done_cb) { |
68 crash_cb_(crash_cb) { | |
69 NaClXMutexCtor(&mu_); | 67 NaClXMutexCtor(&mu_); |
70 NaClXCondVarCtor(&cv_); | 68 NaClXCondVarCtor(&cv_); |
71 } | 69 } |
72 | 70 |
73 PluginReverseInterface::~PluginReverseInterface() { | 71 PluginReverseInterface::~PluginReverseInterface() { |
74 NaClCondVarDtor(&cv_); | 72 NaClCondVarDtor(&cv_); |
75 NaClMutexDtor(&mu_); | 73 NaClMutexDtor(&mu_); |
76 } | 74 } |
77 | 75 |
78 void PluginReverseInterface::ShutDown() { | 76 void PluginReverseInterface::ShutDown() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 4, | 213 4, |
216 "StreamAsFile_MainThreadContinuation: !PP_OK, setting desc -1\n"); | 214 "StreamAsFile_MainThreadContinuation: !PP_OK, setting desc -1\n"); |
217 p->file_info->desc = -1; | 215 p->file_info->desc = -1; |
218 } | 216 } |
219 *p->op_complete_ptr = true; | 217 *p->op_complete_ptr = true; |
220 NaClXCondVarBroadcast(&cv_); | 218 NaClXCondVarBroadcast(&cv_); |
221 } | 219 } |
222 } | 220 } |
223 | 221 |
224 void PluginReverseInterface::ReportCrash() { | 222 void PluginReverseInterface::ReportCrash() { |
225 NaClLog(4, "PluginReverseInterface::ReportCrash\n"); | 223 // This is now handled through Chromium IPC. |
226 | |
227 if (crash_cb_.pp_completion_callback().func != NULL) { | |
228 NaClLog(4, "PluginReverseInterface::ReportCrash: invoking CB\n"); | |
229 pp::Module::Get()->core()->CallOnMainThread(0, crash_cb_, PP_OK); | |
230 // Clear the callback to avoid it gets invoked twice. | |
231 crash_cb_ = pp::CompletionCallback(); | |
232 } else { | |
233 NaClLog(1, | |
234 "PluginReverseInterface::ReportCrash:" | |
235 " crash_cb_ not valid, skipping\n"); | |
236 } | |
237 } | 224 } |
238 | 225 |
239 void PluginReverseInterface::ReportExitStatus(int exit_status) { | 226 void PluginReverseInterface::ReportExitStatus(int exit_status) { |
240 // We do nothing here; reporting exit status is handled through a separate | 227 // We do nothing here; reporting exit status is handled through a separate |
241 // embedder interface. | 228 // embedder interface. |
242 } | 229 } |
243 | 230 |
244 int64_t PluginReverseInterface::RequestQuotaForWrite( | 231 int64_t PluginReverseInterface::RequestQuotaForWrite( |
245 nacl::string file_id, int64_t offset, int64_t bytes_to_write) { | 232 nacl::string file_id, int64_t offset, int64_t bytes_to_write) { |
246 return bytes_to_write; | 233 return bytes_to_write; |
247 } | 234 } |
248 | 235 |
249 ServiceRuntime::ServiceRuntime(Plugin* plugin, | 236 ServiceRuntime::ServiceRuntime(Plugin* plugin, |
250 PP_Instance pp_instance, | 237 PP_Instance pp_instance, |
251 bool main_service_runtime, | 238 bool main_service_runtime, |
252 bool uses_nonsfi_mode, | 239 bool uses_nonsfi_mode, |
253 pp::CompletionCallback init_done_cb, | 240 pp::CompletionCallback init_done_cb) |
254 pp::CompletionCallback crash_cb) | |
255 : plugin_(plugin), | 241 : plugin_(plugin), |
256 pp_instance_(pp_instance), | 242 pp_instance_(pp_instance), |
257 main_service_runtime_(main_service_runtime), | 243 main_service_runtime_(main_service_runtime), |
258 uses_nonsfi_mode_(uses_nonsfi_mode), | 244 uses_nonsfi_mode_(uses_nonsfi_mode), |
259 reverse_service_(NULL), | 245 reverse_service_(NULL), |
260 anchor_(new nacl::WeakRefAnchor()), | 246 anchor_(new nacl::WeakRefAnchor()), |
261 rev_interface_(new PluginReverseInterface(anchor_, pp_instance, this, | 247 rev_interface_(new PluginReverseInterface(anchor_, pp_instance, this, |
262 init_done_cb, crash_cb)), | 248 init_done_cb)), |
263 start_sel_ldr_done_(false), | 249 start_sel_ldr_done_(false), |
264 start_nexe_done_(false), | 250 start_nexe_done_(false), |
265 nexe_started_ok_(false), | 251 nexe_started_ok_(false), |
266 bootstrap_channel_(NACL_INVALID_HANDLE) { | 252 bootstrap_channel_(NACL_INVALID_HANDLE) { |
267 NaClSrpcChannelInitialize(&command_channel_); | 253 NaClSrpcChannelInitialize(&command_channel_); |
268 NaClXMutexCtor(&mu_); | 254 NaClXMutexCtor(&mu_); |
269 NaClXCondVarCtor(&cond_); | 255 NaClXCondVarCtor(&cond_); |
270 } | 256 } |
271 | 257 |
272 bool ServiceRuntime::SetupCommandChannel() { | 258 bool ServiceRuntime::SetupCommandChannel() { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 466 |
481 bool ServiceRuntime::StartNexeInternal() { | 467 bool ServiceRuntime::StartNexeInternal() { |
482 if (!SetupCommandChannel()) | 468 if (!SetupCommandChannel()) |
483 return false; | 469 return false; |
484 if (!InitReverseService()) | 470 if (!InitReverseService()) |
485 return false; | 471 return false; |
486 return StartModule(); | 472 return StartModule(); |
487 } | 473 } |
488 | 474 |
489 void ServiceRuntime::ReapLogs() { | 475 void ServiceRuntime::ReapLogs() { |
490 // On a load failure the service runtime does not crash itself to | 476 // TODO(teravest): We should allow the NaCl process to crash itself when a |
| 477 // module fails to start, and remove the call to RemoteLog() here. The |
| 478 // reverse channel is no longer needed for crash reporting. |
| 479 // |
| 480 // The reasoning behind the current code behavior follows: |
| 481 // On a load failure the NaCl process does not crash itself to |
491 // avoid a race where the no-more-senders error on the reverse | 482 // avoid a race where the no-more-senders error on the reverse |
492 // channel service thread might cause the crash-detection logic to | 483 // channel service thread might cause the crash-detection logic to |
493 // kick in before the start_module RPC reply has been received. So | 484 // kick in before the start_module RPC reply has been received. So |
494 // we induce a service runtime crash here. We do not release | 485 // we induce a NaCl process crash here. |
495 // subprocess_ since it's needed to collect crash log output after | |
496 // the error is reported. | |
497 RemoteLog(LOG_FATAL, "reap logs\n"); | 486 RemoteLog(LOG_FATAL, "reap logs\n"); |
498 if (NULL == reverse_service_) { | 487 |
499 // No crash detector thread. | 488 // TODO(teravest): Release subprocess_ here since it's no longer needed. It |
500 NaClLog(LOG_ERROR, "scheduling to get crash log\n"); | 489 // was previously kept around to collect crash log output from the bootstrap |
501 // Invoking rev_interface's method is workaround to avoid crash_cb | 490 // channel. |
502 // gets called twice or more. We should clean this up later. | |
503 rev_interface_->ReportCrash(); | |
504 NaClLog(LOG_ERROR, "should fire soon\n"); | |
505 } else { | |
506 NaClLog(LOG_ERROR, "Reverse service thread will pick up crash log\n"); | |
507 } | |
508 } | 491 } |
509 | 492 |
510 void ServiceRuntime::ReportLoadError(const ErrorInfo& error_info) { | 493 void ServiceRuntime::ReportLoadError(const ErrorInfo& error_info) { |
511 if (main_service_runtime_) { | 494 if (main_service_runtime_) { |
512 plugin_->ReportLoadError(error_info); | 495 plugin_->ReportLoadError(error_info); |
513 } | 496 } |
514 } | 497 } |
515 | 498 |
516 SrpcClient* ServiceRuntime::SetupAppChannel() { | 499 SrpcClient* ServiceRuntime::SetupAppChannel() { |
517 NaClLog(4, "ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", | 500 NaClLog(4, "ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 reverse_service_->Unref(); | 559 reverse_service_->Unref(); |
577 | 560 |
578 rev_interface_->Unref(); | 561 rev_interface_->Unref(); |
579 | 562 |
580 anchor_->Unref(); | 563 anchor_->Unref(); |
581 NaClCondVarDtor(&cond_); | 564 NaClCondVarDtor(&cond_); |
582 NaClMutexDtor(&mu_); | 565 NaClMutexDtor(&mu_); |
583 } | 566 } |
584 | 567 |
585 } // namespace plugin | 568 } // namespace plugin |
OLD | NEW |