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

Side by Side Diff: util/mac/mach_o_image_symbol_table_reader.cc

Issue 558313002: Add a MappedMemory interface to TaskMemory and use it in MachOImageSymbolTableReader (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 3 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 | « no previous file | util/mach/task_memory.h » ('j') | util/mach/task_memory.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 98
99 scoped_ptr<process_types::nlist[]> symbols( 99 scoped_ptr<process_types::nlist[]> symbols(
100 new process_types::nlist[symtab_command->nsyms]); 100 new process_types::nlist[symtab_command->nsyms]);
101 if (!process_types::nlist::ReadArrayInto( 101 if (!process_types::nlist::ReadArrayInto(
102 process_reader_, symtab_address, symbol_count, &symbols[0])) { 102 process_reader_, symtab_address, symbol_count, &symbols[0])) {
103 LOG(WARNING) << "could not read symbol table" << module_info_; 103 LOG(WARNING) << "could not read symbol table" << module_info_;
104 return false; 104 return false;
105 } 105 }
106 106
107 scoped_ptr<TaskMemory::MappedMemory> string_table;
107 for (size_t symbol_index = 0; symbol_index < symbol_count; ++symbol_index) { 108 for (size_t symbol_index = 0; symbol_index < symbol_count; ++symbol_index) {
108 const process_types::nlist& symbol = symbols[symbol_index]; 109 const process_types::nlist& symbol = symbols[symbol_index];
109 std::string symbol_info = base::StringPrintf(", symbol index %zu%s", 110 std::string symbol_info = base::StringPrintf(", symbol index %zu%s",
110 skip_count + symbol_index, 111 skip_count + symbol_index,
111 module_info_.c_str()); 112 module_info_.c_str());
112 uint8_t symbol_type = symbol.n_type & N_TYPE; 113 uint8_t symbol_type = symbol.n_type & N_TYPE;
113 if ((symbol.n_type & N_STAB) == 0 && (symbol.n_type & N_PEXT) == 0 && 114 if ((symbol.n_type & N_STAB) == 0 && (symbol.n_type & N_PEXT) == 0 &&
114 (symbol_type == N_ABS || symbol_type == N_SECT) && 115 (symbol_type == N_ABS || symbol_type == N_SECT) &&
115 (symbol.n_type & N_EXT)) { 116 (symbol.n_type & N_EXT)) {
116 if (symbol.n_strx >= strtab_size) { 117 if (symbol.n_strx >= strtab_size) {
117 LOG(WARNING) << base::StringPrintf( 118 LOG(WARNING) << base::StringPrintf(
118 "string at 0x%x out of bounds (0x%llx)", 119 "string at 0x%x out of bounds (0x%llx)",
119 symbol.n_strx, 120 symbol.n_strx,
120 strtab_size) << symbol_info; 121 strtab_size) << symbol_info;
121 return false; 122 return false;
122 } 123 }
123 124
125 if (!string_table) {
126 string_table = process_reader_->Memory()->ReadMapped(
127 strtab_address, strtab_size);
128 if (!string_table) {
129 LOG(WARNING) << "could not read string table" << module_info_;
130 return false;
131 }
132 }
133
124 std::string name; 134 std::string name;
125 if (!process_reader_->Memory()->ReadCStringSizeLimited( 135 if (!string_table->ReadCString(symbol.n_strx, &name)) {
Robert Sesek 2014/09/10 21:37:40 This doesn't take into the size limiting anymore.
Mark Mentovai 2014/09/10 22:16:55 rsesek wrote:
126 strtab_address + symbol.n_strx,
127 strtab_size - symbol.n_strx,
128 &name)) {
129 LOG(WARNING) << "could not read string" << symbol_info; 136 LOG(WARNING) << "could not read string" << symbol_info;
130 return false; 137 return false;
131 } 138 }
132 139
133 if (symbol_type == N_ABS && symbol.n_sect != NO_SECT) { 140 if (symbol_type == N_ABS && symbol.n_sect != NO_SECT) {
134 LOG(WARNING) << base::StringPrintf("N_ABS symbol %s in section %u", 141 LOG(WARNING) << base::StringPrintf("N_ABS symbol %s in section %u",
135 name.c_str(), 142 name.c_str(),
136 symbol.n_sect) << symbol_info; 143 symbol.n_sect) << symbol_info;
137 return false; 144 return false;
138 } 145 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 265 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
259 266
260 const auto& iterator = external_defined_symbols_.find(name); 267 const auto& iterator = external_defined_symbols_.find(name);
261 if (iterator == external_defined_symbols_.end()) { 268 if (iterator == external_defined_symbols_.end()) {
262 return NULL; 269 return NULL;
263 } 270 }
264 return &iterator->second; 271 return &iterator->second;
265 } 272 }
266 273
267 } // namespace crashpad 274 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | util/mach/task_memory.h » ('j') | util/mach/task_memory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698