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; |
| 31 | unsigned char Padding[14]; // Need 32 bytes |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 32 | #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 Berris | 4ef1a69 | 2016-10-06 07:09:40 +0000 | [diff] [blame] | 39 | #error "Unsupported word size." |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 40 | #endif |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 41 | }; |
Dean Michael Berris | 5cc4632 | 2017-05-04 04:59:20 +0000 | [diff] [blame] | 42 | |
| 43 | struct XRayFunctionSledIndex { |
| 44 | const XRaySledEntry* Begin; |
| 45 | const XRaySledEntry* End; |
| 46 | }; |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | namespace __xray { |
| 50 | |
| 51 | struct XRaySledMap { |
| 52 | const XRaySledEntry *Sleds; |
| 53 | size_t Entries; |
Dean Michael Berris | 5cc4632 | 2017-05-04 04:59:20 +0000 | [diff] [blame] | 54 | const XRayFunctionSledIndex *SledsIndex; |
| 55 | size_t Functions; |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Dean Michael Berris | 1b09aae | 2016-10-13 23:56:54 +0000 | [diff] [blame] | 58 | bool patchFunctionEntry(bool Enable, uint32_t FuncId, |
Dean Michael Berris | a814c94 | 2017-03-06 07:25:41 +0000 | [diff] [blame] | 59 | const XRaySledEntry &Sled, void (*Trampoline)()); |
Dean Michael Berris | 1b09aae | 2016-10-13 23:56:54 +0000 | [diff] [blame] | 60 | bool patchFunctionExit(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); |
| 61 | bool patchFunctionTailExit(bool Enable, uint32_t FuncId, |
| 62 | const XRaySledEntry &Sled); |
Dean Michael Berris | 29e16de | 2017-05-12 01:07:41 +0000 | [diff] [blame] | 63 | bool patchCustomEvent(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled); |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 64 | |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 65 | } // namespace __xray |
| 66 | |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 67 | extern "C" { |
| 68 | // The following functions have to be defined in assembler, on a per-platform |
| 69 | // basis. See xray_trampoline_*.S files for implementations. |
| 70 | extern void __xray_FunctionEntry(); |
| 71 | extern void __xray_FunctionExit(); |
Dean Michael Berris | 0d86810 | 2016-11-02 04:11:29 +0000 | [diff] [blame] | 72 | extern void __xray_FunctionTailExit(); |
Dean Michael Berris | a814c94 | 2017-03-06 07:25:41 +0000 | [diff] [blame] | 73 | extern void __xray_ArgLoggerEntry(); |
Dean Michael Berris | 29e16de | 2017-05-12 01:07:41 +0000 | [diff] [blame] | 74 | extern void __xray_CustomEvent(); |
Dean Michael Berris | d1617cd | 2016-09-20 14:35:57 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 77 | #endif |