1 // Copyright 2015 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 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_MEMORY_INFO_WRITER_H_
16 #define CRASHPAD_MINIDUMP_MINIDUMP_MEMORY_INFO_WRITER_H_
17 
18 #include <windows.h>
19 #include <dbghelp.h>
20 #include <stdint.h>
21 #include <sys/types.h>
22 
23 #include <vector>
24 
25 #include "base/macros.h"
26 #include "minidump/minidump_stream_writer.h"
27 #include "minidump/minidump_writable.h"
28 
29 namespace crashpad {
30 
31 class MemoryMapRegionSnapshot;
32 class MinidumpContextWriter;
33 class MinidumpMemoryListWriter;
34 class MinidumpMemoryWriter;
35 
36 //! \brief The writer for a MINIDUMP_MEMORY_INFO_LIST stream in a minidump file,
37 //!     containing a list of MINIDUMP_MEMORY_INFO objects.
38 class MinidumpMemoryInfoListWriter final
39     : public internal::MinidumpStreamWriter {
40  public:
41   MinidumpMemoryInfoListWriter();
42   ~MinidumpMemoryInfoListWriter() override;
43 
44   //! \brief Initializes a MINIDUMP_MEMORY_INFO_LIST based on \a memory_map.
45   //!
46   //! \param[in] memory_map The vector of memory map region snapshots to use as
47   //!     source data.
48   //!
49   //! \note Valid in #kStateMutable.
50   void InitializeFromSnapshot(
51       const std::vector<const MemoryMapRegionSnapshot*>& memory_map);
52 
53  protected:
54   // MinidumpWritable:
55   bool Freeze() override;
56   size_t SizeOfObject() override;
57   std::vector<internal::MinidumpWritable*> Children() override;
58   bool WriteObject(FileWriterInterface* file_writer) override;
59 
60   // MinidumpStreamWriter:
61   MinidumpStreamType StreamType() const override;
62 
63  private:
64   MINIDUMP_MEMORY_INFO_LIST memory_info_list_base_;
65   std::vector<MINIDUMP_MEMORY_INFO> items_;
66 
67   DISALLOW_COPY_AND_ASSIGN(MinidumpMemoryInfoListWriter);
68 };
69 
70 }  // namespace crashpad
71 
72 #endif  // CRASHPAD_MINIDUMP_MINIDUMP_MEMORY_INFO_WRITER_H_
73