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

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

Issue 666483002: Create snapshot/mac and move some files from snapshot and util to there (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad/+/master
Patch Set: Move process_reader, process_types, and mach_o_image*_reader from util/mac to snapshot/mac Created 6 years, 2 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/mac/mach_o_image_segment_reader.h" 15 #include "snapshot/mac/mach_o_image_segment_reader.h"
16 16
17 #include <mach-o/loader.h> 17 #include <mach-o/loader.h>
18 18
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "snapshot/mac/process_reader.h"
21 #include "util/mac/checked_mach_address_range.h" 22 #include "util/mac/checked_mach_address_range.h"
22 #include "util/mac/process_reader.h"
23 #include "util/stdlib/strnlen.h" 23 #include "util/stdlib/strnlen.h"
24 24
25 namespace crashpad { 25 namespace crashpad {
26 26
27 namespace { 27 namespace {
28 28
29 std::string SizeLimitedCString(const char* c_string, size_t max_length) { 29 std::string SizeLimitedCString(const char* c_string, size_t max_length) {
30 return std::string(c_string, strnlen(c_string, max_length)); 30 return std::string(c_string, strnlen(c_string, max_length));
31 } 31 }
32 32
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 kRequiredSize) << load_command_info; 72 kRequiredSize) << load_command_info;
73 return false; 73 return false;
74 } 74 }
75 75
76 std::string segment_name = NameInternal(); 76 std::string segment_name = NameInternal();
77 std::string segment_info = base::StringPrintf( 77 std::string segment_info = base::StringPrintf(
78 ", segment %s%s", segment_name.c_str(), load_command_info.c_str()); 78 ", segment %s%s", segment_name.c_str(), load_command_info.c_str());
79 79
80 // This checks the unslid segment range. The slid range (as loaded into 80 // This checks the unslid segment range. The slid range (as loaded into
81 // memory) will be checked later by MachOImageReader. 81 // memory) will be checked later by MachOImageReader.
82 CheckedMachAddressRange segment_range( 82 CheckedMachAddressRange segment_range(process_reader->Is64Bit(),
83 process_reader, segment_command_.vmaddr, segment_command_.vmsize); 83 segment_command_.vmaddr,
84 segment_command_.vmsize);
84 if (!segment_range.IsValid()) { 85 if (!segment_range.IsValid()) {
85 LOG(WARNING) << base::StringPrintf("invalid segment range 0x%llx + 0x%llx", 86 LOG(WARNING) << base::StringPrintf("invalid segment range 0x%llx + 0x%llx",
86 segment_command_.vmaddr, 87 segment_command_.vmaddr,
87 segment_command_.vmsize) << segment_info; 88 segment_command_.vmsize) << segment_info;
88 return false; 89 return false;
89 } 90 }
90 91
91 sections_.resize(segment_command_.nsects); 92 sections_.resize(segment_command_.nsects);
92 if (!process_types::section::ReadArrayInto( 93 if (!process_types::section::ReadArrayInto(
93 process_reader, 94 process_reader,
(...skipping 19 matching lines...) Expand all
113 sections_.size(), 114 sections_.size(),
114 load_command_info.c_str()); 115 load_command_info.c_str());
115 116
116 if (section_segment_name != segment_name) { 117 if (section_segment_name != segment_name) {
117 LOG(WARNING) << "section.segname incorrect in segment " << segment_name 118 LOG(WARNING) << "section.segname incorrect in segment " << segment_name
118 << section_info; 119 << section_info;
119 return false; 120 return false;
120 } 121 }
121 122
122 CheckedMachAddressRange section_range( 123 CheckedMachAddressRange section_range(
123 process_reader, section.addr, section.size); 124 process_reader->Is64Bit(), section.addr, section.size);
124 if (!section_range.IsValid()) { 125 if (!section_range.IsValid()) {
125 LOG(WARNING) << base::StringPrintf( 126 LOG(WARNING) << base::StringPrintf(
126 "invalid section range 0x%llx + 0x%llx", 127 "invalid section range 0x%llx + 0x%llx",
127 section.addr, 128 section.addr,
128 section.size) << section_info; 129 section.size) << section_info;
129 return false; 130 return false;
130 } 131 }
131 132
132 if (!segment_range.ContainsRange(section_range)) { 133 if (!segment_range.ContainsRange(section_range)) {
133 LOG(WARNING) << base::StringPrintf( 134 LOG(WARNING) << base::StringPrintf(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 267 }
267 268
268 void MachOImageSegmentReader::SetSlide(mach_vm_size_t slide) { 269 void MachOImageSegmentReader::SetSlide(mach_vm_size_t slide) {
269 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 270 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
270 INITIALIZATION_STATE_SET_INITIALIZING(initialized_slide_); 271 INITIALIZATION_STATE_SET_INITIALIZING(initialized_slide_);
271 slide_ = slide; 272 slide_ = slide;
272 INITIALIZATION_STATE_SET_VALID(initialized_slide_); 273 INITIALIZATION_STATE_SET_VALID(initialized_slide_);
273 } 274 }
274 275
275 } // namespace crashpad 276 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/mac/mach_o_image_segment_reader.h ('k') | snapshot/mac/mach_o_image_segment_reader_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698