Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 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 | |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 18 | #include "sanitizer_common/sanitizer_platform.h" |
Dean Michael Berris | 4ef1a69 | 2016-10-06 07:09:40 +0000 | [diff] [blame] | 19 | #include "xray/xray_interface.h" |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 20 | #include <cstddef> |
| 21 | #include <cstdint> |
| 22 | |
| 23 | extern "C" { |
| 24 | |
| 25 | struct XRaySledEntry { |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 26 | #if SANITIZER_WORDSIZE == 64 |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 27 | uint64_t Address; |
| 28 | uint64_t Function; |
| 29 | unsigned char Kind; |
| 30 | unsigned char AlwaysInstrument; |
Dean Michael Berris | 71f88a9 | 2017-08-23 04:42:37 +0000 | [diff] [blame] | 31 | unsigned char Version; |
| 32 | unsigned char Padding[13]; // Need 32 bytes |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 33 | #elif SANITIZER_WORDSIZE == 32 |
| 34 | uint32_t Address; |
| 35 | uint32_t Function; |
| 36 | unsigned char Kind; |
| 37 | unsigned char AlwaysInstrument; |
Dean Michael Berris | 71f88a9 | 2017-08-23 04:42:37 +0000 | [diff] [blame] | 38 | unsigned char Version; |
| 39 | unsigned char Padding[5]; // Need 16 bytes |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 40 | #else |
Dean Michael Berris | 4ef1a69 | 2016-10-06 07:09:40 +0000 | [diff] [blame] | 41 | #error "Unsupported word size." |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 42 | #endif |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 43 | }; |
Dean Michael Berris | 5cc4632 | 2017-05-04 04:59:20 +0000 | [diff] [blame] | 44 | |
| 45 | struct XRayFunctionSledIndex { |
Keith Wyss | adb092e | 2018-04-17 21:28:53 +0000 | [diff] [blame] | 46 | const XRaySledEntry *Begin; |
| 47 | const XRaySledEntry *End; |
Dean Michael Berris | 5cc4632 | 2017-05-04 04:59:20 +0000 | [diff] [blame] | 48 | }; |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | namespace __xray { |
| 52 | |
| 53 | struct XRaySledMap { |
| 54 | const XRaySledEntry *Sleds; |
| 55 | size_t Entries; |
Dean Michael Berris | 5cc4632 | 2017-05-04 04:59:20 +0000 | [diff] [blame] | 56 | const XRayFunctionSledIndex *SledsIndex; |
| 57 | size_t Functions; |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Keith Wyss | adb092e | 2018-04-17 21:28:53 +0000 | [diff] [blame] | 60 | bool patchFunctionEntry(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled, |
| 61 | void (*Trampoline)()); |
Dean Michael Berris | 1b09aae | 2016-10-13 23:56:54 +0000 | [diff] [blame] | 62 | bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); |
| 63 | bool patchFunctionTailExit(bool Enable, uint32_t FuncId, |
| 64 | const XRaySledEntry &Sled); |
Dean Michael Berris | 29e16de | 2017-05-12 01:07:41 +0000 | [diff] [blame] | 65 | bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); |
Keith Wyss | adb092e | 2018-04-17 21:28:53 +0000 | [diff] [blame] | 66 | bool patchTypedEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 67 | |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 68 | } // namespace __xray |
| 69 | |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 70 | extern "C" { |
| 71 | // The following functions have to be defined in assembler, on a per-platform |
| 72 | // basis. See xray_trampoline_*.S files for implementations. |
| 73 | extern void __xray_FunctionEntry(); |
| 74 | extern void __xray_FunctionExit(); |
Dean Michael Berris | 0d86810 | 2016-11-02 04:11:29 +0000 | [diff] [blame] | 75 | extern void __xray_FunctionTailExit(); |
Dean Michael Berris | a814c94 | 2017-03-06 07:25:41 +0000 | [diff] [blame] | 76 | extern void __xray_ArgLoggerEntry(); |
Dean Michael Berris | 29e16de | 2017-05-12 01:07:41 +0000 | [diff] [blame] | 77 | extern void __xray_CustomEvent(); |
Keith Wyss | adb092e | 2018-04-17 21:28:53 +0000 | [diff] [blame] | 78 | extern void __xray_TypedEvent(); |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 81 | #endif |