bytemap.h 991 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #ifndef SCUDO_BYTEMAP_H_
  9. #define SCUDO_BYTEMAP_H_
  10. #include "atomic_helpers.h"
  11. #include "common.h"
  12. #include "mutex.h"
  13. namespace scudo {
  14. template <uptr Size> class FlatByteMap {
  15. public:
  16. void init() { DCHECK(Size == 0 || Map[0] == 0); }
  17. void unmapTestOnly() { memset(Map, 0, Size); }
  18. void set(uptr Index, u8 Value) {
  19. DCHECK_LT(Index, Size);
  20. DCHECK_EQ(0U, Map[Index]);
  21. Map[Index] = Value;
  22. }
  23. u8 operator[](uptr Index) {
  24. DCHECK_LT(Index, Size);
  25. return Map[Index];
  26. }
  27. void disable() {}
  28. void enable() {}
  29. private:
  30. u8 Map[Size] = {};
  31. };
  32. } // namespace scudo
  33. #endif // SCUDO_BYTEMAP_H_