1 //===-- xray_interface_internal.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 XRay, a dynamic runtime instrumentation system. 10 // 11 // Implementation of the API functions. See also include/xray/xray_interface.h. 12 // 13 //===----------------------------------------------------------------------===// 14 #ifndef XRAY_INTERFACE_INTERNAL_H 15 #define XRAY_INTERFACE_INTERNAL_H 16 17 #include "sanitizer_common/sanitizer_platform.h" 18 #include "xray/xray_interface.h" 19 #include <cstddef> 20 #include <cstdint> 21 22 extern "C" { 23 24 struct XRaySledEntry { 25 #if SANITIZER_WORDSIZE == 64 26 uint64_t Address; 27 uint64_t Function; 28 unsigned char Kind; 29 unsigned char AlwaysInstrument; 30 unsigned char Version; 31 unsigned char Padding[13]; // Need 32 bytes 32 #elif SANITIZER_WORDSIZE == 32 33 uint32_t Address; 34 uint32_t Function; 35 unsigned char Kind; 36 unsigned char AlwaysInstrument; 37 unsigned char Version; 38 unsigned char Padding[5]; // Need 16 bytes 39 #else 40 #error "Unsupported word size." 41 #endif 42 }; 43 44 struct XRayFunctionSledIndex { 45 const XRaySledEntry *Begin; 46 const XRaySledEntry *End; 47 }; 48 } 49 50 namespace __xray { 51 52 struct XRaySledMap { 53 const XRaySledEntry *Sleds; 54 size_t Entries; 55 const XRayFunctionSledIndex *SledsIndex; 56 size_t Functions; 57 }; 58 59 bool patchFunctionEntry(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled, 60 void (*Trampoline)()); 61 bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); 62 bool patchFunctionTailExit(bool Enable, uint32_t FuncId, 63 const XRaySledEntry &Sled); 64 bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); 65 bool patchTypedEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); 66 67 } // namespace __xray 68 69 extern "C" { 70 // The following functions have to be defined in assembler, on a per-platform 71 // basis. See xray_trampoline_*.S files for implementations. 72 extern void __xray_FunctionEntry(); 73 extern void __xray_FunctionExit(); 74 extern void __xray_FunctionTailExit(); 75 extern void __xray_ArgLoggerEntry(); 76 extern void __xray_CustomEvent(); 77 extern void __xray_TypedEvent(); 78 } 79 80 #endif 81