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 11 matching lines...) Expand all Loading... |
65 kTimeSmallMin, kTimeSmallMax, | 71 kTimeSmallMin, kTimeSmallMax, |
66 kTimeSmallBuckets); | 72 kTimeSmallBuckets); |
67 } | 73 } |
68 | 74 |
69 bool Plugin::LoadNaClModuleFromBackgroundThread( | 75 bool Plugin::LoadNaClModuleFromBackgroundThread( |
70 PP_FileHandle file_handle, | 76 PP_FileHandle file_handle, |
71 NaClSubprocess* subprocess, | 77 NaClSubprocess* subprocess, |
72 const SelLdrStartParams& params) { | 78 const SelLdrStartParams& params) { |
73 CHECK(!pp::Module::Get()->core()->IsMainThread()); | 79 CHECK(!pp::Module::Get()->core()->IsMainThread()); |
74 ServiceRuntime* service_runtime = | 80 ServiceRuntime* service_runtime = |
75 new ServiceRuntime(this, false, uses_nonsfi_mode_, | 81 new ServiceRuntime(this, |
| 82 false, // non main_service_runtime |
| 83 false, // no non-SFI mode. (i.e. in SFI-mode). |
76 pp::BlockUntilComplete(), pp::BlockUntilComplete()); | 84 pp::BlockUntilComplete(), pp::BlockUntilComplete()); |
77 subprocess->set_service_runtime(service_runtime); | 85 subprocess->set_service_runtime(service_runtime); |
78 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " | 86 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " |
79 "(service_runtime=%p)\n", | 87 "(service_runtime=%p)\n", |
80 static_cast<void*>(service_runtime))); | 88 static_cast<void*>(service_runtime))); |
81 | 89 |
82 // Now start the SelLdr instance. This must be created on the main thread. | 90 // Now start the SelLdr instance. This must be created on the main thread. |
83 bool service_runtime_started = false; | 91 bool service_runtime_started = false; |
84 pp::CompletionCallback sel_ldr_callback = | 92 pp::CompletionCallback sel_ldr_callback = |
85 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone, | 93 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const pp::CompletionCallback& crash_cb) { | 168 const pp::CompletionCallback& crash_cb) { |
161 CHECK(pp::Module::Get()->core()->IsMainThread()); | 169 CHECK(pp::Module::Get()->core()->IsMainThread()); |
162 // Before forking a new sel_ldr process, ensure that we do not leak | 170 // Before forking a new sel_ldr process, ensure that we do not leak |
163 // the ServiceRuntime object for an existing subprocess, and that any | 171 // the ServiceRuntime object for an existing subprocess, and that any |
164 // associated listener threads do not go unjoined because if they | 172 // associated listener threads do not go unjoined because if they |
165 // outlive the Plugin object, they will not be memory safe. | 173 // outlive the Plugin object, they will not be memory safe. |
166 ShutDownSubprocesses(); | 174 ShutDownSubprocesses(); |
167 pp::Var manifest_base_url = | 175 pp::Var manifest_base_url = |
168 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); | 176 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); |
169 std::string manifest_base_url_str = manifest_base_url.AsString(); | 177 std::string manifest_base_url_str = manifest_base_url.AsString(); |
| 178 |
| 179 PP_NaClFileInfo launch_sel_ldr_file_info; |
| 180 PP_NaClFileInfo load_module_file_info; |
| 181 if (uses_nonsfi_mode) { |
| 182 // In non-SFI mode, LaunchSelLdr is used to pass the nexe file's descriptor |
| 183 // to the plugin. |
| 184 launch_sel_ldr_file_info = file_info; |
| 185 load_module_file_info = kInvalidNaClFileInfo; |
| 186 } else { |
| 187 // Otherwise (i.e. in SFI-mode), LoadModule SRPC is still being used. |
| 188 launch_sel_ldr_file_info = kInvalidNaClFileInfo; |
| 189 load_module_file_info = file_info; |
| 190 } |
| 191 |
170 SelLdrStartParams params(manifest_base_url_str, | 192 SelLdrStartParams params(manifest_base_url_str, |
| 193 launch_sel_ldr_file_info, |
171 true /* uses_irt */, | 194 true /* uses_irt */, |
172 true /* uses_ppapi */, | 195 true /* uses_ppapi */, |
173 uses_nonsfi_mode, | |
174 enable_dyncode_syscalls, | 196 enable_dyncode_syscalls, |
175 enable_exception_handling, | 197 enable_exception_handling, |
176 enable_crash_throttling); | 198 enable_crash_throttling); |
177 ErrorInfo error_info; | 199 ErrorInfo error_info; |
178 ServiceRuntime* service_runtime = | 200 ServiceRuntime* service_runtime = |
179 new ServiceRuntime(this, true, uses_nonsfi_mode, | 201 new ServiceRuntime(this, true, uses_nonsfi_mode, |
180 init_done_cb, crash_cb); | 202 init_done_cb, crash_cb); |
181 main_subprocess_.set_service_runtime(service_runtime); | 203 main_subprocess_.set_service_runtime(service_runtime); |
182 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", | 204 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", |
183 static_cast<void*>(service_runtime))); | 205 static_cast<void*>(service_runtime))); |
184 if (NULL == service_runtime) { | 206 if (NULL == service_runtime) { |
185 error_info.SetReport( | 207 error_info.SetReport( |
186 PP_NACL_ERROR_SEL_LDR_INIT, | 208 PP_NACL_ERROR_SEL_LDR_INIT, |
187 "sel_ldr init failure " + main_subprocess_.description()); | 209 "sel_ldr init failure " + main_subprocess_.description()); |
188 ReportLoadError(error_info); | 210 ReportLoadError(error_info); |
189 return; | 211 return; |
190 } | 212 } |
191 | 213 |
192 // We don't take any action once nexe loading has completed, so pass an empty | 214 // We don't take any action once nexe loading has completed, so pass an empty |
193 // callback here for |callback|. | 215 // callback here for |callback|. |
194 pp::CompletionCallback callback = callback_factory_.NewCallback( | 216 pp::CompletionCallback callback = callback_factory_.NewCallback( |
195 &Plugin::LoadNexeAndStart, | 217 &Plugin::LoadNexeAndStart, |
196 service_runtime, file_info, pp::CompletionCallback()); | 218 service_runtime, load_module_file_info, pp::CompletionCallback()); |
197 StartSelLdrOnMainThread( | 219 StartSelLdrOnMainThread( |
198 static_cast<int32_t>(PP_OK), service_runtime, params, callback); | 220 static_cast<int32_t>(PP_OK), service_runtime, params, callback); |
199 } | 221 } |
200 | 222 |
201 void Plugin::LoadNexeAndStart(int32_t pp_error, | 223 void Plugin::LoadNexeAndStart(int32_t pp_error, |
202 ServiceRuntime* service_runtime, | 224 ServiceRuntime* service_runtime, |
203 PP_NaClFileInfo file_info, | 225 PP_NaClFileInfo file_info, |
204 const pp::CompletionCallback& callback) { | 226 const pp::CompletionCallback& callback) { |
205 CHECK(pp::Module::Get()->core()->IsMainThread()); | 227 CHECK(pp::Module::Get()->core()->IsMainThread()); |
206 if (pp_error != PP_OK) | 228 if (pp_error != PP_OK) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (NULL == nacl_subprocess.get()) { | 263 if (NULL == nacl_subprocess.get()) { |
242 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, | 264 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, |
243 "unable to allocate helper subprocess."); | 265 "unable to allocate helper subprocess."); |
244 return NULL; | 266 return NULL; |
245 } | 267 } |
246 | 268 |
247 // Do not report UMA stats for translator-related nexes. | 269 // Do not report UMA stats for translator-related nexes. |
248 // TODO(sehr): define new UMA stats for translator related nexe events. | 270 // TODO(sehr): define new UMA stats for translator related nexe events. |
249 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is | 271 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is |
250 // done to save on address space and swap space. | 272 // done to save on address space and swap space. |
| 273 // |
| 274 // Currently, this works only in SFI-mode. So, LoadModule SRPC is still used. |
| 275 // So, pass kInvalidNaClFileInfo here, and instead |file_handle| is passed |
| 276 // to LoadNaClModuleFromBackgroundThread() below. |
| 277 // TODO(teravest, hidehiko): Pass file_handle to params, so that LaunchSelLdr |
| 278 // will look at the info. |
251 SelLdrStartParams params(helper_url, | 279 SelLdrStartParams params(helper_url, |
| 280 kInvalidNaClFileInfo, |
252 false /* uses_irt */, | 281 false /* uses_irt */, |
253 false /* uses_ppapi */, | 282 false /* uses_ppapi */, |
254 false /* uses_nonsfi_mode */, | |
255 false /* enable_dyncode_syscalls */, | 283 false /* enable_dyncode_syscalls */, |
256 false /* enable_exception_handling */, | 284 false /* enable_exception_handling */, |
257 true /* enable_crash_throttling */); | 285 true /* enable_crash_throttling */); |
258 | 286 |
259 // Helper NaCl modules always use the PNaCl manifest, as there is no | 287 // Helper NaCl modules always use the PNaCl manifest, as there is no |
260 // corresponding NMF. | 288 // corresponding NMF. |
261 if (!LoadNaClModuleFromBackgroundThread(file_handle, nacl_subprocess.get(), | 289 if (!LoadNaClModuleFromBackgroundThread(file_handle, nacl_subprocess.get(), |
262 params)) { | 290 params)) { |
263 return NULL; | 291 return NULL; |
264 } | 292 } |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 557 |
530 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 558 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
531 int exit_status) { | 559 int exit_status) { |
532 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 560 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
533 DCHECK(nacl_interface_); | 561 DCHECK(nacl_interface_); |
534 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 562 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
535 } | 563 } |
536 | 564 |
537 | 565 |
538 } // namespace plugin | 566 } // namespace plugin |
OLD | NEW |