Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Unified Diff: src/untrusted/pll_loader/pll_loader.cc

Issue 1832623002: PNaCl Dynamic Linking: Using unordered_set to disallow duplicate modules. (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Added AddBySoname/SetSonameSearchPaths, tested in pll_loader_test Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4c47665817c49043baffb9202af4f0e2c711dead 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::SetSonameSearchPaths(const std::vector<std::string> &dir_list) {
+ search_paths_ = 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.
+ struct stat buf;
Mark Seaborn 2016/03/26 00:30:10 Nit: putting this immediately before the stat() ca
Sean Klein 2016/03/26 00:47:25 Done.
+ for (auto path : search_paths_) {
+ // Appending "/" might be unnecessary, but "foo/bar" and "foo//bar" should
+ // point to the same file.
+ path.append("/");
+ path.append(soname);
+ 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);

Powered by Google App Engine
This is Rietveld 408576698