| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (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 | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "minidump/minidump_location_descriptor_list_writer.h" | |
| 16 | |
| 17 #include "base/logging.h" | |
| 18 #include "util/file/file_writer.h" | |
| 19 #include "util/numeric/safe_assignment.h" | |
| 20 | |
| 21 namespace crashpad { | |
| 22 namespace internal { | |
| 23 | |
| 24 MinidumpLocationDescriptorListWriter::MinidumpLocationDescriptorListWriter() | |
| 25 : MinidumpWritable(), | |
| 26 location_descriptor_list_base_(new MinidumpLocationDescriptorList()), | |
| 27 children_(), | |
| 28 child_location_descriptors_() { | |
| 29 } | |
| 30 | |
| 31 MinidumpLocationDescriptorListWriter::~MinidumpLocationDescriptorListWriter() { | |
| 32 } | |
| 33 | |
| 34 void MinidumpLocationDescriptorListWriter::AddChild( | |
| 35 scoped_ptr<MinidumpWritable> child) { | |
| 36 DCHECK_EQ(state(), kStateMutable); | |
| 37 | |
| 38 children_.push_back(child.release()); | |
| 39 } | |
| 40 | |
| 41 bool MinidumpLocationDescriptorListWriter::Freeze() { | |
| 42 DCHECK_EQ(state(), kStateMutable); | |
| 43 DCHECK(child_location_descriptors_.empty()); | |
| 44 | |
| 45 if (!MinidumpWritable::Freeze()) { | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 size_t child_count = children_.size(); | |
| 50 if (!AssignIfInRange(&location_descriptor_list_base_->count, | |
| 51 child_count)) { | |
| 52 LOG(ERROR) << "child_count " << child_count << " out of range"; | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 child_location_descriptors_.resize(child_count); | |
| 57 for (size_t index = 0; index < child_count; ++index) { | |
| 58 children_[index]->RegisterLocationDescriptor( | |
| 59 &child_location_descriptors_[index]); | |
| 60 } | |
| 61 | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 size_t MinidumpLocationDescriptorListWriter::SizeOfObject() { | |
| 66 DCHECK_GE(state(), kStateFrozen); | |
| 67 | |
| 68 return sizeof(*location_descriptor_list_base_) + | |
| 69 children_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR); | |
| 70 } | |
| 71 | |
| 72 std::vector<MinidumpWritable*> | |
| 73 MinidumpLocationDescriptorListWriter::Children() { | |
| 74 DCHECK_GE(state(), kStateFrozen); | |
| 75 | |
| 76 std::vector<MinidumpWritable*> children; | |
| 77 for (MinidumpWritable* child : children_) { | |
| 78 children.push_back(child); | |
| 79 } | |
| 80 | |
| 81 return children; | |
| 82 } | |
| 83 | |
| 84 bool MinidumpLocationDescriptorListWriter::WriteObject( | |
| 85 FileWriterInterface* file_writer) { | |
| 86 DCHECK_EQ(state(), kStateWritable); | |
| 87 DCHECK_EQ(children_.size(), child_location_descriptors_.size()); | |
| 88 | |
| 89 WritableIoVec iov; | |
| 90 iov.iov_base = location_descriptor_list_base_.get(); | |
| 91 iov.iov_len = sizeof(*location_descriptor_list_base_); | |
| 92 std::vector<WritableIoVec> iovecs(1, iov); | |
| 93 | |
| 94 if (!child_location_descriptors_.empty()) { | |
| 95 iov.iov_base = &child_location_descriptors_[0]; | |
| 96 iov.iov_len = child_location_descriptors_.size() * | |
| 97 sizeof(MINIDUMP_LOCATION_DESCRIPTOR); | |
| 98 iovecs.push_back(iov); | |
| 99 } | |
| 100 | |
| 101 return file_writer->WriteIoVec(&iovecs); | |
| 102 } | |
| 103 | |
| 104 } // namespace internal | |
| 105 } // namespace crashpad | |
| OLD | NEW |