Home | History | Annotate | Line # | Download | only in xray
      1  1.1  kamil //===- xray_interface.h -----------------------------------------*- C++ -*-===//
      2  1.1  kamil //
      3  1.1  kamil //                     The LLVM Compiler Infrastructure
      4  1.1  kamil //
      5  1.1  kamil // This file is distributed under the University of Illinois Open Source
      6  1.1  kamil // License. See LICENSE.TXT for details.
      7  1.1  kamil //
      8  1.1  kamil //===----------------------------------------------------------------------===//
      9  1.1  kamil //
     10  1.1  kamil // This file is a part of XRay, a dynamic runtime instrumentation system.
     11  1.1  kamil //
     12  1.1  kamil // APIs for controlling XRay functionality explicitly.
     13  1.1  kamil //===----------------------------------------------------------------------===//
     14  1.1  kamil 
     15  1.1  kamil #ifndef XRAY_XRAY_INTERFACE_H
     16  1.1  kamil #define XRAY_XRAY_INTERFACE_H
     17  1.1  kamil 
     18  1.1  kamil #include <cstddef>
     19  1.1  kamil #include <cstdint>
     20  1.1  kamil 
     21  1.1  kamil extern "C" {
     22  1.1  kamil 
     23  1.1  kamil /// Synchronize this with AsmPrinter::SledKind in LLVM.
     24  1.1  kamil enum XRayEntryType {
     25  1.1  kamil   ENTRY = 0,
     26  1.1  kamil   EXIT = 1,
     27  1.1  kamil   TAIL = 2,
     28  1.1  kamil   LOG_ARGS_ENTRY = 3,
     29  1.1  kamil   CUSTOM_EVENT = 4,
     30  1.1  kamil   TYPED_EVENT = 5,
     31  1.1  kamil };
     32  1.1  kamil 
     33  1.1  kamil /// Provide a function to invoke for when instrumentation points are hit. This
     34  1.1  kamil /// is a user-visible control surface that overrides the default implementation.
     35  1.1  kamil /// The function provided should take the following arguments:
     36  1.1  kamil ///
     37  1.1  kamil ///   - function id: an identifier that indicates the id of a function; this id
     38  1.1  kamil ///                  is generated by xray; the mapping between the function id
     39  1.1  kamil ///                  and the actual function pointer is available through
     40  1.1  kamil ///                  __xray_table.
     41  1.1  kamil ///   - entry type: identifies what kind of instrumentation point was
     42  1.1  kamil ///                 encountered (function entry, function exit, etc.). See the
     43  1.1  kamil ///                 enum XRayEntryType for more details.
     44  1.1  kamil ///
     45  1.1  kamil /// The user handler must handle correctly spurious calls after this handler is
     46  1.1  kamil /// removed or replaced with another handler, because it would be too costly for
     47  1.1  kamil /// XRay runtime to avoid spurious calls.
     48  1.1  kamil /// To prevent circular calling, the handler function itself and all its
     49  1.1  kamil /// direct&indirect callees must not be instrumented with XRay, which can be
     50  1.1  kamil /// achieved by marking them all with: __attribute__((xray_never_instrument))
     51  1.1  kamil ///
     52  1.1  kamil /// Returns 1 on success, 0 on error.
     53  1.1  kamil extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));
     54  1.1  kamil 
     55  1.1  kamil /// This removes whatever the currently provided handler is. Returns 1 on
     56  1.1  kamil /// success, 0 on error.
     57  1.1  kamil extern int __xray_remove_handler();
     58  1.1  kamil 
     59  1.1  kamil /// Use XRay to log the first argument of each (instrumented) function call.
     60  1.1  kamil /// When this function exits, all threads will have observed the effect and
     61  1.1  kamil /// start logging their subsequent affected function calls (if patched).
     62  1.1  kamil ///
     63  1.1  kamil /// Returns 1 on success, 0 on error.
     64  1.1  kamil extern int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType,
     65  1.1  kamil                                                  uint64_t));
     66  1.1  kamil 
     67  1.1  kamil /// Disables the XRay handler used to log first arguments of function calls.
     68  1.1  kamil /// Returns 1 on success, 0 on error.
     69  1.1  kamil extern int __xray_remove_handler_arg1();
     70  1.1  kamil 
     71  1.1  kamil /// Provide a function to invoke when XRay encounters a custom event.
     72  1.1  kamil extern int __xray_set_customevent_handler(void (*entry)(void *, std::size_t));
     73  1.1  kamil 
     74  1.1  kamil /// This removes whatever the currently provided custom event handler is.
     75  1.1  kamil /// Returns 1 on success, 0 on error.
     76  1.1  kamil extern int __xray_remove_customevent_handler();
     77  1.1  kamil 
     78  1.1  kamil /// Set a handler for xray typed event logging. The first parameter is a type
     79  1.1  kamil /// identifier, the second is a payload, and the third is the payload size.
     80  1.1  kamil extern int __xray_set_typedevent_handler(void (*entry)(uint16_t, const void *,
     81  1.1  kamil                                                        std::size_t));
     82  1.1  kamil 
     83  1.1  kamil /// Removes the currently set typed event handler.
     84  1.1  kamil /// Returns 1 on success, 0 on error.
     85  1.1  kamil extern int __xray_remove_typedevent_handler();
     86  1.1  kamil 
     87  1.1  kamil extern uint16_t __xray_register_event_type(const char *event_type);
     88  1.1  kamil 
     89  1.1  kamil enum XRayPatchingStatus {
     90  1.1  kamil   NOT_INITIALIZED = 0,
     91  1.1  kamil   SUCCESS = 1,
     92  1.1  kamil   ONGOING = 2,
     93  1.1  kamil   FAILED = 3,
     94  1.1  kamil };
     95  1.1  kamil 
     96  1.1  kamil /// This tells XRay to patch the instrumentation points. See XRayPatchingStatus
     97  1.1  kamil /// for possible result values.
     98  1.1  kamil extern XRayPatchingStatus __xray_patch();
     99  1.1  kamil 
    100  1.1  kamil /// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
    101  1.1  kamil /// result values.
    102  1.1  kamil extern XRayPatchingStatus __xray_unpatch();
    103  1.1  kamil 
    104  1.1  kamil /// This patches a specific function id. See XRayPatchingStatus for possible
    105  1.1  kamil /// result values.
    106  1.1  kamil extern XRayPatchingStatus __xray_patch_function(int32_t FuncId);
    107  1.1  kamil 
    108  1.1  kamil /// This unpatches a specific function id. See XRayPatchingStatus for possible
    109  1.1  kamil /// result values.
    110  1.1  kamil extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);
    111  1.1  kamil 
    112  1.1  kamil /// This function returns the address of the function provided a valid function
    113  1.1  kamil /// id. We return 0 if we encounter any error, even if 0 may be a valid function
    114  1.1  kamil /// address.
    115  1.1  kamil extern uintptr_t __xray_function_address(int32_t FuncId);
    116  1.1  kamil 
    117  1.1  kamil /// This function returns the maximum valid function id. Returns 0 if we
    118  1.1  kamil /// encounter errors (when there are no instrumented functions, etc.).
    119  1.1  kamil extern size_t __xray_max_function_id();
    120  1.1  kamil 
    121  1.1  kamil /// Initialize the required XRay data structures. This is useful in cases where
    122  1.1  kamil /// users want to control precisely when the XRay instrumentation data
    123  1.1  kamil /// structures are initialized, for example when the XRay library is built with
    124  1.1  kamil /// the XRAY_NO_PREINIT preprocessor definition.
    125  1.1  kamil ///
    126  1.1  kamil /// Calling __xray_init() more than once is safe across multiple threads.
    127  1.1  kamil extern void __xray_init();
    128  1.1  kamil 
    129  1.1  kamil } // end extern "C"
    130  1.1  kamil 
    131  1.1  kamil #endif // XRAY_XRAY_INTERFACE_H
    132