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

Side by Side 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 unified diff | Download patch
OLDNEW
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 #include "native_client/src/untrusted/pll_loader/pll_loader.h" 5 #include "native_client/src/untrusted/pll_loader/pll_loader.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/stat.h>
9 10
10 #include <algorithm> 11 #include <algorithm>
11 12
12 #include "native_client/src/shared/platform/nacl_log.h" 13 #include "native_client/src/shared/platform/nacl_log.h"
13 #include "native_client/src/untrusted/pnacl_dynloader/dynloader.h" 14 #include "native_client/src/untrusted/pnacl_dynloader/dynloader.h"
14 15
15 namespace { 16 namespace {
16 17
17 // This is a simple implementation that does not support multiple threads. 18 // This is a simple implementation that does not support multiple threads.
18 // It demonstrates how we can optimize if we know that pthread_create() 19 // It demonstrates how we can optimize if we know that pthread_create()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (posix_memalign(&base, alignment, root_->tls_template_total_size) != 0) { 78 if (posix_memalign(&base, alignment, root_->tls_template_total_size) != 0) {
78 NaClLog(LOG_FATAL, "InstantiateTLSBlock: Allocation failed\n"); 79 NaClLog(LOG_FATAL, "InstantiateTLSBlock: Allocation failed\n");
79 } 80 }
80 memcpy(base, root_->tls_template, root_->tls_template_data_size); 81 memcpy(base, root_->tls_template, root_->tls_template_data_size);
81 size_t bss_size = (root_->tls_template_total_size - 82 size_t bss_size = (root_->tls_template_total_size -
82 root_->tls_template_data_size); 83 root_->tls_template_data_size);
83 memset((char *) base + root_->tls_template_data_size, 0, bss_size); 84 memset((char *) base + root_->tls_template_data_size, 0, bss_size);
84 return base; 85 return base;
85 } 86 }
86 87
88 void ModuleSet::SetSonameSearchPaths(const std::vector<std::string> &dir_list) {
89 search_paths_ = dir_list;
90 }
91
92 void ModuleSet::AddBySoname(const char *soname) {
93 // TODO(smklein): Deduplicate rather than failing once dependencies are added.
94 if (sonames_.count(soname) != 0) {
95 NaClLog(LOG_FATAL, "PLL Loader found duplicate soname: %s\n", soname);
96 }
97 sonames_.insert(soname);
98
99 // Actually load the module implied by the soname.
100 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.
101 for (auto path : search_paths_) {
102 // Appending "/" might be unnecessary, but "foo/bar" and "foo//bar" should
103 // point to the same file.
104 path.append("/");
105 path.append(soname);
106 if (stat(path.c_str(), &buf) == 0) {
107 AddByFilename(path.c_str());
108 return;
109 }
110 }
111
112 NaClLog(LOG_FATAL, "PLL Loader cannot find shared object file: %s\n", soname);
113 }
114
87 void ModuleSet::AddByFilename(const char *filename) { 115 void ModuleSet::AddByFilename(const char *filename) {
88 void *pso_root; 116 void *pso_root;
89 int err = pnacl_load_elf_file(filename, &pso_root); 117 int err = pnacl_load_elf_file(filename, &pso_root);
90 if (err != 0) { 118 if (err != 0) {
91 NaClLog(LOG_FATAL, "pnacl_load_elf_file() failed: errno=%d\n", err); 119 NaClLog(LOG_FATAL, "pnacl_load_elf_file() failed: errno=%d\n", err);
92 } 120 }
93 modules_.push_back(PLLModule((const PLLRoot *) pso_root)); 121 modules_.push_back(PLLModule((const PLLRoot *) pso_root));
94 } 122 }
95 123
96 void *ModuleSet::GetSym(const char *name) { 124 void *ModuleSet::GetSym(const char *name) {
(...skipping 16 matching lines...) Expand all
113 *(uintptr_t *) module.root()->imported_ptrs[index] += sym_value; 141 *(uintptr_t *) module.root()->imported_ptrs[index] += sym_value;
114 } 142 }
115 143
116 // Initialize TLS. 144 // Initialize TLS.
117 if (PLLTLSBlockGetter *tls_block_getter = module.root()->tls_block_getter) { 145 if (PLLTLSBlockGetter *tls_block_getter = module.root()->tls_block_getter) {
118 tls_block_getter->func = TLSBlockGetter; 146 tls_block_getter->func = TLSBlockGetter;
119 tls_block_getter->arg = module.InstantiateTLSBlock(); 147 tls_block_getter->arg = module.InstantiateTLSBlock();
120 } 148 }
121 } 149 }
122 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698