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 #ifndef CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ |
| 16 #define CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ |
| 17 |
| 18 #include <dbghelp.h> |
| 19 |
| 20 #include <string> |
| 21 |
| 22 #include "gtest/gtest.h" |
| 23 |
| 24 namespace crashpad { |
| 25 namespace test { |
| 26 |
| 27 //! \brief Returns an untyped minidump object located within a minidump file’s |
| 28 //! contents, where the offset of the object is known. |
| 29 //! |
| 30 //! \param[in] file_contents The contents of the minidump file. |
| 31 //! \param[in] rva The offset within the minidump file of the desired object. |
| 32 //! |
| 33 //! \return If \a rva is within the range of \a file_contents, returns a pointer |
| 34 //! into \a file_contents at offset \a rva. Otherwise, raises a gtest |
| 35 //! assertion failure and returns `nullptr`. |
| 36 //! |
| 37 //! Do not call this function. Use the typed version, MinidumpWritableAtRVA<>(), |
| 38 //! or another type-specific function. |
| 39 //! |
| 40 //! \sa MinidumpWritableAtLocationDescriptorInternal() |
| 41 const void* MinidumpWritableAtRVAInternal(const std::string& file_contents, |
| 42 RVA rva); |
| 43 |
| 44 //! \brief Returns an untyped minidump object located within a minidump file’s |
| 45 //! contents, where the offset and size of the object are known. |
| 46 //! |
| 47 //! \param[in] file_contents The contents of the minidump file. |
| 48 //! \param[in] location A MINIDUMP_LOCATION_DESCRIPTOR giving the offset within |
| 49 //! the minidump file of the desired object, as well as its size. |
| 50 //! \param[in] expected_minimum_size The minimum size allowable for the object. |
| 51 //! |
| 52 //! \return If the size of \a location is at least as big as \a |
| 53 //! expected_minimum_size, and if \a location is within the range of \a |
| 54 //! file_contents, returns a pointer into \a file_contents at offset \a rva. |
| 55 //! Otherwise, raises a gtest assertion failure and returns `nullptr`. |
| 56 //! |
| 57 //! Do not call this function. Use the typed version, |
| 58 //! MinidumpWritableAtLocationDescriptor<>(), or another type-specific function. |
| 59 //! |
| 60 //! \sa MinidumpWritableAtRVAInternal() |
| 61 const void* MinidumpWritableAtLocationDescriptorInternal( |
| 62 const std::string& file_contents, |
| 63 const MINIDUMP_LOCATION_DESCRIPTOR& location, |
| 64 size_t expected_minimum_size); |
| 65 |
| 66 //! \brief Returns a typed minidump object located within a minidump file’s |
| 67 //! contents, where the offset of the object is known. |
| 68 //! |
| 69 //! \param[in] file_contents The contents of the minidump file. |
| 70 //! \param[in] rva The offset within the minidump file of the desired object. |
| 71 //! |
| 72 //! \return If \a rva is within the range of \a file_contents, returns a pointer |
| 73 //! into \a file_contents at offset \a rva. Otherwise, raises a gtest |
| 74 //! assertion failure and returns `nullptr`. |
| 75 //! |
| 76 //! \sa MinidumpWritableAtLocationDescriptor<>() |
| 77 template <typename T> |
| 78 const T* MinidumpWritableAtRVA(const std::string& file_contents, RVA rva) { |
| 79 return reinterpret_cast<const T*>( |
| 80 MinidumpWritableAtRVAInternal(file_contents, rva)); |
| 81 } |
| 82 |
| 83 //! \brief Returns a typed minidump object located within a minidump file’s |
| 84 //! contents, where the offset and size of the object are known. |
| 85 //! |
| 86 //! \param[in] file_contents The contents of the minidump file. |
| 87 //! \param[in] location A MINIDUMP_LOCATION_DESCRIPTOR giving the offset within |
| 88 //! the minidump file of the desired object, as well as its size. |
| 89 //! |
| 90 //! \return If the size of \a location is at least as big as the size of the |
| 91 //! requested object, and if \a location is within the range of \a |
| 92 //! file_contents, returns a pointer into \a file_contents at offset \a rva. |
| 93 //! Otherwise, raises a gtest assertion failure and returns `nullptr`. |
| 94 //! |
| 95 //! \sa MinidumpWritableAtRVA() |
| 96 template <typename T> |
| 97 const T* MinidumpWritableAtLocationDescriptor( |
| 98 const std::string& file_contents, |
| 99 const MINIDUMP_LOCATION_DESCRIPTOR& location) { |
| 100 return reinterpret_cast<const T*>( |
| 101 MinidumpWritableAtLocationDescriptorInternal( |
| 102 file_contents, location, sizeof(T))); |
| 103 } |
| 104 |
| 105 } // namespace test |
| 106 } // namespace crashpad |
| 107 |
| 108 #endif // CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ |
OLD | NEW |