Chromium Code Reviews| 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 <utility> | |
| 10 #include <vector> | |
| 11 | |
| 5 #include "components/nacl/loader/nonsfi/irt_interfaces.h" | 12 #include "components/nacl/loader/nonsfi/irt_interfaces.h" |
| 6 #include "ppapi/nacl_irt/irt_manifest.h" | 13 #include "ppapi/nacl_irt/irt_manifest.h" |
| 7 | 14 |
| 8 namespace nacl { | 15 namespace nacl { |
| 9 namespace nonsfi { | 16 namespace nonsfi { |
| 10 | 17 |
| 18 namespace { | |
| 19 | |
| 20 pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; | |
| 21 std::map<std::string, int>* g_fds; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 void RegisterPreopenedDescriptors( | |
| 26 const std::vector<std::pair<std::string, int> >& key_fd_pairs) { | |
| 27 pthread_mutex_lock(&g_mu); | |
| 28 g_fds = new std::map<std::string, int>; | |
| 29 for (size_t i = 0; i < key_fd_pairs.size(); ++i) | |
| 30 g_fds->insert(key_fd_pairs[i]); | |
| 31 pthread_mutex_unlock(&g_mu); | |
| 32 } | |
| 33 | |
| 34 int IrtOpenResource(const char* file, int* fd) { | |
| 35 pthread_mutex_lock(&g_mu); | |
| 36 if (g_fds) { | |
| 37 std::map<std::string, int>::iterator it; | |
| 38 if (file[0] == '/') | |
| 39 it = g_fds->find(file + 1); | |
| 40 else | |
| 41 it = g_fds->find(file); | |
| 42 if (it != g_fds->end()) { | |
| 43 *fd = it->second; | |
| 44 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
| |
| 45 pthread_mutex_unlock(&g_mu); | |
| 46 return 0; | |
| 47 } | |
| 48 } | |
| 49 pthread_mutex_unlock(&g_mu); | |
| 50 return ppapi::IrtOpenResource(file, fd); | |
| 51 } | |
| 52 | |
| 11 const nacl_irt_resource_open kIrtResourceOpen = { | 53 const nacl_irt_resource_open kIrtResourceOpen = { |
| 12 ppapi::IrtOpenResource, | 54 nacl::nonsfi::IrtOpenResource, |
| 13 }; | 55 }; |
| 14 | 56 |
| 15 } // namespace nonsfi | 57 } // namespace nonsfi |
| 16 } // namespace nacl | 58 } // namespace nacl |
| OLD | NEW |