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 14#ifndef HWASAN_GLOBALS_H 15#define HWASAN_GLOBALS_H 16 17#include <link.h> 18 19#include "sanitizer_common/sanitizer_common.h" 20#include "sanitizer_common/sanitizer_internal_defs.h" 21 22namespace __hwasan { 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. 25struct 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; }; 33 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. 36 s32 gv_relptr; 37 u32 info; 38}; 39 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 42// array. 43ArrayRef<const hwasan_global> HwasanGlobalsFor(ElfW(Addr) base, 44 const ElfW(Phdr) * phdr, 45 ElfW(Half) phnum); 46 47} // namespace __hwasan 48 49#endif // HWASAN_GLOBALS_H 50