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

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: Using unordered_set, preserving vector. Created 4 years, 8 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
« no previous file with comments | « src/untrusted/pll_loader/pll_loader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "native_client/src/shared/platform/nacl_log.h" 12 #include "native_client/src/shared/platform/nacl_log.h"
13 #include "native_client/src/untrusted/pnacl_dynloader/dynloader.h" 13 #include "native_client/src/untrusted/pnacl_dynloader/dynloader.h"
14 14
15 namespace { 15 namespace {
16 16
17 // This is a simple implementation that does not support multiple threads. 17 // This is a simple implementation that does not support multiple threads.
18 // It demonstrates how we can optimize if we know that pthread_create() 18 // It demonstrates how we can optimize if we know that pthread_create()
19 // will never be called. 19 // will never be called.
20 void *TLSBlockGetter(PLLTLSBlockGetter *closure) { 20 void *TLSBlockGetter(PLLTLSBlockGetter *closure) {
21 return closure->arg; 21 return closure->arg;
22 } 22 }
23 23
24 // Given a pathname, return the filename it points to (or NULL if the path
25 // ends with '/').
26 const char *GetSoname(const char *path) {
Mark Seaborn 2016/03/25 17:57:28 I'm not sure it makes sense to add this because we
Sean Klein 2016/03/25 18:43:57 Yeah, it felt like a temporary solution anyway (I
27 const char *base = path;
28 while (*path) {
29 if (*path == '/')
30 base = path + 1;
31 path++;
32 }
33 return base;
34 }
35
24 } // namespace 36 } // namespace
25 37
26 uint32_t PLLModule::HashString(const char *sp) { 38 uint32_t PLLModule::HashString(const char *sp) {
27 uint32_t h = 5381; 39 uint32_t h = 5381;
28 for (unsigned char c = *sp; c != '\0'; c = *++sp) 40 for (unsigned char c = *sp; c != '\0'; c = *++sp)
29 h = h * 33 + c; 41 h = h * 33 + c;
30 return h; 42 return h;
31 } 43 }
32 44
33 bool PLLModule::IsMaybeExported(uint32_t hash1) { 45 bool PLLModule::IsMaybeExported(uint32_t hash1) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 NaClLog(LOG_FATAL, "InstantiateTLSBlock: Allocation failed\n"); 90 NaClLog(LOG_FATAL, "InstantiateTLSBlock: Allocation failed\n");
79 } 91 }
80 memcpy(base, root_->tls_template, root_->tls_template_data_size); 92 memcpy(base, root_->tls_template, root_->tls_template_data_size);
81 size_t bss_size = (root_->tls_template_total_size - 93 size_t bss_size = (root_->tls_template_total_size -
82 root_->tls_template_data_size); 94 root_->tls_template_data_size);
83 memset((char *) base + root_->tls_template_data_size, 0, bss_size); 95 memset((char *) base + root_->tls_template_data_size, 0, bss_size);
84 return base; 96 return base;
85 } 97 }
86 98
87 void ModuleSet::AddByFilename(const char *filename) { 99 void ModuleSet::AddByFilename(const char *filename) {
100 std::string soname(GetSoname(filename));
101 if (soname.empty()) {
102 NaClLog(LOG_FATAL, "Invalid PLL Path: %s\n", filename);
103 }
104 if (sonames_.count(soname) != 0) {
105 NaClLog(LOG_FATAL, "PLL Loader found duplicate PLL: %s\n", filename);
106 }
107 sonames_.insert(soname);
108
88 void *pso_root; 109 void *pso_root;
89 int err = pnacl_load_elf_file(filename, &pso_root); 110 int err = pnacl_load_elf_file(filename, &pso_root);
90 if (err != 0) { 111 if (err != 0) {
91 NaClLog(LOG_FATAL, "pnacl_load_elf_file() failed: errno=%d\n", err); 112 NaClLog(LOG_FATAL, "pnacl_load_elf_file() failed: errno=%d\n", err);
92 } 113 }
93 modules_.push_back(PLLModule((const PLLRoot *) pso_root)); 114 modules_.push_back(PLLModule((const PLLRoot *) pso_root));
94 } 115 }
95 116
96 void *ModuleSet::GetSym(const char *name) { 117 void *ModuleSet::GetSym(const char *name) {
97 for (auto &module : modules_) { 118 for (auto &module : modules_) {
(...skipping 15 matching lines...) Expand all
113 *(uintptr_t *) module.root()->imported_ptrs[index] += sym_value; 134 *(uintptr_t *) module.root()->imported_ptrs[index] += sym_value;
114 } 135 }
115 136
116 // Initialize TLS. 137 // Initialize TLS.
117 if (PLLTLSBlockGetter *tls_block_getter = module.root()->tls_block_getter) { 138 if (PLLTLSBlockGetter *tls_block_getter = module.root()->tls_block_getter) {
118 tls_block_getter->func = TLSBlockGetter; 139 tls_block_getter->func = TLSBlockGetter;
119 tls_block_getter->arg = module.InstantiateTLSBlock(); 140 tls_block_getter->arg = module.InstantiateTLSBlock();
120 } 141 }
121 } 142 }
122 } 143 }
OLDNEW
« no previous file with comments | « src/untrusted/pll_loader/pll_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698