bit::memory
debug_bounds_checker.hpp
1 /*****************************************************************************
2  * \file
3  * \brief This header contains the implementation of a debug bounds checker
4  *****************************************************************************/
5 
6 /*
7  The MIT License (MIT)
8 
9  Copyright (c) 2018 Matthew Rodusek
10 
11  Permission is hereby granted, free of charge, to any person obtaining a copy
12  of this software and associated documentation files (the "Software"), to deal
13  in the Software without restriction, including without limitation the rights
14  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the Software is
16  furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  SOFTWARE.
28 */
29 #ifndef BIT_MEMORY_POLICIES_BOUNDS_CHECKERS_DEBUG_BOUNDS_CHECKER_HPP
30 #define BIT_MEMORY_POLICIES_BOUNDS_CHECKERS_DEBUG_BOUNDS_CHECKER_HPP
31 
32 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
33 # pragma once
34 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
35 
36 #include "../../utilities/allocator_info.hpp" // allocator_info
37 #include "../../utilities/debugging.hpp" // debug_tag_start_bytes, etc
38 #include "../../utilities/errors.hpp" // get_buffer_overflow_handler
39 
40 #include "../../concepts/BoundsChecker.hpp" // is_bounds_checker
41 
42 #include <cstddef> // std::size_t
43 
44 namespace bit {
45  namespace memory {
46 
55  template<std::size_t FrontSize, std::size_t BackSize = FrontSize>
57  {
58  static_assert( FrontSize > 0, "FrontSize must be greater than 0" );
59  static_assert( BackSize > 0, "BackSize must be greater than 0" );
60 
61  //-----------------------------------------------------------------------
62  // Public Static Members
63  //-----------------------------------------------------------------------
64  public:
65 
66  static constexpr std::size_t front_size = FrontSize;
67  static constexpr std::size_t back_size = BackSize;
68 
69  //-----------------------------------------------------------------------
70  // Preparation
71  //-----------------------------------------------------------------------
72  public:
73 
74  void prepare_front_fence( void* p, std::size_t size ) noexcept;
75 
76  void prepare_back_fence( void* p, std::size_t size ) noexcept;
77 
78  //-----------------------------------------------------------------------
79  // Checking
80  //-----------------------------------------------------------------------
81  public:
82 
83  void check_front_fence( const allocator_info& info,
84  void* p,
85  std::size_t size ) noexcept;
86 
87  void check_back_fence( const allocator_info& info,
88  void* p,
89  std::size_t size ) noexcept;
90  };
91 
92  static_assert( is_bounds_checker_v<debug_bounds_checker<1,1>>,
93  "debug_bounds_checker must satisfy BoundsChecker" );
94 
95  } // namespace memory
96 } // namespace bit
97 
98 #include "detail/debug_bounds_checker.inl"
99 
100 #endif /* BIT_MEMORY_POLICIES_BOUNDS_CHECKERS_DEBUG_BOUNDS_CHECKER_HPP */
This type is used for checking boundaries around memory allocations to determine if buffer-overflows ...
This type is used to hold the generic information for a given allocator.