Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 44 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 45 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | 45 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" |
| 46 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" | 46 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" |
| 47 #include "ppapi/native_client/src/trusted/plugin/sel_ldr_launcher_chrome.h" | 47 #include "ppapi/native_client/src/trusted/plugin/sel_ldr_launcher_chrome.h" |
| 48 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h" | 48 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h" |
| 49 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 49 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
| 50 #include "ppapi/native_client/src/trusted/weak_ref/call_on_main_thread.h" | 50 #include "ppapi/native_client/src/trusted/weak_ref/call_on_main_thread.h" |
| 51 | 51 |
| 52 namespace plugin { | 52 namespace plugin { |
| 53 | 53 |
| 54 class OpenManifestEntryAsyncCallback { | |
| 55 public: | |
| 56 OpenManifestEntryAsyncCallback(PP_OpenResourceCompletionCallback callback, | |
| 57 void* callback_user_data) | |
| 58 : callback_(callback), callback_user_data_(callback_user_data) { | |
| 59 } | |
| 60 | |
| 61 ~OpenManifestEntryAsyncCallback() { | |
| 62 if (callback_) | |
| 63 callback_(callback_user_data_, PP_kInvalidFileHandle); | |
| 64 } | |
| 65 | |
| 66 void Run(int32_t pp_error) { | |
| 67 #if defined(OS_WIN) | |
| 68 // Currently, this is used only for non-SFI mode, and now the mode is not | |
| 69 // supported on windows. | |
| 70 // TODO(hidehiko): Support it on Windows when we switch to use | |
| 71 // ManifestService also in SFI-mode. | |
| 72 NACL_NOTREACHED(); | |
| 73 #elif defined(OS_POSIX) | |
| 74 // On posix, PlatformFile is the file descriptor. | |
| 75 callback_(callback_user_data_, (pp_error == PP_OK) ? info_.desc : -1); | |
| 76 callback_ = NULL; | |
| 77 #endif | |
| 78 } | |
| 79 | |
| 80 NaClFileInfo* mutable_info() { return &info_; } | |
| 81 | |
| 82 private: | |
| 83 NaClFileInfo info_; | |
| 84 PP_OpenResourceCompletionCallback callback_; | |
| 85 void* callback_user_data_; | |
| 86 DISALLOW_COPY_AND_ASSIGN(OpenManifestEntryAsyncCallback); | |
| 87 }; | |
| 88 | |
| 89 namespace { | 54 namespace { |
| 90 | 55 |
| 91 class ManifestService { | 56 class ManifestService { |
| 92 public: | 57 public: |
| 93 ManifestService(nacl::WeakRefAnchor* anchor, | 58 ManifestService(nacl::WeakRefAnchor* anchor, |
| 94 PluginReverseInterface* plugin_reverse) | 59 PluginReverseInterface* plugin_reverse) |
| 95 : anchor_(anchor), | 60 : anchor_(anchor), |
| 96 plugin_reverse_(plugin_reverse) { | 61 plugin_reverse_(plugin_reverse) { |
| 97 } | 62 } |
| 98 | 63 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 109 // Release this instance if the ServiceRuntime is already destructed. | 74 // Release this instance if the ServiceRuntime is already destructed. |
| 110 if (anchor_->is_abandoned()) { | 75 if (anchor_->is_abandoned()) { |
| 111 delete this; | 76 delete this; |
| 112 return false; | 77 return false; |
| 113 } | 78 } |
| 114 | 79 |
| 115 plugin_reverse_->StartupInitializationComplete(); | 80 plugin_reverse_->StartupInitializationComplete(); |
| 116 return true; | 81 return true; |
| 117 } | 82 } |
| 118 | 83 |
| 119 bool OpenResource(const char* entry_key, | |
| 120 PP_OpenResourceCompletionCallback callback, | |
| 121 void* callback_user_data) { | |
| 122 // Release this instance if the ServiceRuntime is already destructed. | |
| 123 if (anchor_->is_abandoned()) { | |
| 124 callback(callback_user_data, PP_kInvalidFileHandle); | |
| 125 delete this; | |
| 126 return false; | |
| 127 } | |
| 128 | |
| 129 OpenManifestEntryAsyncCallback* open_manifest_callback = | |
| 130 new OpenManifestEntryAsyncCallback(callback, callback_user_data); | |
| 131 plugin_reverse_->OpenManifestEntryAsync( | |
| 132 entry_key, | |
| 133 open_manifest_callback->mutable_info(), | |
| 134 open_manifest_callback); | |
| 135 return true; | |
| 136 } | |
| 137 | |
| 138 static PP_Bool QuitTrampoline(void* user_data) { | 84 static PP_Bool QuitTrampoline(void* user_data) { |
| 139 return PP_FromBool(static_cast<ManifestService*>(user_data)->Quit()); | 85 return PP_FromBool(static_cast<ManifestService*>(user_data)->Quit()); |
| 140 } | 86 } |
| 141 | 87 |
| 142 static PP_Bool StartupInitializationCompleteTrampoline(void* user_data) { | 88 static PP_Bool StartupInitializationCompleteTrampoline(void* user_data) { |
| 143 return PP_FromBool(static_cast<ManifestService*>(user_data)-> | 89 return PP_FromBool(static_cast<ManifestService*>(user_data)-> |
| 144 StartupInitializationComplete()); | 90 StartupInitializationComplete()); |
| 145 } | 91 } |
| 146 | 92 |
| 147 static PP_Bool OpenResourceTrampoline( | |
| 148 void* user_data, | |
| 149 const char* entry_key, | |
| 150 PP_OpenResourceCompletionCallback callback, | |
| 151 void* callback_user_data) { | |
| 152 return PP_FromBool(static_cast<ManifestService*>(user_data)->OpenResource( | |
| 153 entry_key, callback, callback_user_data)); | |
| 154 } | |
| 155 | |
| 156 private: | 93 private: |
| 157 // Weak reference to check if plugin_reverse is legally accessible or not. | 94 // Weak reference to check if plugin_reverse is legally accessible or not. |
| 158 nacl::WeakRefAnchor* anchor_; | 95 nacl::WeakRefAnchor* anchor_; |
| 159 PluginReverseInterface* plugin_reverse_; | 96 PluginReverseInterface* plugin_reverse_; |
| 160 | 97 |
| 161 DISALLOW_COPY_AND_ASSIGN(ManifestService); | 98 DISALLOW_COPY_AND_ASSIGN(ManifestService); |
| 162 }; | 99 }; |
| 163 | 100 |
| 164 // Vtable to pass functions to LaunchSelLdr. | 101 // Vtable to pass functions to LaunchSelLdr. |
| 165 const PPP_ManifestService kManifestServiceVTable = { | 102 const PPP_ManifestService kManifestServiceVTable = { |
| 166 &ManifestService::QuitTrampoline, | 103 &ManifestService::QuitTrampoline, |
| 167 &ManifestService::StartupInitializationCompleteTrampoline, | 104 &ManifestService::StartupInitializationCompleteTrampoline, |
| 168 &ManifestService::OpenResourceTrampoline, | 105 NULL |
|
dmichael (off chromium)
2014/06/17 21:52:28
Can we remove that from PPP_ManifestService in thi
teravest
2014/06/18 20:13:44
Done.
| |
| 169 }; | 106 }; |
| 170 | 107 |
| 171 } // namespace | 108 } // namespace |
| 172 | 109 |
| 173 OpenManifestEntryResource::~OpenManifestEntryResource() { | 110 OpenManifestEntryResource::~OpenManifestEntryResource() { |
| 174 MaybeRunCallback(PP_ERROR_ABORTED); | |
| 175 } | |
| 176 | |
| 177 void OpenManifestEntryResource::MaybeRunCallback(int32_t pp_error) { | |
| 178 if (!callback) | |
| 179 return; | |
| 180 | |
| 181 callback->Run(pp_error); | |
| 182 delete callback; | |
| 183 callback = NULL; | |
| 184 } | 111 } |
| 185 | 112 |
| 186 PluginReverseInterface::PluginReverseInterface( | 113 PluginReverseInterface::PluginReverseInterface( |
| 187 nacl::WeakRefAnchor* anchor, | 114 nacl::WeakRefAnchor* anchor, |
| 188 Plugin* plugin, | 115 Plugin* plugin, |
| 189 ServiceRuntime* service_runtime, | 116 ServiceRuntime* service_runtime, |
| 190 pp::CompletionCallback init_done_cb, | 117 pp::CompletionCallback init_done_cb, |
| 191 pp::CompletionCallback crash_cb) | 118 pp::CompletionCallback crash_cb) |
| 192 : anchor_(anchor), | 119 : anchor_(anchor), |
| 193 plugin_(plugin), | 120 plugin_(plugin), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // and invoke StreamAsFile with a completion callback that invokes | 163 // and invoke StreamAsFile with a completion callback that invokes |
| 237 // GetPOSIXFileDesc. | 164 // GetPOSIXFileDesc. |
| 238 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key, | 165 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key, |
| 239 struct NaClFileInfo* info) { | 166 struct NaClFileInfo* info) { |
| 240 bool op_complete = false; // NB: mu_ and cv_ also controls access to this! | 167 bool op_complete = false; // NB: mu_ and cv_ also controls access to this! |
| 241 // The to_open object is owned by the weak ref callback. Because this function | 168 // The to_open object is owned by the weak ref callback. Because this function |
| 242 // waits for the callback to finish, the to_open object will be deallocated on | 169 // waits for the callback to finish, the to_open object will be deallocated on |
| 243 // the main thread before this function can return. The pointers it contains | 170 // the main thread before this function can return. The pointers it contains |
| 244 // to stack variables will not leak. | 171 // to stack variables will not leak. |
| 245 OpenManifestEntryResource* to_open = | 172 OpenManifestEntryResource* to_open = |
| 246 new OpenManifestEntryResource(url_key, info, &op_complete, NULL); | 173 new OpenManifestEntryResource(url_key, info, &op_complete); |
| 247 CHECK(to_open != NULL); | 174 CHECK(to_open != NULL); |
| 248 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: %s\n", | 175 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: %s\n", |
| 249 url_key.c_str()); | 176 url_key.c_str()); |
| 250 // This assumes we are not on the main thread. If false, we deadlock. | 177 // This assumes we are not on the main thread. If false, we deadlock. |
| 251 plugin::WeakRefCallOnMainThread( | 178 plugin::WeakRefCallOnMainThread( |
| 252 anchor_, | 179 anchor_, |
| 253 0, | 180 0, |
| 254 this, | 181 this, |
| 255 &plugin::PluginReverseInterface::OpenManifestEntry_MainThreadContinuation, | 182 &plugin::PluginReverseInterface::OpenManifestEntry_MainThreadContinuation, |
| 256 to_open); | 183 to_open); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 286 if (info->desc == -1) { | 213 if (info->desc == -1) { |
| 287 // TODO(bsy,ncbray): what else should we do with the error? This | 214 // TODO(bsy,ncbray): what else should we do with the error? This |
| 288 // is a runtime error that may simply be a programming error in | 215 // is a runtime error that may simply be a programming error in |
| 289 // the untrusted code, or it may be something else wrong w/ the | 216 // the untrusted code, or it may be something else wrong w/ the |
| 290 // manifest. | 217 // manifest. |
| 291 NaClLog(4, "OpenManifestEntry: failed for key %s", url_key.c_str()); | 218 NaClLog(4, "OpenManifestEntry: failed for key %s", url_key.c_str()); |
| 292 } | 219 } |
| 293 return true; | 220 return true; |
| 294 } | 221 } |
| 295 | 222 |
| 296 void PluginReverseInterface::OpenManifestEntryAsync( | |
| 297 const nacl::string& entry_key, | |
| 298 struct NaClFileInfo* info, | |
| 299 OpenManifestEntryAsyncCallback* callback) { | |
| 300 bool op_complete = false; | |
| 301 OpenManifestEntryResource to_open( | |
| 302 entry_key, info, &op_complete, callback); | |
| 303 OpenManifestEntry_MainThreadContinuation(&to_open, PP_OK); | |
| 304 } | |
| 305 | |
| 306 // Transfer point from OpenManifestEntry() which runs on the main thread | 223 // Transfer point from OpenManifestEntry() which runs on the main thread |
| 307 // (Some PPAPI actions -- like StreamAsFile -- can only run on the main thread). | 224 // (Some PPAPI actions -- like StreamAsFile -- can only run on the main thread). |
| 308 // OpenManifestEntry() is waiting on a condvar for this continuation to | 225 // OpenManifestEntry() is waiting on a condvar for this continuation to |
| 309 // complete. We Broadcast and awaken OpenManifestEntry() whenever we are done | 226 // complete. We Broadcast and awaken OpenManifestEntry() whenever we are done |
| 310 // either here, or in a later MainThreadContinuation step, if there are | 227 // either here, or in a later MainThreadContinuation step, if there are |
| 311 // multiple steps. | 228 // multiple steps. |
| 312 void PluginReverseInterface::OpenManifestEntry_MainThreadContinuation( | 229 void PluginReverseInterface::OpenManifestEntry_MainThreadContinuation( |
| 313 OpenManifestEntryResource* p, | 230 OpenManifestEntryResource* p, |
| 314 int32_t err) { | 231 int32_t err) { |
| 315 UNREFERENCED_PARAMETER(err); | 232 UNREFERENCED_PARAMETER(err); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 327 &pnacl_options)) { | 244 &pnacl_options)) { |
| 328 NaClLog(4, "OpenManifestEntry_MainThreadContinuation: ResolveKey failed\n"); | 245 NaClLog(4, "OpenManifestEntry_MainThreadContinuation: ResolveKey failed\n"); |
| 329 // Failed, and error_info has the details on what happened. Wake | 246 // Failed, and error_info has the details on what happened. Wake |
| 330 // up requesting thread -- we are done. | 247 // up requesting thread -- we are done. |
| 331 { | 248 { |
| 332 nacl::MutexLocker take(&mu_); | 249 nacl::MutexLocker take(&mu_); |
| 333 *p->op_complete_ptr = true; // done... | 250 *p->op_complete_ptr = true; // done... |
| 334 p->file_info->desc = -1; // but failed. | 251 p->file_info->desc = -1; // but failed. |
| 335 NaClXCondVarBroadcast(&cv_); | 252 NaClXCondVarBroadcast(&cv_); |
| 336 } | 253 } |
| 337 p->MaybeRunCallback(PP_OK); | |
| 338 return; | 254 return; |
| 339 } | 255 } |
| 340 nacl::string mapped_url = pp::Var(pp_mapped_url).AsString(); | 256 nacl::string mapped_url = pp::Var(pp_mapped_url).AsString(); |
| 341 NaClLog(4, | 257 NaClLog(4, |
| 342 "OpenManifestEntry_MainThreadContinuation: " | 258 "OpenManifestEntry_MainThreadContinuation: " |
| 343 "ResolveKey: %s -> %s (pnacl_translate(%d))\n", | 259 "ResolveKey: %s -> %s (pnacl_translate(%d))\n", |
| 344 p->url.c_str(), mapped_url.c_str(), pnacl_options.translate); | 260 p->url.c_str(), mapped_url.c_str(), pnacl_options.translate); |
| 345 | 261 |
| 346 if (pnacl_options.translate) { | 262 if (pnacl_options.translate) { |
| 347 // Requires PNaCl translation, but that's not supported. | 263 // Requires PNaCl translation, but that's not supported. |
| 348 NaClLog(4, | 264 NaClLog(4, |
| 349 "OpenManifestEntry_MainThreadContinuation: " | 265 "OpenManifestEntry_MainThreadContinuation: " |
| 350 "Requires PNaCl translation -- not supported\n"); | 266 "Requires PNaCl translation -- not supported\n"); |
| 351 { | 267 { |
| 352 nacl::MutexLocker take(&mu_); | 268 nacl::MutexLocker take(&mu_); |
| 353 *p->op_complete_ptr = true; // done... | 269 *p->op_complete_ptr = true; // done... |
| 354 p->file_info->desc = -1; // but failed. | 270 p->file_info->desc = -1; // but failed. |
| 355 NaClXCondVarBroadcast(&cv_); | 271 NaClXCondVarBroadcast(&cv_); |
| 356 } | 272 } |
| 357 p->MaybeRunCallback(PP_OK); | |
| 358 return; | 273 return; |
| 359 } | 274 } |
| 360 | 275 |
| 361 // Because p is owned by the callback of this invocation, so it is necessary | 276 // Because p is owned by the callback of this invocation, so it is necessary |
| 362 // to create another instance. | 277 // to create another instance. |
| 363 OpenManifestEntryResource* open_cont = new OpenManifestEntryResource(*p); | 278 OpenManifestEntryResource* open_cont = new OpenManifestEntryResource(*p); |
| 364 open_cont->url = mapped_url; | 279 open_cont->url = mapped_url; |
| 365 // Callback is now delegated from p to open_cont. So, here we manually clear | |
| 366 // complete callback. | |
| 367 p->callback = NULL; | |
| 368 | 280 |
| 369 pp::CompletionCallback stream_cc = WeakRefNewCallback( | 281 pp::CompletionCallback stream_cc = WeakRefNewCallback( |
| 370 anchor_, | 282 anchor_, |
| 371 this, | 283 this, |
| 372 &PluginReverseInterface::StreamAsFile_MainThreadContinuation, | 284 &PluginReverseInterface::StreamAsFile_MainThreadContinuation, |
| 373 open_cont); | 285 open_cont); |
| 374 | 286 |
| 375 GetNaClInterface()->DownloadFile(plugin_->pp_instance(), | 287 GetNaClInterface()->DownloadFile(plugin_->pp_instance(), |
| 376 mapped_url.c_str(), | 288 mapped_url.c_str(), |
| 377 &open_cont->pp_file_info, | 289 &open_cont->pp_file_info, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 396 p->file_info->desc); | 308 p->file_info->desc); |
| 397 } else { | 309 } else { |
| 398 NaClLog( | 310 NaClLog( |
| 399 4, | 311 4, |
| 400 "StreamAsFile_MainThreadContinuation: !PP_OK, setting desc -1\n"); | 312 "StreamAsFile_MainThreadContinuation: !PP_OK, setting desc -1\n"); |
| 401 p->file_info->desc = -1; | 313 p->file_info->desc = -1; |
| 402 } | 314 } |
| 403 *p->op_complete_ptr = true; | 315 *p->op_complete_ptr = true; |
| 404 NaClXCondVarBroadcast(&cv_); | 316 NaClXCondVarBroadcast(&cv_); |
| 405 } | 317 } |
| 406 p->MaybeRunCallback(PP_OK); | |
| 407 } | 318 } |
| 408 | 319 |
| 409 bool PluginReverseInterface::CloseManifestEntry(int32_t desc) { | 320 bool PluginReverseInterface::CloseManifestEntry(int32_t desc) { |
| 410 // We don't take any action on a call to CloseManifestEntry today, so always | 321 // We don't take any action on a call to CloseManifestEntry today, so always |
| 411 // return success. | 322 // return success. |
| 412 return true; | 323 return true; |
| 413 } | 324 } |
| 414 | 325 |
| 415 void PluginReverseInterface::ReportCrash() { | 326 void PluginReverseInterface::ReportCrash() { |
| 416 NaClLog(4, "PluginReverseInterface::ReportCrash\n"); | 327 NaClLog(4, "PluginReverseInterface::ReportCrash\n"); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 | 770 |
| 860 nacl::string ServiceRuntime::GetCrashLogOutput() { | 771 nacl::string ServiceRuntime::GetCrashLogOutput() { |
| 861 if (NULL != subprocess_.get()) { | 772 if (NULL != subprocess_.get()) { |
| 862 return subprocess_->GetCrashLogOutput(); | 773 return subprocess_->GetCrashLogOutput(); |
| 863 } else { | 774 } else { |
| 864 return std::string(); | 775 return std::string(); |
| 865 } | 776 } |
| 866 } | 777 } |
| 867 | 778 |
| 868 } // namespace plugin | 779 } // namespace plugin |
| OLD | NEW |