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