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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 private: | 82 private: |
83 NaClFileInfo info_; | 83 NaClFileInfo info_; |
84 PP_OpenResourceCompletionCallback callback_; | 84 PP_OpenResourceCompletionCallback callback_; |
85 void* callback_user_data_; | 85 void* callback_user_data_; |
86 DISALLOW_COPY_AND_ASSIGN(OpenManifestEntryAsyncCallback); | 86 DISALLOW_COPY_AND_ASSIGN(OpenManifestEntryAsyncCallback); |
87 }; | 87 }; |
88 | 88 |
89 namespace { | 89 namespace { |
90 | 90 |
91 // For doing crude quota enforcement on writes to temp files. | |
92 // We do not allow a temp file bigger than 128 MB for now. | |
93 // There is currently a limit of 32M for nexe text size, so 128M | |
94 // should be plenty for static data | |
95 const int64_t kMaxTempQuota = 0x8000000; | |
96 | |
97 class ManifestService { | 91 class ManifestService { |
98 public: | 92 public: |
99 ManifestService(nacl::WeakRefAnchor* anchor, | 93 ManifestService(nacl::WeakRefAnchor* anchor, |
100 PluginReverseInterface* plugin_reverse) | 94 PluginReverseInterface* plugin_reverse) |
101 : anchor_(anchor), | 95 : anchor_(anchor), |
102 plugin_reverse_(plugin_reverse) { | 96 plugin_reverse_(plugin_reverse) { |
103 } | 97 } |
104 | 98 |
105 ~ManifestService() { | 99 ~ManifestService() { |
106 anchor_->Unref(); | 100 anchor_->Unref(); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 " crash_cb_ not valid, skipping\n"); | 462 " crash_cb_ not valid, skipping\n"); |
469 } | 463 } |
470 } | 464 } |
471 | 465 |
472 void PluginReverseInterface::ReportExitStatus(int exit_status) { | 466 void PluginReverseInterface::ReportExitStatus(int exit_status) { |
473 service_runtime_->set_exit_status(exit_status); | 467 service_runtime_->set_exit_status(exit_status); |
474 } | 468 } |
475 | 469 |
476 int64_t PluginReverseInterface::RequestQuotaForWrite( | 470 int64_t PluginReverseInterface::RequestQuotaForWrite( |
477 nacl::string file_id, int64_t offset, int64_t bytes_to_write) { | 471 nacl::string file_id, int64_t offset, int64_t bytes_to_write) { |
478 NaClLog(4, | |
479 "PluginReverseInterface::RequestQuotaForWrite:" | |
480 " (file_id='%s', offset=%" NACL_PRId64 ", bytes_to_write=%" | |
481 NACL_PRId64 ")\n", file_id.c_str(), offset, bytes_to_write); | |
482 uint64_t file_key = STRTOULL(file_id.c_str(), NULL, 10); | |
483 nacl::MutexLocker take(&mu_); | |
484 if (quota_files_.count(file_key) == 0) { | |
485 // Look up failed to find the requested quota managed resource. | |
486 NaClLog(4, "PluginReverseInterface::RequestQuotaForWrite: failed...\n"); | |
487 return 0; | |
488 } | |
489 | |
490 // Because we now only support this interface for tempfiles which are not | |
491 // pepper objects, we can just do some crude quota enforcement here rather | |
492 // than calling out to pepper from the main thread. | |
493 if (offset + bytes_to_write >= kMaxTempQuota) | |
494 return 0; | |
495 | |
496 return bytes_to_write; | 472 return bytes_to_write; |
497 } | 473 } |
498 | 474 |
499 void PluginReverseInterface::AddTempQuotaManagedFile( | |
500 const nacl::string& file_id) { | |
501 NaClLog(4, "PluginReverseInterface::AddTempQuotaManagedFile: " | |
502 "(file_id='%s')\n", file_id.c_str()); | |
503 uint64_t file_key = STRTOULL(file_id.c_str(), NULL, 10); | |
504 nacl::MutexLocker take(&mu_); | |
505 quota_files_.insert(file_key); | |
506 } | |
507 | |
508 ServiceRuntime::ServiceRuntime(Plugin* plugin, | 475 ServiceRuntime::ServiceRuntime(Plugin* plugin, |
509 int32_t manifest_id, | 476 int32_t manifest_id, |
510 bool main_service_runtime, | 477 bool main_service_runtime, |
511 bool uses_nonsfi_mode, | 478 bool uses_nonsfi_mode, |
512 pp::CompletionCallback init_done_cb, | 479 pp::CompletionCallback init_done_cb, |
513 pp::CompletionCallback crash_cb) | 480 pp::CompletionCallback crash_cb) |
514 : plugin_(plugin), | 481 : plugin_(plugin), |
515 main_service_runtime_(main_service_runtime), | 482 main_service_runtime_(main_service_runtime), |
516 uses_nonsfi_mode_(uses_nonsfi_mode), | 483 uses_nonsfi_mode_(uses_nonsfi_mode), |
517 reverse_service_(NULL), | 484 reverse_service_(NULL), |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 801 |
835 nacl::string ServiceRuntime::GetCrashLogOutput() { | 802 nacl::string ServiceRuntime::GetCrashLogOutput() { |
836 if (NULL != subprocess_.get()) { | 803 if (NULL != subprocess_.get()) { |
837 return subprocess_->GetCrashLogOutput(); | 804 return subprocess_->GetCrashLogOutput(); |
838 } else { | 805 } else { |
839 return std::string(); | 806 return std::string(); |
840 } | 807 } |
841 } | 808 } |
842 | 809 |
843 } // namespace plugin | 810 } // namespace plugin |
OLD | NEW |