1 // Copyright 2006 Google LLC
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google LLC nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 // minidump_file_writer-inl.h: Minidump file writer implementation.
30 //
31 // See minidump_file_writer.h for documentation.
32
33 #ifndef CLIENT_MINIDUMP_FILE_WRITER_INL_H__
34 #define CLIENT_MINIDUMP_FILE_WRITER_INL_H__
35
36 #include <assert.h>
37
38 #include "client/minidump_file_writer.h"
39 #include "google_breakpad/common/minidump_size.h"
40
41 namespace google_breakpad {
42
43 template<typename MDType>
Allocate()44 inline bool TypedMDRVA<MDType>::Allocate() {
45 allocation_state_ = SINGLE_OBJECT;
46 return UntypedMDRVA::Allocate(minidump_size<MDType>::size());
47 }
48
49 template<typename MDType>
Allocate(size_t additional)50 inline bool TypedMDRVA<MDType>::Allocate(size_t additional) {
51 allocation_state_ = SINGLE_OBJECT;
52 return UntypedMDRVA::Allocate(minidump_size<MDType>::size() + additional);
53 }
54
55 template<typename MDType>
AllocateArray(size_t count)56 inline bool TypedMDRVA<MDType>::AllocateArray(size_t count) {
57 assert(count);
58 allocation_state_ = ARRAY;
59 return UntypedMDRVA::Allocate(minidump_size<MDType>::size() * count);
60 }
61
62 template<typename MDType>
AllocateObjectAndArray(size_t count,size_t length)63 inline bool TypedMDRVA<MDType>::AllocateObjectAndArray(size_t count,
64 size_t length) {
65 assert(count && length);
66 allocation_state_ = SINGLE_OBJECT_WITH_ARRAY;
67 return UntypedMDRVA::Allocate(minidump_size<MDType>::size() + count * length);
68 }
69
70 template<typename MDType>
CopyIndex(unsigned int index,MDType * item)71 inline bool TypedMDRVA<MDType>::CopyIndex(unsigned int index, MDType* item) {
72 assert(allocation_state_ == ARRAY);
73 return writer_->Copy(
74 static_cast<MDRVA>(position_ + index * minidump_size<MDType>::size()),
75 item, minidump_size<MDType>::size());
76 }
77
78 template<typename MDType>
CopyIndexAfterObject(unsigned int index,const void * src,size_t length)79 inline bool TypedMDRVA<MDType>::CopyIndexAfterObject(unsigned int index,
80 const void* src,
81 size_t length) {
82 assert(allocation_state_ == SINGLE_OBJECT_WITH_ARRAY);
83 return writer_->Copy(
84 static_cast<MDRVA>(position_ + minidump_size<MDType>::size()
85 + index * length),
86 src, length);
87 }
88
89 template<typename MDType>
Flush()90 inline bool TypedMDRVA<MDType>::Flush() {
91 return writer_->Copy(position_, &data_, minidump_size<MDType>::size());
92 }
93
94 } // namespace google_breakpad
95
96 #endif // CLIENT_MINIDUMP_FILE_WRITER_INL_H__
97