hwasan_globals.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===-- hwasan_globals.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. // This file is a part of HWAddressSanitizer.
  10. //
  11. // Private Hwasan header.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef HWASAN_GLOBALS_H
  14. #define HWASAN_GLOBALS_H
  15. #include <link.h>
  16. #include "sanitizer_common/sanitizer_common.h"
  17. #include "sanitizer_common/sanitizer_internal_defs.h"
  18. namespace __hwasan {
  19. // This object should only ever be casted over the global (i.e. not constructed)
  20. // in the ELF PT_NOTE in order for `addr()` to work correctly.
  21. struct hwasan_global {
  22. // The size of this global variable. Note that the size in the descriptor is
  23. // max 1 << 24. Larger globals have multiple descriptors.
  24. uptr size() const { return info & 0xffffff; }
  25. // The fully-relocated address of this global.
  26. uptr addr() const { return reinterpret_cast<uintptr_t>(this) + gv_relptr; }
  27. // The static tag of this global.
  28. u8 tag() const { return info >> 24; };
  29. // The relative address between the start of the descriptor for the HWASan
  30. // global (in the PT_NOTE), and the fully relocated address of the global.
  31. s32 gv_relptr;
  32. u32 info;
  33. };
  34. // Walk through the specific DSO (as specified by the base, phdr, and phnum),
  35. // and return the range of the [beginning, end) of the HWASan globals descriptor
  36. // array.
  37. ArrayRef<const hwasan_global> HwasanGlobalsFor(ElfW(Addr) base,
  38. const ElfW(Phdr) * phdr,
  39. ElfW(Half) phnum);
  40. } // namespace __hwasan
  41. #endif // HWASAN_GLOBALS_H