1 // Copyright 2007 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_size.h: Provides a C++ template for programmatic access to 30 // the sizes of various types defined in minidump_format.h. 31 // 32 // Author: Mark Mentovai 33 34 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_SIZE_H__ 35 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_SIZE_H__ 36 37 #include <sys/types.h> 38 39 #include "google_breakpad/common/minidump_format.h" 40 41 namespace google_breakpad { 42 43 template<typename T> 44 class minidump_size { 45 public: size()46 static size_t size() { return sizeof(T); } 47 }; 48 49 // Explicit specializations for variable-length types. The size returned 50 // for these should be the size for an object without its variable-length 51 // section. 52 53 template<> 54 class minidump_size<MDString> { 55 public: size()56 static size_t size() { return MDString_minsize; } 57 }; 58 59 template<> 60 class minidump_size<MDRawThreadList> { 61 public: size()62 static size_t size() { return MDRawThreadList_minsize; } 63 }; 64 65 template<> 66 class minidump_size<MDCVInfoPDB20> { 67 public: size()68 static size_t size() { return MDCVInfoPDB20_minsize; } 69 }; 70 71 template<> 72 class minidump_size<MDCVInfoPDB70> { 73 public: size()74 static size_t size() { return MDCVInfoPDB70_minsize; } 75 }; 76 77 template<> 78 class minidump_size<MDCVInfoELF> { 79 public: size()80 static size_t size() { return MDCVInfoELF_minsize; } 81 }; 82 83 template<> 84 class minidump_size<MDImageDebugMisc> { 85 public: size()86 static size_t size() { return MDImageDebugMisc_minsize; } 87 }; 88 89 template<> 90 class minidump_size<MDRawModuleList> { 91 public: size()92 static size_t size() { return MDRawModuleList_minsize; } 93 }; 94 95 template<> 96 class minidump_size<MDRawMemoryList> { 97 public: size()98 static size_t size() { return MDRawMemoryList_minsize; } 99 }; 100 101 // Explicit specialization for MDRawModule, for which sizeof may include 102 // tail-padding on some architectures but not others. 103 104 template<> 105 class minidump_size<MDRawModule> { 106 public: size()107 static size_t size() { return MD_MODULE_SIZE; } 108 }; 109 110 } // namespace google_breakpad 111 112 #endif // GOOGLE_BREAKPAD_COMMON_MINIDUMP_SIZE_H__ 113