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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/plugin.cc

Issue 338353008: NaCl: clean up nexe loading logic in trusted plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + resolve conflicts Created 6 years, 6 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 (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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 PP_NaClFileInfo info; 110 PP_NaClFileInfo info;
111 info.handle = file_handle; 111 info.handle = file_handle;
112 info.token_lo = 0; 112 info.token_lo = 0;
113 info.token_hi = 0; 113 info.token_hi = 0;
114 114
115 // Now actually load the nexe, which can happen on a background thread. 115 // Now actually load the nexe, which can happen on a background thread.
116 // 116 //
117 // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we 117 // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we
118 // have to roll our own blocking logic, similar to WaitForSelLdrStart() 118 // have to roll our own blocking logic, similar to WaitForSelLdrStart()
119 // above, except without timeout logic. 119 // above, except without timeout logic.
120 bool nexe_started = false;
121 pp::CompletionCallback nexe_started_callback = callback_factory_.NewCallback(
122 &Plugin::SignalNexeStarted, &nexe_started, service_runtime);
123 pp::Module::Get()->core()->CallOnMainThread( 120 pp::Module::Get()->core()->CallOnMainThread(
124 0, 121 0,
125 callback_factory_.NewCallback( 122 callback_factory_.NewCallback(
126 &Plugin::LoadNexeAndStart, 123 &Plugin::LoadNexeAndStart,
127 service_runtime, info, nexe_started_callback)); 124 service_runtime,
128 service_runtime->WaitForNexeStart(); 125 info));
129 126 return service_runtime->WaitForNexeStart();
130 return nexe_started;
131 } 127 }
132 128
133 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, 129 void Plugin::StartSelLdrOnMainThread(int32_t pp_error,
134 ServiceRuntime* service_runtime, 130 ServiceRuntime* service_runtime,
135 const SelLdrStartParams& params, 131 const SelLdrStartParams& params,
136 pp::CompletionCallback callback) { 132 pp::CompletionCallback callback) {
137 if (pp_error != PP_OK) { 133 if (pp_error != PP_OK) {
138 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " 134 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg "
139 "-- SHOULD NOT HAPPEN\n")); 135 "-- SHOULD NOT HAPPEN\n"));
140 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error); 136 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error);
141 return; 137 return;
142 } 138 }
143 service_runtime->StartSelLdr(params, callback); 139 service_runtime->StartSelLdr(params, callback);
144 } 140 }
145 141
146 void Plugin::SignalStartSelLdrDone(int32_t pp_error, 142 void Plugin::SignalStartSelLdrDone(int32_t pp_error,
147 bool* started, 143 bool* started,
148 ServiceRuntime* service_runtime) { 144 ServiceRuntime* service_runtime) {
149 *started = (pp_error == PP_OK); 145 *started = (pp_error == PP_OK);
150 service_runtime->SignalStartSelLdrDone(); 146 service_runtime->SignalStartSelLdrDone();
151 } 147 }
152 148
153 void Plugin::SignalNexeStarted(int32_t pp_error,
154 bool* started,
155 ServiceRuntime* service_runtime) {
156 *started = (pp_error == PP_OK);
157 service_runtime->SignalNexeStarted();
158 }
159
160 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, 149 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info,
161 bool uses_nonsfi_mode, 150 bool uses_nonsfi_mode,
162 bool enable_dyncode_syscalls, 151 bool enable_dyncode_syscalls,
163 bool enable_exception_handling, 152 bool enable_exception_handling,
164 bool enable_crash_throttling, 153 bool enable_crash_throttling,
165 const pp::CompletionCallback& init_done_cb, 154 const pp::CompletionCallback& init_done_cb,
166 const pp::CompletionCallback& crash_cb) { 155 const pp::CompletionCallback& crash_cb) {
167 CHECK(pp::Module::Get()->core()->IsMainThread()); 156 CHECK(pp::Module::Get()->core()->IsMainThread());
168 // Before forking a new sel_ldr process, ensure that we do not leak 157 // Before forking a new sel_ldr process, ensure that we do not leak
169 // the ServiceRuntime object for an existing subprocess, and that any 158 // the ServiceRuntime object for an existing subprocess, and that any
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 error_info.SetReport( 191 error_info.SetReport(
203 PP_NACL_ERROR_SEL_LDR_INIT, 192 PP_NACL_ERROR_SEL_LDR_INIT,
204 "sel_ldr init failure " + main_subprocess_.description()); 193 "sel_ldr init failure " + main_subprocess_.description());
205 ReportLoadError(error_info); 194 ReportLoadError(error_info);
206 return; 195 return;
207 } 196 }
208 197
209 // We don't take any action once nexe loading has completed, so pass an empty 198 // We don't take any action once nexe loading has completed, so pass an empty
210 // callback here for |callback|. 199 // callback here for |callback|.
211 pp::CompletionCallback callback = callback_factory_.NewCallback( 200 pp::CompletionCallback callback = callback_factory_.NewCallback(
212 &Plugin::LoadNexeAndStart, 201 &Plugin::LoadNexeAndStart, service_runtime, file_info_for_srpc);
213 service_runtime, file_info_for_srpc, pp::CompletionCallback());
214 StartSelLdrOnMainThread( 202 StartSelLdrOnMainThread(
215 static_cast<int32_t>(PP_OK), service_runtime, params, callback); 203 static_cast<int32_t>(PP_OK), service_runtime, params, callback);
216 } 204 }
217 205
218 void Plugin::LoadNexeAndStart(int32_t pp_error, 206 void Plugin::LoadNexeAndStart(int32_t pp_error,
219 ServiceRuntime* service_runtime, 207 ServiceRuntime* service_runtime,
220 PP_NaClFileInfo file_info, 208 PP_NaClFileInfo file_info) {
221 const pp::CompletionCallback& callback) {
222 CHECK(pp::Module::Get()->core()->IsMainThread()); 209 CHECK(pp::Module::Get()->core()->IsMainThread());
223 if (pp_error != PP_OK) 210 if (pp_error != PP_OK)
224 return; 211 return;
225 service_runtime->LoadNexeAndStart(file_info, callback); 212 service_runtime->LoadNexeAndStart(file_info);
226 } 213 }
227 214
228 bool Plugin::LoadNaClModuleContinuationIntern() { 215 bool Plugin::LoadNaClModuleContinuationIntern() {
229 ErrorInfo error_info; 216 ErrorInfo error_info;
230 if (!uses_nonsfi_mode_) { 217 if (!uses_nonsfi_mode_) {
231 if (!main_subprocess_.StartSrpcServices()) { 218 if (!main_subprocess_.StartSrpcServices()) {
232 // The NaCl process probably crashed. On Linux, a crash causes this 219 // The NaCl process probably crashed. On Linux, a crash causes this
233 // error, while on other platforms, the error is detected below, when we 220 // error, while on other platforms, the error is detected below, when we
234 // attempt to start the proxy. Report a module initialization error here, 221 // attempt to start the proxy. Report a module initialization error here,
235 // to make it less confusing for developers. 222 // to make it less confusing for developers.
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 538
552 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, 539 void Plugin::SetExitStatusOnMainThread(int32_t pp_error,
553 int exit_status) { 540 int exit_status) {
554 DCHECK(pp::Module::Get()->core()->IsMainThread()); 541 DCHECK(pp::Module::Get()->core()->IsMainThread());
555 DCHECK(nacl_interface_); 542 DCHECK(nacl_interface_);
556 nacl_interface_->SetExitStatus(pp_instance(), exit_status); 543 nacl_interface_->SetExitStatus(pp_instance(), exit_status);
557 } 544 }
558 545
559 546
560 } // namespace plugin 547 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | ppapi/native_client/src/trusted/plugin/service_runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698