OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <pthread.h> |
| 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
5 #include "components/nacl/loader/nonsfi/irt_interfaces.h" | 11 #include "components/nacl/loader/nonsfi/irt_interfaces.h" |
6 #include "ppapi/nacl_irt/irt_manifest.h" | 12 #include "ppapi/nacl_irt/irt_manifest.h" |
7 | 13 |
8 namespace nacl { | 14 namespace nacl { |
9 namespace nonsfi { | 15 namespace nonsfi { |
10 | 16 |
| 17 namespace { |
| 18 |
| 19 pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; |
| 20 std::map<std::string, int>* g_fds; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 void RegisterPreopenedDescriptors(const std::vector<std::string>& keys, |
| 25 const std::vector<int>& fds) { |
| 26 pthread_mutex_lock(&g_mu); |
| 27 g_fds = new std::map<std::string, int>; |
| 28 for (size_t i = 0; i < keys.size(); ++i) |
| 29 g_fds->insert(std::make_pair(keys[i], fds[i])); |
| 30 pthread_mutex_unlock(&g_mu); |
| 31 } |
| 32 |
| 33 int IrtOpenResource(const char* file, int* fd) { |
| 34 pthread_mutex_lock(&g_mu); |
| 35 if (g_fds) { |
| 36 std::map<std::string, int>::iterator it; |
| 37 if (file[0] == '/') |
| 38 it = g_fds->find(file + 1); |
| 39 else |
| 40 it = g_fds->find(file); |
| 41 if (it != g_fds->end()) { |
| 42 *fd = it->second; |
| 43 g_fds->erase(it); |
| 44 pthread_mutex_unlock(&g_mu); |
| 45 return 0; |
| 46 } |
| 47 } |
| 48 pthread_mutex_unlock(&g_mu); |
| 49 return ppapi::IrtOpenResource(file, fd); |
| 50 } |
| 51 |
11 const nacl_irt_resource_open kIrtResourceOpen = { | 52 const nacl_irt_resource_open kIrtResourceOpen = { |
12 ppapi::IrtOpenResource, | 53 nacl::nonsfi::IrtOpenResource, |
13 }; | 54 }; |
14 | 55 |
15 } // namespace nonsfi | 56 } // namespace nonsfi |
16 } // namespace nacl | 57 } // namespace nacl |
OLD | NEW |