1 //===-- xray_interface_internal.h -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file is a part of XRay, a dynamic runtime instrumentation system.
11 // Implementation of the API functions. See also include/xray/xray_interface.h.
13 //===----------------------------------------------------------------------===//
14 #ifndef XRAY_INTERFACE_INTERNAL_H
15 #define XRAY_INTERFACE_INTERNAL_H
17 #include "sanitizer_common/sanitizer_platform.h"
18 #include "xray/xray_interface.h"
24 struct XRaySledEntry
{
25 #if SANITIZER_WORDSIZE == 64
29 unsigned char AlwaysInstrument
;
30 unsigned char Version
;
31 unsigned char Padding
[13]; // Need 32 bytes
32 uint64_t function() const {
33 // The target address is relative to the location of the Function variable.
34 return reinterpret_cast<uint64_t>(&Function
) + Function
;
36 uint64_t address() const {
37 // The target address is relative to the location of the Address variable.
38 return reinterpret_cast<uint64_t>(&Address
) + Address
;
40 #elif SANITIZER_WORDSIZE == 32
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
;
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
;
56 #error "Unsupported word size."
60 struct XRayFunctionSledIndex
{
61 const XRaySledEntry
*Begin
;
62 const XRaySledEntry
*End
;
69 const XRaySledEntry
*Sleds
;
71 const XRayFunctionSledIndex
*SledsIndex
;
75 bool patchFunctionEntry(bool Enable
, uint32_t FuncId
, const XRaySledEntry
&Sled
,
76 void (*Trampoline
)());
77 bool patchFunctionExit(bool Enable
, uint32_t FuncId
, const XRaySledEntry
&Sled
);
78 bool patchFunctionTailExit(bool Enable
, uint32_t FuncId
,
79 const XRaySledEntry
&Sled
);
80 bool patchCustomEvent(bool Enable
, uint32_t FuncId
, const XRaySledEntry
&Sled
);
81 bool patchTypedEvent(bool Enable
, uint32_t FuncId
, const XRaySledEntry
&Sled
);
86 // The following functions have to be defined in assembler, on a per-platform
87 // basis. See xray_trampoline_*.S files for implementations.
88 extern void __xray_FunctionEntry();
89 extern void __xray_FunctionExit();
90 extern void __xray_FunctionTailExit();
91 extern void __xray_ArgLoggerEntry();
92 extern void __xray_CustomEvent();
93 extern void __xray_TypedEvent();