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, |
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 "minidump/minidump_rva_list_writer.h" | 15 #include "minidump/minidump_rva_list_writer.h" |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "util/file/file_writer.h" | 18 #include "util/file/file_writer.h" |
19 #include "util/numeric/safe_assignment.h" | 19 #include "util/numeric/safe_assignment.h" |
20 | 20 |
21 namespace crashpad { | 21 namespace crashpad { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 MinidumpRVAListWriter::MinidumpRVAListWriter() | 24 MinidumpRVAListWriter::MinidumpRVAListWriter() |
25 : MinidumpWritable(), | 25 : MinidumpWritable(), |
26 rva_list_base_(), | 26 rva_list_base_(new MinidumpRVAList()), |
27 children_(), | 27 children_(), |
28 child_rvas_() { | 28 child_rvas_() { |
29 } | 29 } |
30 | 30 |
31 MinidumpRVAListWriter::~MinidumpRVAListWriter() { | 31 MinidumpRVAListWriter::~MinidumpRVAListWriter() { |
32 } | 32 } |
33 | 33 |
34 void MinidumpRVAListWriter::AddChild(scoped_ptr<MinidumpWritable> child) { | 34 void MinidumpRVAListWriter::AddChild(scoped_ptr<MinidumpWritable> child) { |
35 DCHECK_EQ(state(), kStateMutable); | 35 DCHECK_EQ(state(), kStateMutable); |
36 | 36 |
37 children_.push_back(child.release()); | 37 children_.push_back(child.release()); |
38 } | 38 } |
39 | 39 |
40 bool MinidumpRVAListWriter::Freeze() { | 40 bool MinidumpRVAListWriter::Freeze() { |
41 DCHECK_EQ(state(), kStateMutable); | 41 DCHECK_EQ(state(), kStateMutable); |
42 DCHECK(child_rvas_.empty()); | 42 DCHECK(child_rvas_.empty()); |
43 | 43 |
44 if (!MinidumpWritable::Freeze()) { | 44 if (!MinidumpWritable::Freeze()) { |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 size_t child_count = children_.size(); | 48 size_t child_count = children_.size(); |
49 if (!AssignIfInRange(&rva_list_base_.count, child_count)) { | 49 if (!AssignIfInRange(&rva_list_base_->count, child_count)) { |
50 LOG(ERROR) << "child_count " << child_count << " out of range"; | 50 LOG(ERROR) << "child_count " << child_count << " out of range"; |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 child_rvas_.resize(child_count); | 54 child_rvas_.resize(child_count); |
55 for (size_t index = 0; index < child_count; ++index) { | 55 for (size_t index = 0; index < child_count; ++index) { |
56 children_[index]->RegisterRVA(&child_rvas_[index]); | 56 children_[index]->RegisterRVA(&child_rvas_[index]); |
57 } | 57 } |
58 | 58 |
59 return true; | 59 return true; |
60 } | 60 } |
61 | 61 |
62 size_t MinidumpRVAListWriter::SizeOfObject() { | 62 size_t MinidumpRVAListWriter::SizeOfObject() { |
63 DCHECK_GE(state(), kStateFrozen); | 63 DCHECK_GE(state(), kStateFrozen); |
64 | 64 |
65 return sizeof(rva_list_base_) + children_.size() * sizeof(RVA); | 65 return sizeof(*rva_list_base_) + children_.size() * sizeof(RVA); |
66 } | 66 } |
67 | 67 |
68 std::vector<MinidumpWritable*> MinidumpRVAListWriter::Children() { | 68 std::vector<MinidumpWritable*> MinidumpRVAListWriter::Children() { |
69 DCHECK_GE(state(), kStateFrozen); | 69 DCHECK_GE(state(), kStateFrozen); |
70 | 70 |
71 std::vector<MinidumpWritable*> children; | 71 std::vector<MinidumpWritable*> children; |
72 for (MinidumpWritable* child : children_) { | 72 for (MinidumpWritable* child : children_) { |
73 children.push_back(child); | 73 children.push_back(child); |
74 } | 74 } |
75 | 75 |
76 return children; | 76 return children; |
77 } | 77 } |
78 | 78 |
79 bool MinidumpRVAListWriter::WriteObject(FileWriterInterface* file_writer) { | 79 bool MinidumpRVAListWriter::WriteObject(FileWriterInterface* file_writer) { |
80 DCHECK_EQ(state(), kStateWritable); | 80 DCHECK_EQ(state(), kStateWritable); |
81 DCHECK_EQ(children_.size(), child_rvas_.size()); | 81 DCHECK_EQ(children_.size(), child_rvas_.size()); |
82 | 82 |
83 WritableIoVec iov; | 83 WritableIoVec iov; |
84 iov.iov_base = &rva_list_base_; | 84 iov.iov_base = rva_list_base_.get(); |
85 iov.iov_len = sizeof(rva_list_base_); | 85 iov.iov_len = sizeof(*rva_list_base_); |
86 std::vector<WritableIoVec> iovecs(1, iov); | 86 std::vector<WritableIoVec> iovecs(1, iov); |
87 | 87 |
88 if (!child_rvas_.empty()) { | 88 if (!child_rvas_.empty()) { |
89 iov.iov_base = &child_rvas_[0]; | 89 iov.iov_base = &child_rvas_[0]; |
90 iov.iov_len = child_rvas_.size() * sizeof(RVA); | 90 iov.iov_len = child_rvas_.size() * sizeof(RVA); |
91 iovecs.push_back(iov); | 91 iovecs.push_back(iov); |
92 } | 92 } |
93 | 93 |
94 return file_writer->WriteIoVec(&iovecs); | 94 return file_writer->WriteIoVec(&iovecs); |
95 } | 95 } |
96 | 96 |
97 } // namespace internal | 97 } // namespace internal |
98 } // namespace crashpad | 98 } // namespace crashpad |
OLD | NEW |