Kostya Kortchinsky | 7421f7b | 2019-03-05 17:36:11 | [diff] [blame] | 1 | //===-- bytemap.h -----------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef SCUDO_BYTEMAP_H_ |
| 10 | #define SCUDO_BYTEMAP_H_ |
| 11 | |
| 12 | #include "atomic_helpers.h" |
| 13 | #include "common.h" |
| 14 | #include "mutex.h" |
| 15 | |
| 16 | namespace scudo { |
| 17 | |
| 18 | template <uptr Size> class FlatByteMap { |
| 19 | public: |
Kostya Kortchinsky | a45877e | 2021-05-25 22:00:58 | [diff] [blame] | 20 | void init() { DCHECK(Size == 0 || Map[0] == 0); } |
Kostya Kortchinsky | 7421f7b | 2019-03-05 17:36:11 | [diff] [blame] | 21 | |
Kostya Kortchinsky | a45877e | 2021-05-25 22:00:58 | [diff] [blame] | 22 | void unmapTestOnly() { memset(Map, 0, Size); } |
Kostya Kortchinsky | 624a24e | 2019-06-11 19:50:12 | [diff] [blame] | 23 | |
Kostya Kortchinsky | 7421f7b | 2019-03-05 17:36:11 | [diff] [blame] | 24 | void set(uptr Index, u8 Value) { |
| 25 | DCHECK_LT(Index, Size); |
| 26 | DCHECK_EQ(0U, Map[Index]); |
| 27 | Map[Index] = Value; |
| 28 | } |
| 29 | u8 operator[](uptr Index) { |
| 30 | DCHECK_LT(Index, Size); |
| 31 | return Map[Index]; |
| 32 | } |
| 33 | |
Kostya Kortchinsky | 9ef6faf | 2020-01-09 19:43:16 | [diff] [blame] | 34 | void disable() {} |
| 35 | void enable() {} |
| 36 | |
Kostya Kortchinsky | 7421f7b | 2019-03-05 17:36:11 | [diff] [blame] | 37 | private: |
Kostya Kortchinsky | a45877e | 2021-05-25 22:00:58 | [diff] [blame] | 38 | u8 Map[Size] = {}; |
Kostya Kortchinsky | 7421f7b | 2019-03-05 17:36:11 | [diff] [blame] | 39 | }; |
| 40 | |
Kostya Kortchinsky | 7421f7b | 2019-03-05 17:36:11 | [diff] [blame] | 41 | } // namespace scudo |
| 42 | |
| 43 | #endif // SCUDO_BYTEMAP_H_ |