1258945Sroberto//===-- xray_interface_internal.h -------------------------------*- C++ -*-===// 2280849Scy// 3258945Sroberto// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4258945Sroberto// See https://llvm.org/LICENSE.txt for license information. 5258945Sroberto// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6258945Sroberto// 7258945Sroberto//===----------------------------------------------------------------------===// 8258945Sroberto// 9258945Sroberto// This file is a part of XRay, a dynamic runtime instrumentation system. 10258945Sroberto// 11258945Sroberto// Implementation of the API functions. See also include/xray/xray_interface.h. 12258945Sroberto// 13258945Sroberto//===----------------------------------------------------------------------===// 14258945Sroberto#ifndef XRAY_INTERFACE_INTERNAL_H 15258945Sroberto#define XRAY_INTERFACE_INTERNAL_H 16258945Sroberto 17258945Sroberto#include "sanitizer_common/sanitizer_platform.h" 18280849Scy#include "xray/xray_interface.h" 19258945Sroberto#include <cstddef> 20258945Sroberto#include <cstdint> 21258945Sroberto 22258945Srobertoextern "C" { 23258945Sroberto 24258945Srobertostruct XRaySledEntry { 25280849Scy#if SANITIZER_WORDSIZE == 64 26280849Scy uint64_t Address; 27280849Scy uint64_t Function; 28280849Scy unsigned char Kind; 29280849Scy unsigned char AlwaysInstrument; 30280849Scy unsigned char Version; 31280849Scy unsigned char Padding[13]; // Need 32 bytes 32258945Sroberto uint64_t function() const { 33280849Scy // The target address is relative to the location of the Function variable. 34258945Sroberto return reinterpret_cast<uint64_t>(&Function) + Function; 35258945Sroberto } 36280849Scy uint64_t address() const { 37280849Scy // The target address is relative to the location of the Address variable. 38258945Sroberto return reinterpret_cast<uint64_t>(&Address) + Address; 39258945Sroberto } 40#elif SANITIZER_WORDSIZE == 32 41 uint32_t Address; 42 uint32_t Function; 43 unsigned char Kind; 44 unsigned char AlwaysInstrument; 45 unsigned char Version; 46 unsigned char Padding[5]; // Need 16 bytes 47 uint32_t function() const { 48 // The target address is relative to the location of the Function variable. 49 return reinterpret_cast<uint32_t>(&Function) + Function; 50 } 51 uint32_t address() const { 52 // The target address is relative to the location of the Address variable. 53 return reinterpret_cast<uint32_t>(&Address) + Address; 54 } 55#else 56#error "Unsupported word size." 57#endif 58}; 59 60struct XRayFunctionSledIndex { 61 const XRaySledEntry *Begin; 62 const XRaySledEntry *End; 63}; 64} 65 66namespace __xray { 67 68struct XRaySledMap { 69 const XRaySledEntry *Sleds; 70 size_t Entries; 71 const XRayFunctionSledIndex *SledsIndex; 72 size_t Functions; 73}; 74 75bool patchFunctionEntry(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled, 76 void (*Trampoline)()); 77bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); 78bool patchFunctionTailExit(bool Enable, uint32_t FuncId, 79 const XRaySledEntry &Sled); 80bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); 81bool patchTypedEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); 82 83} // namespace __xray 84 85extern "C" { 86// The following functions have to be defined in assembler, on a per-platform 87// basis. See xray_trampoline_*.S files for implementations. 88extern void __xray_FunctionEntry(); 89extern void __xray_FunctionExit(); 90extern void __xray_FunctionTailExit(); 91extern void __xray_ArgLoggerEntry(); 92extern void __xray_CustomEvent(); 93extern void __xray_TypedEvent(); 94} 95 96#endif 97