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

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 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
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));
123 120 return service_runtime->WaitForNexeStart();
124 return nexe_started;
125 } 121 }
126 122
127 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, 123 void Plugin::StartSelLdrOnMainThread(int32_t pp_error,
128 ServiceRuntime* service_runtime, 124 ServiceRuntime* service_runtime,
129 const SelLdrStartParams& params, 125 const SelLdrStartParams& params,
130 pp::CompletionCallback callback) { 126 pp::CompletionCallback callback) {
131 if (pp_error != PP_OK) { 127 if (pp_error != PP_OK) {
132 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " 128 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg "
133 "-- SHOULD NOT HAPPEN\n")); 129 "-- SHOULD NOT HAPPEN\n"));
134 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error); 130 pp::Module::Get()->core()->CallOnMainThread(0, callback, pp_error);
135 return; 131 return;
136 } 132 }
137 service_runtime->StartSelLdr(params, callback); 133 service_runtime->StartSelLdr(params, callback);
138 } 134 }
139 135
140 void Plugin::SignalStartSelLdrDone(int32_t pp_error, 136 void Plugin::SignalStartSelLdrDone(int32_t pp_error,
141 bool* started, 137 bool* started,
142 ServiceRuntime* service_runtime) { 138 ServiceRuntime* service_runtime) {
143 *started = (pp_error == PP_OK); 139 *started = (pp_error == PP_OK);
144 service_runtime->SignalStartSelLdrDone(); 140 service_runtime->SignalStartSelLdrDone();
145 } 141 }
146 142
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, 143 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info,
155 bool uses_nonsfi_mode, 144 bool uses_nonsfi_mode,
156 bool enable_dyncode_syscalls, 145 bool enable_dyncode_syscalls,
157 bool enable_exception_handling, 146 bool enable_exception_handling,
158 bool enable_crash_throttling, 147 bool enable_crash_throttling,
159 const pp::CompletionCallback& init_done_cb, 148 const pp::CompletionCallback& init_done_cb,
160 const pp::CompletionCallback& crash_cb) { 149 const pp::CompletionCallback& crash_cb) {
161 CHECK(pp::Module::Get()->core()->IsMainThread()); 150 CHECK(pp::Module::Get()->core()->IsMainThread());
162 // Before forking a new sel_ldr process, ensure that we do not leak 151 // Before forking a new sel_ldr process, ensure that we do not leak
163 // the ServiceRuntime object for an existing subprocess, and that any 152 // the ServiceRuntime object for an existing subprocess, and that any
(...skipping 19 matching lines...) Expand all
183 error_info.SetReport( 172 error_info.SetReport(
184 PP_NACL_ERROR_SEL_LDR_INIT, 173 PP_NACL_ERROR_SEL_LDR_INIT,
185 "sel_ldr init failure " + main_subprocess_.description()); 174 "sel_ldr init failure " + main_subprocess_.description());
186 ReportLoadError(error_info); 175 ReportLoadError(error_info);
187 return; 176 return;
188 } 177 }
189 178
190 // We don't take any action once nexe loading has completed, so pass an empty 179 // We don't take any action once nexe loading has completed, so pass an empty
191 // callback here for |callback|. 180 // callback here for |callback|.
192 pp::CompletionCallback callback = callback_factory_.NewCallback( 181 pp::CompletionCallback callback = callback_factory_.NewCallback(
193 &Plugin::LoadNexeAndStart, 182 &Plugin::LoadNexeAndStart, service_runtime, file_info);
194 service_runtime, file_info, pp::CompletionCallback());
195 StartSelLdrOnMainThread( 183 StartSelLdrOnMainThread(
196 static_cast<int32_t>(PP_OK), service_runtime, params, callback); 184 static_cast<int32_t>(PP_OK), service_runtime, params, callback);
197 } 185 }
198 186
199 void Plugin::LoadNexeAndStart(int32_t pp_error, 187 void Plugin::LoadNexeAndStart(int32_t pp_error,
200 ServiceRuntime* service_runtime, 188 ServiceRuntime* service_runtime,
201 PP_NaClFileInfo file_info, 189 PP_NaClFileInfo file_info) {
202 const pp::CompletionCallback& callback) {
203 CHECK(pp::Module::Get()->core()->IsMainThread()); 190 CHECK(pp::Module::Get()->core()->IsMainThread());
204 if (pp_error != PP_OK) 191 if (pp_error != PP_OK)
205 return; 192 return;
206 service_runtime->LoadNexeAndStart(file_info, callback); 193 service_runtime->LoadNexeAndStart(file_info);
207 } 194 }
208 195
209 bool Plugin::LoadNaClModuleContinuationIntern() { 196 bool Plugin::LoadNaClModuleContinuationIntern() {
210 ErrorInfo error_info; 197 ErrorInfo error_info;
211 if (!uses_nonsfi_mode_) { 198 if (!uses_nonsfi_mode_) {
212 if (!main_subprocess_.StartSrpcServices()) { 199 if (!main_subprocess_.StartSrpcServices()) {
213 // The NaCl process probably crashed. On Linux, a crash causes this 200 // The NaCl process probably crashed. On Linux, a crash causes this
214 // error, while on other platforms, the error is detected below, when we 201 // error, while on other platforms, the error is detected below, when we
215 // attempt to start the proxy. Report a module initialization error here, 202 // attempt to start the proxy. Report a module initialization error here,
216 // to make it less confusing for developers. 203 // to make it less confusing for developers.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 512
526 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, 513 void Plugin::SetExitStatusOnMainThread(int32_t pp_error,
527 int exit_status) { 514 int exit_status) {
528 DCHECK(pp::Module::Get()->core()->IsMainThread()); 515 DCHECK(pp::Module::Get()->core()->IsMainThread());
529 DCHECK(nacl_interface_); 516 DCHECK(nacl_interface_);
530 nacl_interface_->SetExitStatus(pp_instance(), exit_status); 517 nacl_interface_->SetExitStatus(pp_instance(), exit_status);
531 } 518 }
532 519
533 520
534 } // namespace plugin 521 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698