blob: 4a2784612fcbb0f3f800b502ecb2d4b89c4fb887 [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;
31 unsigned char Padding[14]; // Need 32 bytes
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000032#elif SANITIZER_WORDSIZE == 32
33 uint32_t Address;
34 uint32_t Function;
35 unsigned char Kind;
36 unsigned char AlwaysInstrument;
37 unsigned char Padding[6]; // Need 16 bytes
38#else
Dean Michael Berris4ef1a692016-10-06 07:09:40 +000039#error "Unsupported word size."
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000040#endif
Dean Michael Berris938c5032016-07-21 07:39:55 +000041};
Dean Michael Berris5cc46322017-05-04 04:59:20 +000042
43struct XRayFunctionSledIndex {
44 const XRaySledEntry* Begin;
45 const XRaySledEntry* End;
46};
Dean Michael Berris938c5032016-07-21 07:39:55 +000047}
48
49namespace __xray {
50
51struct XRaySledMap {
52 const XRaySledEntry *Sleds;
53 size_t Entries;
Dean Michael Berris5cc46322017-05-04 04:59:20 +000054 const XRayFunctionSledIndex *SledsIndex;
55 size_t Functions;
Dean Michael Berris938c5032016-07-21 07:39:55 +000056};
57
Dean Michael Berris1b09aae2016-10-13 23:56:54 +000058bool patchFunctionEntry(bool Enable, uint32_t FuncId,
Dean Michael Berrisa814c942017-03-06 07:25:41 +000059 const XRaySledEntry &Sled, void (*Trampoline)());
Dean Michael Berris1b09aae2016-10-13 23:56:54 +000060bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);
61bool patchFunctionTailExit(bool Enable, uint32_t FuncId,
62 const XRaySledEntry &Sled);
Dean Michael Berris29e16de2017-05-12 01:07:41 +000063bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled);
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000064
Dean Michael Berris938c5032016-07-21 07:39:55 +000065} // namespace __xray
66
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000067extern "C" {
68// The following functions have to be defined in assembler, on a per-platform
69// basis. See xray_trampoline_*.S files for implementations.
70extern void __xray_FunctionEntry();
71extern void __xray_FunctionExit();
Dean Michael Berris0d868102016-11-02 04:11:29 +000072extern void __xray_FunctionTailExit();
Dean Michael Berrisa814c942017-03-06 07:25:41 +000073extern void __xray_ArgLoggerEntry();
Dean Michael Berris29e16de2017-05-12 01:07:41 +000074extern void __xray_CustomEvent();
Dean Michael Berrisd1617cd2016-09-20 14:35:57 +000075}
76
Dean Michael Berris938c5032016-07-21 07:39:55 +000077#endif