Chromium Code Reviews| 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..6e84f54e1d011ab8fa0071374f56496fa528af43 100644 |
| --- a/components/nacl/loader/nonsfi/irt_resource_open.cc |
| +++ b/components/nacl/loader/nonsfi/irt_resource_open.cc |
| @@ -2,14 +2,56 @@ |
| // 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 <utility> |
| +#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::pair<std::string, int> >& key_fd_pairs) { |
| + pthread_mutex_lock(&g_mu); |
| + g_fds = new std::map<std::string, int>; |
| + for (size_t i = 0; i < key_fd_pairs.size(); ++i) |
| + g_fds->insert(key_fd_pairs[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); |
|
teravest
2014/11/10 20:36:12
Are the preopened resources only ever opened once
Yusuke Sato
2014/11/11 00:58:35
I think this is reasonable.
* The dynamic linker
|
| + 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 |