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

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

Issue 535343004: Add MachOImageReader and its test (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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return &sections_[iterator->second]; 187 return &sections_[iterator->second];
188 } 188 }
189 189
190 const process_types::section* MachOImageSegmentReader::GetSectionAtIndex( 190 const process_types::section* MachOImageSegmentReader::GetSectionAtIndex(
191 size_t index) const { 191 size_t index) const {
192 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 192 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
193 CHECK_LT(index, sections_.size()); 193 CHECK_LT(index, sections_.size());
194 return &sections_[index]; 194 return &sections_[index];
195 } 195 }
196 196
197 bool MachOImageSegmentReader::SegmentSlides() const {
198 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
199
200 // These are the same rules that the kernel uses to identify __PAGEZERO. See
201 // 10.9.4 xnu-2422.110.17/bsd/kern/mach_loader.c load_segment().
202 return !(segment_command_.vmaddr == 0 && segment_command_.filesize == 0 &&
203 segment_command_.vmsize != 0 &&
204 (segment_command_.initprot & VM_PROT_ALL) == VM_PROT_NONE &&
205 (segment_command_.maxprot & VM_PROT_ALL) == VM_PROT_NONE);
206 }
207
197 // static 208 // static
198 std::string MachOImageSegmentReader::SegmentNameString( 209 std::string MachOImageSegmentReader::SegmentNameString(
199 const char* segment_name_c) { 210 const char* segment_name_c) {
200 // This is used to interpret the segname field of both the segment_command and 211 // This is used to interpret the segname field of both the segment_command and
201 // section structures, so be sure that they’re identical. 212 // section structures, so be sure that they’re identical.
202 COMPILE_ASSERT(sizeof(process_types::segment_command::segname) == 213 COMPILE_ASSERT(sizeof(process_types::segment_command::segname) ==
203 sizeof(process_types::section::segname), 214 sizeof(process_types::section::segname),
204 sizes_must_be_equal); 215 sizes_must_be_equal);
205 216
206 return SizeLimitedCString(segment_name_c, 217 return SizeLimitedCString(segment_name_c,
(...skipping 14 matching lines...) Expand all
221 return base::StringPrintf("%s,%s", 232 return base::StringPrintf("%s,%s",
222 SegmentNameString(segment_name_c).c_str(), 233 SegmentNameString(segment_name_c).c_str(),
223 SectionNameString(section_name_c).c_str()); 234 SectionNameString(section_name_c).c_str());
224 } 235 }
225 236
226 std::string MachOImageSegmentReader::NameInternal() const { 237 std::string MachOImageSegmentReader::NameInternal() const {
227 return SegmentNameString(segment_command_.segname); 238 return SegmentNameString(segment_command_.segname);
228 } 239 }
229 240
230 } // namespace crashpad 241 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698