Path: blob/main/contrib/llvm-project/compiler-rt/include/xray/xray_interface.h
35262 views
//===- xray_interface.h -----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of XRay, a dynamic runtime instrumentation system.9//10// APIs for controlling XRay functionality explicitly.11//===----------------------------------------------------------------------===//1213#ifndef XRAY_XRAY_INTERFACE_H14#define XRAY_XRAY_INTERFACE_H1516#include <cstddef>17#include <cstdint>1819extern "C" {2021/// Synchronize this with AsmPrinter::SledKind in LLVM.22enum XRayEntryType {23ENTRY = 0,24EXIT = 1,25TAIL = 2,26LOG_ARGS_ENTRY = 3,27CUSTOM_EVENT = 4,28TYPED_EVENT = 5,29};3031/// Provide a function to invoke for when instrumentation points are hit. This32/// is a user-visible control surface that overrides the default implementation.33/// The function provided should take the following arguments:34///35/// - function id: an identifier that indicates the id of a function; this id36/// is generated by xray; the mapping between the function id37/// and the actual function pointer is available through38/// __xray_table.39/// - entry type: identifies what kind of instrumentation point was40/// encountered (function entry, function exit, etc.). See the41/// enum XRayEntryType for more details.42///43/// The user handler must handle correctly spurious calls after this handler is44/// removed or replaced with another handler, because it would be too costly for45/// XRay runtime to avoid spurious calls.46/// To prevent circular calling, the handler function itself and all its47/// direct&indirect callees must not be instrumented with XRay, which can be48/// achieved by marking them all with: __attribute__((xray_never_instrument))49///50/// Returns 1 on success, 0 on error.51extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));5253/// This removes whatever the currently provided handler is. Returns 1 on54/// success, 0 on error.55extern int __xray_remove_handler();5657/// Use XRay to log the first argument of each (instrumented) function call.58/// When this function exits, all threads will have observed the effect and59/// start logging their subsequent affected function calls (if patched).60///61/// Returns 1 on success, 0 on error.62extern int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType,63uint64_t));6465/// Disables the XRay handler used to log first arguments of function calls.66/// Returns 1 on success, 0 on error.67extern int __xray_remove_handler_arg1();6869/// Provide a function to invoke when XRay encounters a custom event.70extern int __xray_set_customevent_handler(void (*entry)(void *, std::size_t));7172/// This removes whatever the currently provided custom event handler is.73/// Returns 1 on success, 0 on error.74extern int __xray_remove_customevent_handler();7576/// Set a handler for xray typed event logging. The first parameter is a type77/// identifier, the second is a payload, and the third is the payload size.78/// NOTE: fdrLoggingHandleTypedEvent only supports uint16_t event type.79extern int __xray_set_typedevent_handler(void (*entry)(size_t, const void *,80size_t));8182/// Removes the currently set typed event handler.83/// Returns 1 on success, 0 on error.84extern int __xray_remove_typedevent_handler();8586extern uint16_t __xray_register_event_type(const char *event_type);8788enum XRayPatchingStatus {89NOT_INITIALIZED = 0,90SUCCESS = 1,91ONGOING = 2,92FAILED = 3,93};9495/// This tells XRay to patch the instrumentation points. See XRayPatchingStatus96/// for possible result values.97extern XRayPatchingStatus __xray_patch();9899/// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible100/// result values.101extern XRayPatchingStatus __xray_unpatch();102103/// This patches a specific function id. See XRayPatchingStatus for possible104/// result values.105extern XRayPatchingStatus __xray_patch_function(int32_t FuncId);106107/// This unpatches a specific function id. See XRayPatchingStatus for possible108/// result values.109extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);110111/// This function returns the address of the function provided a valid function112/// id. We return 0 if we encounter any error, even if 0 may be a valid function113/// address.114extern uintptr_t __xray_function_address(int32_t FuncId);115116/// This function returns the maximum valid function id. Returns 0 if we117/// encounter errors (when there are no instrumented functions, etc.).118extern size_t __xray_max_function_id();119120/// Initialize the required XRay data structures. This is useful in cases where121/// users want to control precisely when the XRay instrumentation data122/// structures are initialized, for example when the XRay library is built with123/// the XRAY_NO_PREINIT preprocessor definition.124///125/// Calling __xray_init() more than once is safe across multiple threads.126extern void __xray_init();127128} // end extern "C"129130#endif // XRAY_XRAY_INTERFACE_H131132133