| 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
|
|
|