Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_globals.h
35236 views
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_array_ref.h"
20
#include "sanitizer_common/sanitizer_common.h"
21
#include "sanitizer_common/sanitizer_internal_defs.h"
22
23
namespace __hwasan {
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; };
34
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.
37
s32 gv_relptr;
38
u32 info;
39
};
40
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
43
// array.
44
ArrayRef<const hwasan_global> HwasanGlobalsFor(ElfW(Addr) base,
45
const ElfW(Phdr) * phdr,
46
ElfW(Half) phnum);
47
48
} // namespace __hwasan
49
50
#endif // HWASAN_GLOBALS_H
51
52