OLD | NEW |
---|---|
1 // Copyright 2016 The Native Client Authors. All rights reserved. | 1 // Copyright 2016 The Native Client 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 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_PLL_LOADER_PLL_LOADER_H_ | 5 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_PLL_LOADER_PLL_LOADER_H_ |
6 #define NATIVE_CLIENT_SRC_UNTRUSTED_PLL_LOADER_PLL_LOADER_H_ 1 | 6 #define NATIVE_CLIENT_SRC_UNTRUSTED_PLL_LOADER_PLL_LOADER_H_ 1 |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <unordered_set> | 9 #include <unordered_set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "native_client/src/untrusted/pll_loader/pll_root.h" | 12 #include "native_client/src/untrusted/pll_loader/pll_root.h" |
13 | 13 |
14 // This helper class wraps the PLLRoot data structure and provides methods | 14 // This helper class wraps the PLLRoot data structure and provides methods |
15 // for accessing parts of PLLRoot. | 15 // for accessing parts of PLLRoot. |
16 class PLLModule { | 16 class PLLModule { |
17 public: | 17 public: |
18 explicit PLLModule(const PLLRoot *root) : root_(root) {} | 18 explicit PLLModule(const PLLRoot *root) : root_(root) {} |
19 | 19 |
20 static uint32_t HashString(const char *sp); | 20 static uint32_t HashString(const char *sp); |
21 | 21 |
22 const PLLRoot *root() { return root_; } | 22 const PLLRoot *root() const { return root_; } |
Mark Seaborn
2016/04/01 23:42:19
Nit: The whole PLLModule object is stateless since
Sean Klein
2016/04/02 00:50:33
Got it. Const removed from this function. To compi
| |
23 | 23 |
24 const char *GetExportedSymbolName(size_t i) { | 24 const char *GetExportedSymbolName(size_t i) { |
25 return root_->string_table + root_->exported_names[i]; | 25 return root_->string_table + root_->exported_names[i]; |
26 } | 26 } |
27 | 27 |
28 const char *GetImportedSymbolName(size_t i) { | 28 const char *GetImportedSymbolName(size_t i) { |
29 return root_->string_table + root_->imported_names[i]; | 29 return root_->string_table + root_->imported_names[i]; |
30 } | 30 } |
31 | 31 |
32 // If this function returns "false", the symbol is definitely not exported. | 32 // If this function returns "false", the symbol is definitely not exported. |
33 // Otherwise, the symbol may or may not be exported. This is public so the | 33 // Otherwise, the symbol may or may not be exported. This is public so the |
34 // bloom filter can be tested. | 34 // bloom filter can be tested. |
35 bool IsMaybeExported(uint32_t hash); | 35 bool IsMaybeExported(uint32_t hash); |
36 | 36 |
37 void *GetExportedSym(const char *name); | 37 void *GetExportedSym(const char *name); |
38 void *InstantiateTLSBlock(); | 38 void *InstantiateTLSBlock(); |
39 | 39 |
40 private: | 40 private: |
41 const PLLRoot *root_; | 41 const PLLRoot *root_; |
42 }; | 42 }; |
43 | 43 |
44 // ModuleSet represents a set of loaded PLLs. | 44 // ModuleSet represents a set of loaded PLLs. |
45 class ModuleSet { | 45 class ModuleSet { |
46 public: | 46 public: |
47 // Load a PLL by filename. Does not add the filename to a known set of loaded | 47 // Load a PLL by filename. Does not add the filename to a known set of loaded |
48 // modules, and will not de-duplicate loading modules. | 48 // modules, and will not de-duplicate loading modules. |
49 void AddByFilename(const char *filename); | 49 // Returns a pointer to the PLL's pso_root. |
Mark Seaborn
2016/04/01 23:42:19
Nit: Should return a PLLRoot* rather than void* th
Sean Klein
2016/04/02 00:50:33
Done.
| |
50 void *AddByFilename(const char *filename); | |
50 | 51 |
51 // Change the search path used by the linker when looking for PLLs by soname. | 52 // Change the search path used by the linker when looking for PLLs by soname. |
52 void SetSonameSearchPath(const std::vector<std::string> &dir_list); | 53 void SetSonameSearchPath(const std::vector<std::string> &dir_list); |
53 | 54 |
54 // Load a PLL by soname and add the soname to the set of loaded modules. | 55 // Load a PLL by soname and add the soname to the set of loaded modules. |
55 void AddBySoname(const char *soname); | 56 // Returns a pointer to the PLL's pso_root if it is loaded, NULL otherwise. |
57 void *AddBySoname(const char *soname); | |
56 | 58 |
57 // Looks up a symbol in the set of modules. This does a linear search of | 59 // Looks up a symbol in the set of modules. This does a linear search of |
58 // the modules, in the order that they were added using AddByFilename(). | 60 // the modules, in the order that they were added using AddByFilename(). |
59 void *GetSym(const char *name); | 61 void *GetSym(const char *name); |
60 | 62 |
61 // Applies relocations to the modules, resolving references between them. | 63 // Applies relocations to the modules, resolving references between them. |
62 void ResolveRefs(); | 64 void ResolveRefs(); |
63 | 65 |
64 private: | 66 private: |
65 // The search path used to look for "sonames". | 67 // The search path used to look for "sonames". |
66 std::vector<std::string> search_path_; | 68 std::vector<std::string> search_path_; |
67 // An unordered set of "sonames" (to see if a module has been loaded). | 69 // An unordered set of "sonames" (to see if a module has been loaded). |
68 std::unordered_set<std::string> sonames_; | 70 std::unordered_set<std::string> sonames_; |
69 std::vector<PLLModule> modules_; | 71 std::vector<PLLModule> modules_; |
70 }; | 72 }; |
71 | 73 |
72 #endif | 74 #endif |
OLD | NEW |