Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: components/nacl/loader/nonsfi/irt_resource_open.cc

Issue 649603004: Non-SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/nacl/loader/nonsfi/irt_resource_open.cc
diff --git a/components/nacl/loader/nonsfi/irt_resource_open.cc b/components/nacl/loader/nonsfi/irt_resource_open.cc
index cf193c13ba14c82afa410f2dd37ba4161ead9c35..011d9140cc1a60e3558e65d390917a27c6e8d8f5 100644
--- a/components/nacl/loader/nonsfi/irt_resource_open.cc
+++ b/components/nacl/loader/nonsfi/irt_resource_open.cc
@@ -2,14 +2,55 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <pthread.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "ppapi/nacl_irt/irt_manifest.h"
namespace nacl {
namespace nonsfi {
+namespace {
+
+pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER;
+std::map<std::string, int>* g_fds;
+
+} // namespace
+
+void RegisterPreopenedDescriptors(const std::vector<std::string>& keys,
+ const std::vector<int>& fds) {
+ pthread_mutex_lock(&g_mu);
+ g_fds = new std::map<std::string, int>;
+ for (size_t i = 0; i < keys.size(); ++i)
+ g_fds->insert(std::make_pair(keys[i], fds[i]));
+ pthread_mutex_unlock(&g_mu);
+}
+
+int IrtOpenResource(const char* file, int* fd) {
+ pthread_mutex_lock(&g_mu);
+ if (g_fds) {
+ std::map<std::string, int>::iterator it;
+ if (file[0] == '/')
+ it = g_fds->find(file + 1);
+ else
+ it = g_fds->find(file);
+ if (it != g_fds->end()) {
+ *fd = it->second;
+ g_fds->erase(it);
+ pthread_mutex_unlock(&g_mu);
+ return 0;
+ }
+ }
+ pthread_mutex_unlock(&g_mu);
+ return ppapi::IrtOpenResource(file, fd);
+}
+
const nacl_irt_resource_open kIrtResourceOpen = {
- ppapi::IrtOpenResource,
+ nacl::nonsfi::IrtOpenResource,
};
} // namespace nonsfi

Powered by Google App Engine
This is Rietveld 408576698