blob: 8ca87457437e9ac491e5bc8a5162f223b367b3ef [file] [log] [blame]
Dean Michael Berris938c5032016-07-21 07:39:55 +00001//===-- 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
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000018#include "sanitizer_common/sanitizer_platform.h"
Dean Michael Berris4ef1a692016-10-06 07:09:40 +000019#include "xray/xray_interface.h"
Dean Michael Berris938c5032016-07-21 07:39:55 +000020#include <cstddef>
21#include <cstdint>
22
23extern "C" {
24
25struct XRaySledEntry {
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000026#if SANITIZER_WORDSIZE == 64
Dean Michael Berris938c5032016-07-21 07:39:55 +000027 uint64_t Address;
28 uint64_t Function;
29 unsigned char Kind;
30 unsigned char AlwaysInstrument;
Dean Michael Berris71f88a92017-08-23 04:42:37 +000031 unsigned char Version;
32 unsigned char Padding[13]; // Need 32 bytes
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000033#elif SANITIZER_WORDSIZE == 32
34 uint32_t Address;
35 uint32_t Function;
36 unsigned char Kind;
37 unsigned char AlwaysInstrument;
Dean Michael Berris71f88a92017-08-23 04:42:37 +000038 unsigned char Version;
39 unsigned char Padding[5]; // Need 16 bytes
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000040#else
Dean Michael Berris4ef1a692016-10-06 07:09:40 +000041#error "Unsupported word size."
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000042#endif
Dean Michael Berris938c5032016-07-21 07:39:55 +000043};
Dean Michael Berris5cc46322017-05-04 04:59:20 +000044
45struct XRayFunctionSledIndex {
Keith Wyssadb092e2018-04-17 21:28:53 +000046 const XRaySledEntry *Begin;
47 const XRaySledEntry *End;
Dean Michael Berris5cc46322017-05-04 04:59:20 +000048};
Dean Michael Berris938c5032016-07-21 07:39:55 +000049}
50
51namespace __xray {
52
53struct XRaySledMap {
54 const XRaySledEntry *Sleds;
55 size_t Entries;
Dean Michael Berris5cc46322017-05-04 04:59:20 +000056 const XRayFunctionSledIndex *SledsIndex;
57 size_t Functions;
Dean Michael Berris938c5032016-07-21 07:39:55 +000058};
59
Keith Wyssadb092e2018-04-17 21:28:53 +000060bool patchFunctionEntry(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled,
61 void (*Trampoline)());
Dean Michael Berris1b09aae2016-10-13 23:56:54 +000062bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);
63bool patchFunctionTailExit(bool Enable, uint32_t FuncId,
64 const XRaySledEntry &Sled);
Dean Michael Berris29e16de2017-05-12 01:07:41 +000065bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);
Keith Wyssadb092e2018-04-17 21:28:53 +000066bool patchTypedEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000067
Dean Michael Berris938c5032016-07-21 07:39:55 +000068} // namespace __xray
69
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000070extern "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();
Dean Michael Berris0d868102016-11-02 04:11:29 +000075extern void __xray_FunctionTailExit();
Dean Michael Berrisa814c942017-03-06 07:25:41 +000076extern void __xray_ArgLoggerEntry();
Dean Michael Berris29e16de2017-05-12 01:07:41 +000077extern void __xray_CustomEvent();
Keith Wyssadb092e2018-04-17 21:28:53 +000078extern void __xray_TypedEvent();
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000079}
80
Dean Michael Berris938c5032016-07-21 07:39:55 +000081#endif