Path: blob/main/contrib/llvm-project/compiler-rt/lib/xray/xray_interface_internal.h
35265 views
//===-- xray_interface_internal.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 XRay, a dynamic runtime instrumentation system.9//10// Implementation of the API functions. See also include/xray/xray_interface.h.11//12//===----------------------------------------------------------------------===//13#ifndef XRAY_INTERFACE_INTERNAL_H14#define XRAY_INTERFACE_INTERNAL_H1516#include "sanitizer_common/sanitizer_platform.h"17#include "xray/xray_interface.h"18#include <cstddef>19#include <cstdint>2021extern "C" {2223struct XRaySledEntry {24#if SANITIZER_WORDSIZE == 6425uint64_t Address;26uint64_t Function;27unsigned char Kind;28unsigned char AlwaysInstrument;29unsigned char Version;30unsigned char Padding[13]; // Need 32 bytes31uint64_t function() const {32// The target address is relative to the location of the Function variable.33return reinterpret_cast<uint64_t>(&Function) + Function;34}35uint64_t address() const {36// The target address is relative to the location of the Address variable.37return reinterpret_cast<uint64_t>(&Address) + Address;38}39#elif SANITIZER_WORDSIZE == 3240uint32_t Address;41uint32_t Function;42unsigned char Kind;43unsigned char AlwaysInstrument;44unsigned char Version;45unsigned char Padding[5]; // Need 16 bytes46uint32_t function() const {47// The target address is relative to the location of the Function variable.48return reinterpret_cast<uint32_t>(&Function) + Function;49}50uint32_t address() const {51// The target address is relative to the location of the Address variable.52return reinterpret_cast<uint32_t>(&Address) + Address;53}54#else55#error "Unsupported word size."56#endif57};5859struct XRayFunctionSledIndex {60const XRaySledEntry *Begin;61size_t Size;62// For an entry in the xray_fn_idx section, the address is relative to the63// location of the Begin variable.64const XRaySledEntry *fromPCRelative() const {65return reinterpret_cast<const XRaySledEntry *>(uintptr_t(&Begin) +66uintptr_t(Begin));67}68};69}7071namespace __xray {7273struct XRaySledMap {74const XRaySledEntry *Sleds;75size_t Entries;76const XRayFunctionSledIndex *SledsIndex;77size_t Functions;78};7980bool patchFunctionEntry(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled,81void (*Trampoline)());82bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);83bool patchFunctionTailExit(bool Enable, uint32_t FuncId,84const XRaySledEntry &Sled);85bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);86bool patchTypedEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);8788} // namespace __xray8990extern "C" {91// The following functions have to be defined in assembler, on a per-platform92// basis. See xray_trampoline_*.S files for implementations.93extern void __xray_FunctionEntry();94extern void __xray_FunctionExit();95extern void __xray_FunctionTailExit();96extern void __xray_ArgLoggerEntry();97extern void __xray_CustomEvent();98extern void __xray_TypedEvent();99}100101#endif102103104