Index: src/untrusted/pll_loader/pll_loader.cc |
diff --git a/src/untrusted/pll_loader/pll_loader.cc b/src/untrusted/pll_loader/pll_loader.cc |
index aa7724e0c02ae42149d6f13dbdb39152ac9a2116..46e496aa30eb780882bf1123f2ab79739a7c1311 100644 |
--- a/src/untrusted/pll_loader/pll_loader.cc |
+++ b/src/untrusted/pll_loader/pll_loader.cc |
@@ -6,6 +6,7 @@ |
#include <stdlib.h> |
#include <string.h> |
+#include <sys/stat.h> |
#include <algorithm> |
@@ -84,6 +85,33 @@ void *PLLModule::InstantiateTLSBlock() { |
return base; |
} |
+void ModuleSet::SetSonameSearchPath(const std::vector<std::string> &dir_list) { |
+ search_path_ = dir_list; |
+} |
+ |
+void ModuleSet::AddBySoname(const char *soname) { |
+ // TODO(smklein): Deduplicate rather than failing once dependencies are added. |
+ if (sonames_.count(soname) != 0) { |
+ NaClLog(LOG_FATAL, "PLL Loader found duplicate soname: %s\n", soname); |
+ } |
+ sonames_.insert(soname); |
+ |
+ // Actually load the module implied by the soname. |
+ for (auto path : search_path_) { |
+ // Appending "/" might be unnecessary, but "foo/bar" and "foo//bar" should |
+ // point to the same file. |
+ path.append("/"); |
+ path.append(soname); |
+ struct stat buf; |
+ if (stat(path.c_str(), &buf) == 0) { |
+ AddByFilename(path.c_str()); |
+ return; |
+ } |
+ } |
+ |
+ NaClLog(LOG_FATAL, "PLL Loader cannot find shared object file: %s\n", soname); |
+} |
+ |
void ModuleSet::AddByFilename(const char *filename) { |
void *pso_root; |
int err = pnacl_load_elf_file(filename, &pso_root); |