OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 bool MinidumpWritable::WriteEverything(FileWriterInterface* file_writer) { | 37 bool MinidumpWritable::WriteEverything(FileWriterInterface* file_writer) { |
38 DCHECK_EQ(state_, kStateMutable); | 38 DCHECK_EQ(state_, kStateMutable); |
39 | 39 |
40 if (!Freeze()) { | 40 if (!Freeze()) { |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 DCHECK_EQ(state_, kStateFrozen); | 44 DCHECK_EQ(state_, kStateFrozen); |
45 | 45 |
46 off_t offset = 0; | 46 FileOffset offset = 0; |
47 std::vector<MinidumpWritable*> write_sequence; | 47 std::vector<MinidumpWritable*> write_sequence; |
48 size_t size = WillWriteAtOffset(kPhaseEarly, &offset, &write_sequence); | 48 size_t size = WillWriteAtOffset(kPhaseEarly, &offset, &write_sequence); |
49 if (size == kInvalidSize) { | 49 if (size == kInvalidSize) { |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 offset += size; | 53 offset += size; |
54 if (WillWriteAtOffset(kPhaseLate, &offset, &write_sequence) == kInvalidSize) { | 54 if (WillWriteAtOffset(kPhaseLate, &offset, &write_sequence) == kInvalidSize) { |
55 return false; | 55 return false; |
56 } | 56 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 return std::vector<MinidumpWritable*>(); | 118 return std::vector<MinidumpWritable*>(); |
119 } | 119 } |
120 | 120 |
121 MinidumpWritable::Phase MinidumpWritable::WritePhase() { | 121 MinidumpWritable::Phase MinidumpWritable::WritePhase() { |
122 return kPhaseEarly; | 122 return kPhaseEarly; |
123 } | 123 } |
124 | 124 |
125 size_t MinidumpWritable::WillWriteAtOffset( | 125 size_t MinidumpWritable::WillWriteAtOffset( |
126 Phase phase, | 126 Phase phase, |
127 off_t* offset, | 127 FileOffset* offset, |
128 std::vector<MinidumpWritable*>* write_sequence) { | 128 std::vector<MinidumpWritable*>* write_sequence) { |
129 off_t local_offset = *offset; | 129 FileOffset local_offset = *offset; |
130 CHECK_GE(local_offset, 0); | 130 CHECK_GE(local_offset, 0); |
131 | 131 |
132 size_t leading_pad_bytes_this_phase; | 132 size_t leading_pad_bytes_this_phase; |
133 size_t size; | 133 size_t size; |
134 if (phase == WritePhase()) { | 134 if (phase == WritePhase()) { |
135 DCHECK_EQ(state_, kStateFrozen); | 135 DCHECK_EQ(state_, kStateFrozen); |
136 | 136 |
137 // Add this object to the sequence of MinidumpWritable objects to be | 137 // Add this object to the sequence of MinidumpWritable objects to be |
138 // written. | 138 // written. |
139 write_sequence->push_back(this); | 139 write_sequence->push_back(this); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 size = 0; | 211 size = 0; |
212 leading_pad_bytes_this_phase = 0; | 212 leading_pad_bytes_this_phase = 0; |
213 } | 213 } |
214 | 214 |
215 // Loop over children regardless of whether this object itself will write | 215 // Loop over children regardless of whether this object itself will write |
216 // during this phase. An object’s children are not required to be written | 216 // during this phase. An object’s children are not required to be written |
217 // during the same phase as their parent. | 217 // during the same phase as their parent. |
218 std::vector<MinidumpWritable*> children = Children(); | 218 std::vector<MinidumpWritable*> children = Children(); |
219 for (MinidumpWritable* child : children) { | 219 for (MinidumpWritable* child : children) { |
220 // Use “auto” here because it’s impossible to know whether size_t (size) or | 220 // Use “auto” here because it’s impossible to know whether size_t (size) or |
221 // off_t (local_offset) is the wider type, and thus what type the result of | 221 // FileOffset (local_offset) is the wider type, and thus what type the |
222 // adding these two variables will have. | 222 // result of adding these two variables will have. |
223 auto unaligned_child_offset = local_offset + size; | 223 auto unaligned_child_offset = local_offset + size; |
224 off_t child_offset; | 224 FileOffset child_offset; |
225 if (!AssignIfInRange(&child_offset, unaligned_child_offset)) { | 225 if (!AssignIfInRange(&child_offset, unaligned_child_offset)) { |
226 LOG(ERROR) << "offset " << unaligned_child_offset << " out of range"; | 226 LOG(ERROR) << "offset " << unaligned_child_offset << " out of range"; |
227 return kInvalidSize; | 227 return kInvalidSize; |
228 } | 228 } |
229 | 229 |
230 size_t child_size = | 230 size_t child_size = |
231 child->WillWriteAtOffset(phase, &child_offset, write_sequence); | 231 child->WillWriteAtOffset(phase, &child_offset, write_sequence); |
232 if (child_size == kInvalidSize) { | 232 if (child_size == kInvalidSize) { |
233 return kInvalidSize; | 233 return kInvalidSize; |
234 } | 234 } |
235 | 235 |
236 size += child_size; | 236 size += child_size; |
237 } | 237 } |
238 | 238 |
239 return leading_pad_bytes_this_phase + size; | 239 return leading_pad_bytes_this_phase + size; |
240 } | 240 } |
241 | 241 |
242 bool MinidumpWritable::WillWriteAtOffsetImpl(off_t offset) { | 242 bool MinidumpWritable::WillWriteAtOffsetImpl(FileOffset offset) { |
243 return true; | 243 return true; |
244 } | 244 } |
245 | 245 |
246 bool MinidumpWritable::WritePaddingAndObject(FileWriterInterface* file_writer) { | 246 bool MinidumpWritable::WritePaddingAndObject(FileWriterInterface* file_writer) { |
247 DCHECK_EQ(state_, kStateWritable); | 247 DCHECK_EQ(state_, kStateWritable); |
248 | 248 |
249 // The number of elements in kZeroes must be at least one less than the | 249 // The number of elements in kZeroes must be at least one less than the |
250 // maximum Alignment() ever encountered. | 250 // maximum Alignment() ever encountered. |
251 const uint8_t kZeroes[kMaximumAlignment - 1] = {}; | 251 const uint8_t kZeroes[kMaximumAlignment - 1] = {}; |
252 DCHECK_LE(leading_pad_bytes_, arraysize(kZeroes)); | 252 DCHECK_LE(leading_pad_bytes_, arraysize(kZeroes)); |
253 | 253 |
254 if (leading_pad_bytes_) { | 254 if (leading_pad_bytes_) { |
255 if (!file_writer->Write(&kZeroes, leading_pad_bytes_)) { | 255 if (!file_writer->Write(&kZeroes, leading_pad_bytes_)) { |
256 return false; | 256 return false; |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 if (!WriteObject(file_writer)) { | 260 if (!WriteObject(file_writer)) { |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 state_ = kStateWritten; | 264 state_ = kStateWritten; |
265 return true; | 265 return true; |
266 } | 266 } |
267 | 267 |
268 } // namespace internal | 268 } // namespace internal |
269 } // namespace crashpad | 269 } // namespace crashpad |
OLD | NEW |