github.com/castai/kvisor@v1.7.1-0.20240516114728-b3572a2607b5/pkg/ebpftracer/c/headers/common/probes.h (about)

     1  #ifndef __COMMON_PROBES_H__
     2  #define __COMMON_PROBES_H__
     3  
     4  #include <vmlinux.h>
     5  
     6  #include <bpf/bpf_tracing.h>
     7  
     8  #include <common/arguments.h>
     9  #include <common/buffer.h>
    10  #include <common/context.h>
    11  #include <common/filtering.h>
    12  
    13  #define TRACE_ENT_FUNC(name, id)                                                                   \
    14      int trace_##name(struct pt_regs *ctx)                                                          \
    15      {                                                                                              \
    16          args_t args = {};                                                                          \
    17          args.args[0] = PT_REGS_PARM1(ctx);                                                         \
    18          args.args[1] = PT_REGS_PARM2(ctx);                                                         \
    19          args.args[2] = PT_REGS_PARM3(ctx);                                                         \
    20          args.args[3] = PT_REGS_PARM4(ctx);                                                         \
    21          args.args[4] = PT_REGS_PARM5(ctx);                                                         \
    22          args.args[5] = PT_REGS_PARM6(ctx);                                                         \
    23                                                                                                     \
    24          return save_args(&args, id);                                                               \
    25      }
    26  
    27  #define TRACE_RET_FUNC(name, id, ret)                                                              \
    28      int trace_ret_##name(void *ctx)                                                                \
    29      {                                                                                              \
    30          args_t args = {};                                                                          \
    31          if (load_args(&args, id) != 0)                                                             \
    32              return -1;                                                                             \
    33          del_args(id);                                                                              \
    34                                                                                                     \
    35          program_data_t p = {};                                                                     \
    36          if (!init_program_data(&p, ctx))                                                           \
    37              return 0;                                                                              \
    38                                                                                                     \
    39          if (!should_trace(&p))                                                                     \
    40              return 0;                                                                              \
    41                                                                                                     \
    42          if (!should_submit(id, p.event))                                                           \
    43              return 0;                                                                              \
    44                                                                                                     \
    45          save_args_to_submit_buf(p.event, &args);                                                   \
    46                                                                                                     \
    47          return events_perf_submit(&p, id, ret);                                                    \
    48      }
    49  
    50  #endif