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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 int32_t err) { | 130 int32_t err) { |
131 UNREFERENCED_PARAMETER(err); | 131 UNREFERENCED_PARAMETER(err); |
132 NaClLog(4, | 132 NaClLog(4, |
133 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", | 133 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", |
134 p->message.c_str()); | 134 p->message.c_str()); |
135 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); | 135 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); |
136 } | 136 } |
137 | 137 |
138 bool PluginReverseInterface::EnumerateManifestKeys( | 138 bool PluginReverseInterface::EnumerateManifestKeys( |
139 std::set<nacl::string>* out_keys) { | 139 std::set<nacl::string>* out_keys) { |
140 Manifest const* mp = manifest_; | 140 return manifest_->GetFileKeys(out_keys); |
141 | |
142 if (!mp->GetFileKeys(out_keys)) { | |
143 return false; | |
144 } | |
145 | |
146 return true; | |
147 } | 141 } |
148 | 142 |
149 // TODO(bsy): OpenManifestEntry should use the manifest to ResolveKey | 143 // TODO(bsy): OpenManifestEntry should use the manifest to ResolveKey |
150 // and invoke StreamAsFile with a completion callback that invokes | 144 // and invoke StreamAsFile with a completion callback that invokes |
151 // GetPOSIXFileDesc. | 145 // GetPOSIXFileDesc. |
152 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key, | 146 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key, |
153 struct NaClFileInfo* info) { | 147 struct NaClFileInfo* info) { |
154 ErrorInfo error_info; | 148 ErrorInfo error_info; |
155 bool op_complete = false; // NB: mu_ and cv_ also controls access to this! | 149 bool op_complete = false; // NB: mu_ and cv_ also controls access to this! |
156 // The to_open object is owned by the weak ref callback. Because this function | 150 // The to_open object is owned by the weak ref callback. Because this function |
157 // waits for the callback to finish, the to_open object will be deallocated on | 151 // waits for the callback to finish, the to_open object will be deallocated on |
158 // the main thread before this function can return. The pointers it contains | 152 // the main thread before this function can return. The pointers it contains |
159 // to stack variables will not leak. | 153 // to stack variables will not leak. |
160 OpenManifestEntryResource* to_open = | 154 OpenManifestEntryResource* to_open = |
161 new OpenManifestEntryResource(url_key, info, | 155 new OpenManifestEntryResource(url_key, info, |
162 &error_info, &op_complete); | 156 &error_info, &op_complete); |
163 CHECK(to_open != NULL); | 157 CHECK(to_open != NULL); |
164 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: %s\n", | 158 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: %s\n", |
165 url_key.c_str()); | 159 url_key.c_str()); |
166 // This assumes we are not on the main thread. If false, we deadlock. | 160 // This assumes we are not on the main thread. If false, we deadlock. |
167 plugin::WeakRefCallOnMainThread( | 161 plugin::WeakRefCallOnMainThread( |
168 anchor_, | 162 anchor_, |
169 0, | 163 0, |
170 this, | 164 this, |
171 &plugin::PluginReverseInterface::OpenManifestEntry_MainThreadContinuation, | 165 &plugin::PluginReverseInterface::OpenManifestEntry_MainThreadContinuation, |
172 to_open); | 166 to_open); |
173 NaClLog(4, | 167 NaClLog(4, |
174 "PluginReverseInterface::OpenManifestEntry:" | 168 "PluginReverseInterface::OpenManifestEntry:" |
175 " waiting on main thread\n"); | 169 " waiting on main thread\n"); |
176 bool shutting_down; | 170 { |
177 do { | |
178 nacl::MutexLocker take(&mu_); | 171 nacl::MutexLocker take(&mu_); |
179 for (;;) { | 172 while (true) { |
dmichael (off chromium)
2014/03/05 16:54:51
Could this instead be:
while (!shutting_down_ && !
| |
180 NaClLog(4, | 173 NaClLog(4, |
181 "PluginReverseInterface::OpenManifestEntry:" | 174 "PluginReverseInterface::OpenManifestEntry:" |
182 " got lock, checking shutdown and completion: (%s, %s)\n", | 175 " got lock, checking shutdown and completion: (%s, %s)\n", |
183 shutting_down_ ? "yes" : "no", | 176 shutting_down_ ? "yes" : "no", |
184 op_complete ? "yes" : "no"); | 177 op_complete ? "yes" : "no"); |
185 shutting_down = shutting_down_; | 178 if (shutting_down_) { |
186 if (op_complete || shutting_down) { | 179 NaClLog(4, |
180 "PluginReverseInterface::OpenManifestEntry:" | |
181 " plugin is shutting down\n"); | |
182 return false; | |
183 } | |
184 if (op_complete) { | |
187 NaClLog(4, | 185 NaClLog(4, |
188 "PluginReverseInterface::OpenManifestEntry:" | 186 "PluginReverseInterface::OpenManifestEntry:" |
189 " done!\n"); | 187 " done!\n"); |
190 break; | 188 break; |
191 } | 189 } |
192 NaClXCondVarWait(&cv_, &mu_); | 190 NaClXCondVarWait(&cv_, &mu_); |
193 } | 191 } |
194 } while (0); | |
195 if (shutting_down) { | |
196 NaClLog(4, | |
197 "PluginReverseInterface::OpenManifestEntry:" | |
198 " plugin is shutting down\n"); | |
199 return false; | |
200 } | 192 } |
201 // out_desc has the returned descriptor if successful, else -1. | |
202 | 193 |
203 // The caller is responsible for not closing *out_desc. If it is | 194 // info->desc has the returned descriptor if successful, else -1. |
195 | |
196 // The caller is responsible for not closing info->desc. If it is | |
204 // closed prematurely, then another open could re-use the OS | 197 // closed prematurely, then another open could re-use the OS |
205 // descriptor, confusing the opened_ map. If the caller is going to | 198 // descriptor, confusing the opened_ map. If the caller is going to |
206 // want to make a NaClDesc object and transfer it etc., then the | 199 // want to make a NaClDesc object and transfer it etc., then the |
207 // caller should DUP the descriptor (but remember the original | 200 // caller should DUP the descriptor (but remember the original |
208 // value) for use by the NaClDesc object, which closes when the | 201 // value) for use by the NaClDesc object, which closes when the |
209 // object is destroyed. | 202 // object is destroyed. |
210 NaClLog(4, | 203 NaClLog(4, |
211 "PluginReverseInterface::OpenManifestEntry:" | 204 "PluginReverseInterface::OpenManifestEntry: info->desc = %d\n", |
212 " *out_desc = %d\n", | |
213 info->desc); | 205 info->desc); |
214 if (info->desc == -1) { | 206 if (info->desc == -1) { |
215 // TODO(bsy,ncbray): what else should we do with the error? This | 207 // TODO(bsy,ncbray): what else should we do with the error? This |
216 // is a runtime error that may simply be a programming error in | 208 // is a runtime error that may simply be a programming error in |
217 // the untrusted code, or it may be something else wrong w/ the | 209 // the untrusted code, or it may be something else wrong w/ the |
218 // manifest. | 210 // manifest. |
219 NaClLog(4, | 211 NaClLog(4, |
220 "OpenManifestEntry: failed for key %s, code %d (%s)\n", | 212 "OpenManifestEntry: failed for key %s, code %d (%s)\n", |
221 url_key.c_str(), | 213 url_key.c_str(), |
222 error_info.error_code(), | 214 error_info.error_code(), |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 *p->op_complete_ptr = true; | 344 *p->op_complete_ptr = true; |
353 NaClXCondVarBroadcast(&cv_); | 345 NaClXCondVarBroadcast(&cv_); |
354 } | 346 } |
355 | 347 |
356 bool PluginReverseInterface::CloseManifestEntry(int32_t desc) { | 348 bool PluginReverseInterface::CloseManifestEntry(int32_t desc) { |
357 bool op_complete = false; | 349 bool op_complete = false; |
358 bool op_result; | 350 bool op_result; |
359 CloseManifestEntryResource* to_close = | 351 CloseManifestEntryResource* to_close = |
360 new CloseManifestEntryResource(desc, &op_complete, &op_result); | 352 new CloseManifestEntryResource(desc, &op_complete, &op_result); |
361 | 353 |
362 bool shutting_down; | |
363 plugin::WeakRefCallOnMainThread( | 354 plugin::WeakRefCallOnMainThread( |
364 anchor_, | 355 anchor_, |
365 0, | 356 0, |
366 this, | 357 this, |
367 &plugin::PluginReverseInterface:: | 358 &plugin::PluginReverseInterface:: |
368 CloseManifestEntry_MainThreadContinuation, | 359 CloseManifestEntry_MainThreadContinuation, |
369 to_close); | 360 to_close); |
361 | |
370 // wait for completion or surf-away. | 362 // wait for completion or surf-away. |
371 do { | 363 { |
372 nacl::MutexLocker take(&mu_); | 364 nacl::MutexLocker take(&mu_); |
373 for (;;) { | 365 while (true) { |
dmichael (off chromium)
2014/03/05 16:54:51
I think you could do the same kind of transformati
| |
374 shutting_down = shutting_down_; | 366 if (shutting_down_) |
375 if (op_complete || shutting_down) { | 367 return false; |
368 if (op_complete) | |
376 break; | 369 break; |
377 } | |
378 NaClXCondVarWait(&cv_, &mu_); | 370 NaClXCondVarWait(&cv_, &mu_); |
379 } | 371 } |
380 } while (0); | 372 } |
381 | 373 |
382 if (shutting_down) return false; | |
383 // op_result true if close was successful; false otherwise (e.g., bad desc). | 374 // op_result true if close was successful; false otherwise (e.g., bad desc). |
384 return op_result; | 375 return op_result; |
385 } | 376 } |
386 | 377 |
387 void PluginReverseInterface::CloseManifestEntry_MainThreadContinuation( | 378 void PluginReverseInterface::CloseManifestEntry_MainThreadContinuation( |
388 CloseManifestEntryResource* cls, | 379 CloseManifestEntryResource* cls, |
389 int32_t err) { | 380 int32_t err) { |
390 UNREFERENCED_PARAMETER(err); | 381 UNREFERENCED_PARAMETER(err); |
391 | 382 |
392 nacl::MutexLocker take(&mu_); | 383 nacl::MutexLocker take(&mu_); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 | 730 |
740 nacl::string ServiceRuntime::GetCrashLogOutput() { | 731 nacl::string ServiceRuntime::GetCrashLogOutput() { |
741 if (NULL != subprocess_.get()) { | 732 if (NULL != subprocess_.get()) { |
742 return subprocess_->GetCrashLogOutput(); | 733 return subprocess_->GetCrashLogOutput(); |
743 } else { | 734 } else { |
744 return std::string(); | 735 return std::string(); |
745 } | 736 } |
746 } | 737 } |
747 | 738 |
748 } // namespace plugin | 739 } // namespace plugin |
OLD | NEW |