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 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 namespace plugin { | 35 namespace plugin { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Up to 20 seconds | 39 // Up to 20 seconds |
40 const int64_t kTimeSmallMin = 1; // in ms | 40 const int64_t kTimeSmallMin = 1; // in ms |
41 const int64_t kTimeSmallMax = 20000; // in ms | 41 const int64_t kTimeSmallMax = 20000; // in ms |
42 const uint32_t kTimeSmallBuckets = 100; | 42 const uint32_t kTimeSmallBuckets = 100; |
43 | 43 |
44 const PP_NaClFileInfo kInvalidNaClFileInfo = { | |
45 PP_kInvalidFileHandle, | |
46 0, // token_lo | |
47 0, // token_hi | |
48 }; | |
49 | |
44 } // namespace | 50 } // namespace |
45 | 51 |
46 void Plugin::ShutDownSubprocesses() { | 52 void Plugin::ShutDownSubprocesses() { |
47 PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (this=%p)\n", | 53 PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (this=%p)\n", |
48 static_cast<void*>(this))); | 54 static_cast<void*>(this))); |
49 PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (%s)\n", | 55 PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (%s)\n", |
50 main_subprocess_.detailed_description().c_str())); | 56 main_subprocess_.detailed_description().c_str())); |
51 | 57 |
52 // Shut down service runtime. This must be done before all other calls so | 58 // Shut down service runtime. This must be done before all other calls so |
53 // they don't block forever when waiting for the upcall thread to exit. | 59 // they don't block forever when waiting for the upcall thread to exit. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 const pp::CompletionCallback& crash_cb) { | 166 const pp::CompletionCallback& crash_cb) { |
161 CHECK(pp::Module::Get()->core()->IsMainThread()); | 167 CHECK(pp::Module::Get()->core()->IsMainThread()); |
162 // Before forking a new sel_ldr process, ensure that we do not leak | 168 // Before forking a new sel_ldr process, ensure that we do not leak |
163 // the ServiceRuntime object for an existing subprocess, and that any | 169 // the ServiceRuntime object for an existing subprocess, and that any |
164 // associated listener threads do not go unjoined because if they | 170 // associated listener threads do not go unjoined because if they |
165 // outlive the Plugin object, they will not be memory safe. | 171 // outlive the Plugin object, they will not be memory safe. |
166 ShutDownSubprocesses(); | 172 ShutDownSubprocesses(); |
167 pp::Var manifest_base_url = | 173 pp::Var manifest_base_url = |
168 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); | 174 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); |
169 std::string manifest_base_url_str = manifest_base_url.AsString(); | 175 std::string manifest_base_url_str = manifest_base_url.AsString(); |
176 | |
177 PP_NaClFileInfo launch_sel_ldr_file_info; | |
Mark Seaborn
2014/06/18 19:53:12
The names "launch_sel_ldr" and "load_module" are a
hidehiko
2014/06/19 07:02:00
Done.
| |
178 PP_NaClFileInfo load_module_file_info; | |
179 if (uses_nonsfi_mode) { | |
180 // In non-SFI mode, LaunchSelLdr is used to pass the nexe file's descriptor | |
181 // to the plugin. | |
Mark Seaborn
2014/06/18 19:53:12
"to the NaCl loader process", really. "Plugin" is
hidehiko
2014/06/19 07:01:59
Done.
| |
182 launch_sel_ldr_file_info = file_info; | |
183 load_module_file_info = kInvalidNaClFileInfo; | |
184 } else { | |
185 // Otherwise (i.e. in SFI-mode), LoadModule SRPC is still being used. | |
186 launch_sel_ldr_file_info = kInvalidNaClFileInfo; | |
187 load_module_file_info = file_info; | |
188 } | |
189 | |
170 SelLdrStartParams params(manifest_base_url_str, | 190 SelLdrStartParams params(manifest_base_url_str, |
191 launch_sel_ldr_file_info, | |
Mark Seaborn
2014/06/18 19:53:12
This will take ownership of the FD when a message
hidehiko
2014/06/19 07:01:59
Good point. Can I work on it in a separate CL, to
Mark Seaborn
2014/06/19 22:36:47
Yes, feel free to leave that to a separate change.
| |
171 true /* uses_irt */, | 192 true /* uses_irt */, |
172 true /* uses_ppapi */, | 193 true /* uses_ppapi */, |
173 enable_dyncode_syscalls, | 194 enable_dyncode_syscalls, |
174 enable_exception_handling, | 195 enable_exception_handling, |
175 enable_crash_throttling); | 196 enable_crash_throttling); |
176 ErrorInfo error_info; | 197 ErrorInfo error_info; |
177 ServiceRuntime* service_runtime = new ServiceRuntime( | 198 ServiceRuntime* service_runtime = new ServiceRuntime( |
178 this, true, uses_nonsfi_mode, init_done_cb, crash_cb); | 199 this, true, uses_nonsfi_mode, init_done_cb, crash_cb); |
179 main_subprocess_.set_service_runtime(service_runtime); | 200 main_subprocess_.set_service_runtime(service_runtime); |
180 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", | 201 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", |
181 static_cast<void*>(service_runtime))); | 202 static_cast<void*>(service_runtime))); |
182 if (NULL == service_runtime) { | 203 if (NULL == service_runtime) { |
183 error_info.SetReport( | 204 error_info.SetReport( |
184 PP_NACL_ERROR_SEL_LDR_INIT, | 205 PP_NACL_ERROR_SEL_LDR_INIT, |
185 "sel_ldr init failure " + main_subprocess_.description()); | 206 "sel_ldr init failure " + main_subprocess_.description()); |
186 ReportLoadError(error_info); | 207 ReportLoadError(error_info); |
187 return; | 208 return; |
Mark Seaborn
2014/06/18 19:53:12
...but would the FD get closed if we return early
hidehiko
2014/06/19 07:01:59
Admittedly...
| |
188 } | 209 } |
189 | 210 |
190 // We don't take any action once nexe loading has completed, so pass an empty | 211 // We don't take any action once nexe loading has completed, so pass an empty |
191 // callback here for |callback|. | 212 // callback here for |callback|. |
192 pp::CompletionCallback callback = callback_factory_.NewCallback( | 213 pp::CompletionCallback callback = callback_factory_.NewCallback( |
193 &Plugin::LoadNexeAndStart, | 214 &Plugin::LoadNexeAndStart, |
194 service_runtime, file_info, pp::CompletionCallback()); | 215 service_runtime, load_module_file_info, pp::CompletionCallback()); |
Mark Seaborn
2014/06/18 19:53:12
...and does this existing SRPC code path take owne
hidehiko
2014/06/19 07:02:00
It takes.
So, here we have three problems.
1) If c
Mark Seaborn
2014/06/19 22:36:48
I don't know the answer. Justin probably knows th
| |
195 StartSelLdrOnMainThread( | 216 StartSelLdrOnMainThread( |
196 static_cast<int32_t>(PP_OK), service_runtime, params, callback); | 217 static_cast<int32_t>(PP_OK), service_runtime, params, callback); |
197 } | 218 } |
198 | 219 |
199 void Plugin::LoadNexeAndStart(int32_t pp_error, | 220 void Plugin::LoadNexeAndStart(int32_t pp_error, |
200 ServiceRuntime* service_runtime, | 221 ServiceRuntime* service_runtime, |
201 PP_NaClFileInfo file_info, | 222 PP_NaClFileInfo file_info, |
202 const pp::CompletionCallback& callback) { | 223 const pp::CompletionCallback& callback) { |
203 CHECK(pp::Module::Get()->core()->IsMainThread()); | 224 CHECK(pp::Module::Get()->core()->IsMainThread()); |
204 if (pp_error != PP_OK) | 225 if (pp_error != PP_OK) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 if (NULL == nacl_subprocess.get()) { | 260 if (NULL == nacl_subprocess.get()) { |
240 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, | 261 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, |
241 "unable to allocate helper subprocess."); | 262 "unable to allocate helper subprocess."); |
242 return NULL; | 263 return NULL; |
243 } | 264 } |
244 | 265 |
245 // Do not report UMA stats for translator-related nexes. | 266 // Do not report UMA stats for translator-related nexes. |
246 // TODO(sehr): define new UMA stats for translator related nexe events. | 267 // TODO(sehr): define new UMA stats for translator related nexe events. |
247 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is | 268 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is |
248 // done to save on address space and swap space. | 269 // done to save on address space and swap space. |
270 // | |
271 // Currently, this works only in SFI-mode. So, LoadModule SRPC is still used. | |
272 // So, pass kInvalidNaClFileInfo here, and instead |file_handle| is passed | |
273 // to LoadNaClModuleFromBackgroundThread() below. | |
274 // TODO(teravest, hidehiko): Pass file_handle to params, so that LaunchSelLdr | |
275 // will look at the info. | |
249 SelLdrStartParams params(helper_url, | 276 SelLdrStartParams params(helper_url, |
277 kInvalidNaClFileInfo, | |
250 false /* uses_irt */, | 278 false /* uses_irt */, |
251 false /* uses_ppapi */, | 279 false /* uses_ppapi */, |
252 false /* enable_dyncode_syscalls */, | 280 false /* enable_dyncode_syscalls */, |
253 false /* enable_exception_handling */, | 281 false /* enable_exception_handling */, |
254 true /* enable_crash_throttling */); | 282 true /* enable_crash_throttling */); |
255 | 283 |
256 // Helper NaCl modules always use the PNaCl manifest, as there is no | 284 // Helper NaCl modules always use the PNaCl manifest, as there is no |
257 // corresponding NMF. | 285 // corresponding NMF. |
258 if (!LoadHelperNaClModule(file_handle, nacl_subprocess.get(), params)) { | 286 if (!LoadHelperNaClModule(file_handle, nacl_subprocess.get(), params)) { |
259 return NULL; | 287 return NULL; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 | 553 |
526 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 554 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
527 int exit_status) { | 555 int exit_status) { |
528 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 556 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
529 DCHECK(nacl_interface_); | 557 DCHECK(nacl_interface_); |
530 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 558 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
531 } | 559 } |
532 | 560 |
533 | 561 |
534 } // namespace plugin | 562 } // namespace plugin |
OLD | NEW |