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_common.h"
20 #include "sanitizer_common/sanitizer_internal_defs.h"
23 // This object should only ever be casted over the global (i.e. not constructed)
24 // in the ELF PT_NOTE in order for `addr()` to work correctly.
25 struct hwasan_global
{
26 // The size of this global variable. Note that the size in the descriptor is
27 // max 1 << 24. Larger globals have multiple descriptors.
28 uptr
size() const { return info
& 0xffffff; }
29 // The fully-relocated address of this global.
30 uptr
addr() const { return reinterpret_cast<uintptr_t>(this) + gv_relptr
; }
31 // The static tag of this global.
32 u8
tag() const { return info
>> 24; };
34 // The relative address between the start of the descriptor for the HWASan
35 // global (in the PT_NOTE), and the fully relocated address of the global.
40 // Walk through the specific DSO (as specified by the base, phdr, and phnum),
41 // and return the range of the [beginning, end) of the HWASan globals descriptor
43 ArrayRef
<const hwasan_global
> HwasanGlobalsFor(ElfW(Addr
) base
,
44 const ElfW(Phdr
) * phdr
,
47 } // namespace __hwasan
49 #endif // HWASAN_GLOBALS_H