linux/kernel/trace/trace_probe.h

// SPDX-License-Identifier: GPL-2.0
/*
 * Common header file for probe-based Dynamic events.
 *
 * This code was copied from kernel/trace/trace_kprobe.h written by
 * Masami Hiramatsu <[email protected]>
 *
 * Updates to make this generic:
 * Copyright (C) IBM Corporation, 2010-2011
 * Author:     Srikar Dronamraju
 */

#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/smp.h>
#include <linux/tracefs.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ptrace.h>
#include <linux/perf_event.h>
#include <linux/kprobes.h>
#include <linux/stringify.h>
#include <linux/limits.h>
#include <linux/uaccess.h>
#include <linux/bitops.h>
#include <linux/btf.h>
#include <asm/bitsperlong.h>

#include "trace.h"
#include "trace_output.h"

#define MAX_TRACE_ARGS
#define MAX_ARGSTR_LEN
#define MAX_ARRAY_LEN
#define MAX_ARG_NAME_LEN
#define MAX_BTF_ARGS_LEN
#define MAX_DENTRY_ARGS_LEN
#define MAX_STRING_SIZE
#define MAX_ARG_BUF_LEN

/* Reserved field names */
#define FIELD_STRING_IP
#define FIELD_STRING_RETIP
#define FIELD_STRING_FUNC

#undef DEFINE_FIELD
#define DEFINE_FIELD(type, item, name, is_signed)


/* Flags for trace_probe */
#define TP_FLAG_TRACE
#define TP_FLAG_PROFILE

/* data_loc: data location, compatible with u32 */
#define make_data_loc(len, offs)
#define get_loc_len(dl)
#define get_loc_offs(dl)

static nokprobe_inline void *get_loc_data(u32 *dl, void *ent)
{}

static nokprobe_inline u32 update_data_loc(u32 loc, int consumed)
{}

/* Printing function type */
print_type_func_t;

enum fetch_op {};

struct fetch_insn {};

/* fetch + deref*N + store + mod + end <= 16, this allows N=12, enough */
#define FETCH_INSN_MAX
#define FETCH_TOKEN_COMM

/* Fetch type information table */
struct fetch_type {};

/* For defining macros, define string/string_size types */
string;
string_size;

#define PRINT_TYPE_FUNC_NAME(type)
#define PRINT_TYPE_FMT_NAME(type)

/* Printing  in basic type function template */
#define DECLARE_BASIC_PRINT_TYPE_FUNC(type)

DECLARE_BASIC_PRINT_TYPE_FUNC(u8);
DECLARE_BASIC_PRINT_TYPE_FUNC(u16);
DECLARE_BASIC_PRINT_TYPE_FUNC(u32);
DECLARE_BASIC_PRINT_TYPE_FUNC(u64);
DECLARE_BASIC_PRINT_TYPE_FUNC(s8);
DECLARE_BASIC_PRINT_TYPE_FUNC(s16);
DECLARE_BASIC_PRINT_TYPE_FUNC(s32);
DECLARE_BASIC_PRINT_TYPE_FUNC(s64);
DECLARE_BASIC_PRINT_TYPE_FUNC(x8);
DECLARE_BASIC_PRINT_TYPE_FUNC(x16);
DECLARE_BASIC_PRINT_TYPE_FUNC(x32);
DECLARE_BASIC_PRINT_TYPE_FUNC(x64);

DECLARE_BASIC_PRINT_TYPE_FUNC(char);
DECLARE_BASIC_PRINT_TYPE_FUNC(string);
DECLARE_BASIC_PRINT_TYPE_FUNC(symbol);

/* Default (unsigned long) fetch type */
#define __DEFAULT_FETCH_TYPE(t)
#define _DEFAULT_FETCH_TYPE(t)
#define DEFAULT_FETCH_TYPE
#define DEFAULT_FETCH_TYPE_STR

#define __ADDR_FETCH_TYPE(t)
#define _ADDR_FETCH_TYPE(t)
#define ADDR_FETCH_TYPE

#define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, str, _fmttype)

/* Non string types can use these macros */
#define _ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype)
#define ASSIGN_FETCH_TYPE(ptype, ftype, sign)

/* If ptype is an alias of atype, use this macro (show atype in format) */
#define ASSIGN_FETCH_TYPE_ALIAS(ptype, atype, ftype, sign)

#define ASSIGN_FETCH_TYPE_END
#define MAX_ARRAY_LEN

#ifdef CONFIG_KPROBE_EVENTS
bool trace_kprobe_on_func_entry(struct trace_event_call *call);
bool trace_kprobe_error_injectable(struct trace_event_call *call);
#else
static inline bool trace_kprobe_on_func_entry(struct trace_event_call *call)
{
	return false;
}

static inline bool trace_kprobe_error_injectable(struct trace_event_call *call)
{
	return false;
}
#endif /* CONFIG_KPROBE_EVENTS */

struct probe_arg {};

struct probe_entry_arg {};

struct trace_uprobe_filter {};

/* Event call and class holder */
struct trace_probe_event {};

struct trace_probe {};

struct event_file_link {};

static inline bool trace_probe_test_flag(struct trace_probe *tp,
					 unsigned int flag)
{}

static inline void trace_probe_set_flag(struct trace_probe *tp,
					unsigned int flag)
{}

static inline void trace_probe_clear_flag(struct trace_probe *tp,
					  unsigned int flag)
{}

static inline bool trace_probe_is_enabled(struct trace_probe *tp)
{}

static inline const char *trace_probe_name(struct trace_probe *tp)
{}

static inline const char *trace_probe_group_name(struct trace_probe *tp)
{}

static inline struct trace_event_call *
	trace_probe_event_call(struct trace_probe *tp)
{}

static inline struct trace_probe_event *
trace_probe_event_from_call(struct trace_event_call *event_call)
{}

static inline struct trace_probe *
trace_probe_primary_from_call(struct trace_event_call *call)
{}

static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)
{}

static inline bool trace_probe_has_sibling(struct trace_probe *tp)
{}

static inline int trace_probe_unregister_event_call(struct trace_probe *tp)
{}

static inline bool trace_probe_has_single_file(struct trace_probe *tp)
{}

int trace_probe_init(struct trace_probe *tp, const char *event,
		     const char *group, bool alloc_filter, int nargs);
void trace_probe_cleanup(struct trace_probe *tp);
int trace_probe_append(struct trace_probe *tp, struct trace_probe *to);
void trace_probe_unlink(struct trace_probe *tp);
int trace_probe_register_event_call(struct trace_probe *tp);
int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file);
int trace_probe_remove_file(struct trace_probe *tp,
			    struct trace_event_file *file);
struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
						struct trace_event_file *file);
int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
bool trace_probe_match_command_args(struct trace_probe *tp,
				    int argc, const char **argv);
int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **));
int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
		 u8 *data, void *field);

#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
int traceprobe_get_entry_data_size(struct trace_probe *tp);
/* This is a runtime function to store entry data */
void store_trace_entry_data(void *edata, struct trace_probe *tp, struct pt_regs *regs);
#else /* !CONFIG_HAVE_FUNCTION_ARG_ACCESS_API */
static inline int traceprobe_get_entry_data_size(struct trace_probe *tp)
{
	return 0;
}
#define store_trace_entry_data
#endif

#define trace_probe_for_each_link(pos, tp)
#define trace_probe_for_each_link_rcu(pos, tp)

/*
 * The flags used for parsing trace_probe arguments.
 * TPARG_FL_RETURN, TPARG_FL_FENTRY and TPARG_FL_TEVENT are mutually exclusive.
 * TPARG_FL_KERNEL and TPARG_FL_USER are also mutually exclusive.
 * TPARG_FL_FPROBE and TPARG_FL_TPOINT are optional but it should be with
 * TPARG_FL_KERNEL.
 */
#define TPARG_FL_RETURN
#define TPARG_FL_KERNEL
#define TPARG_FL_FENTRY
#define TPARG_FL_TEVENT
#define TPARG_FL_USER
#define TPARG_FL_FPROBE
#define TPARG_FL_TPOINT
#define TPARG_FL_LOC_MASK

static inline bool tparg_is_function_entry(unsigned int flags)
{}

static inline bool tparg_is_function_return(unsigned int flags)
{}

struct traceprobe_parse_context {};

extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i,
				      const char *argv,
				      struct traceprobe_parse_context *ctx);
const char **traceprobe_expand_meta_args(int argc, const char *argv[],
					 int *new_argc, char *buf, int bufsize,
					 struct traceprobe_parse_context *ctx);
extern int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf);

extern int traceprobe_update_arg(struct probe_arg *arg);
extern void traceprobe_free_probe_arg(struct probe_arg *arg);

/*
 * If either traceprobe_parse_probe_arg() or traceprobe_expand_meta_args() is called,
 * this MUST be called for clean up the context and return a resource.
 */
void traceprobe_finish_parse(struct traceprobe_parse_context *ctx);

extern int traceprobe_split_symbol_offset(char *symbol, long *offset);
int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
				char *buf, int offset);

enum probe_print_type {};

extern int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype);

#ifdef CONFIG_PERF_EVENTS
extern struct trace_event_call *
create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
			  bool is_return);
extern void destroy_local_trace_kprobe(struct trace_event_call *event_call);

extern struct trace_event_call *
create_local_trace_uprobe(char *name, unsigned long offs,
			  unsigned long ref_ctr_offset, bool is_return);
extern void destroy_local_trace_uprobe(struct trace_event_call *event_call);
#endif
extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
					size_t offset, struct trace_probe *tp);

#undef ERRORS
#define ERRORS

#undef C
#define C(a, b)

/* Define TP_ERR_ */
enum {};

/* Error text is defined in trace_probe.c */

struct trace_probe_log {};

void trace_probe_log_init(const char *subsystem, int argc, const char **argv);
void trace_probe_log_set_index(int index);
void trace_probe_log_clear(void);
void __trace_probe_log_err(int offset, int err);

#define trace_probe_log_err(offs, err)

struct uprobe_dispatch_data {};