Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_globals.h
35236 views
//===-- hwasan_globals.h ----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of HWAddressSanitizer.9//10// Private Hwasan header.11//===----------------------------------------------------------------------===//1213#ifndef HWASAN_GLOBALS_H14#define HWASAN_GLOBALS_H1516#include <link.h>1718#include "sanitizer_common/sanitizer_array_ref.h"19#include "sanitizer_common/sanitizer_common.h"20#include "sanitizer_common/sanitizer_internal_defs.h"2122namespace __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 is27// max 1 << 24. Larger globals have multiple descriptors.28uptr size() const { return info & 0xffffff; }29// The fully-relocated address of this global.30uptr addr() const { return reinterpret_cast<uintptr_t>(this) + gv_relptr; }31// The static tag of this global.32u8 tag() const { return info >> 24; };3334// The relative address between the start of the descriptor for the HWASan35// global (in the PT_NOTE), and the fully relocated address of the global.36s32 gv_relptr;37u32 info;38};3940// 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 descriptor42// array.43ArrayRef<const hwasan_global> HwasanGlobalsFor(ElfW(Addr) base,44const ElfW(Phdr) * phdr,45ElfW(Half) phnum);4647} // namespace __hwasan4849#endif // HWASAN_GLOBALS_H505152