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