linux/tools/testing/selftests/bpf/progs/test_module_attach.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright (c) 2020 Facebook */
   3
   4#include "vmlinux.h"
   5#include <bpf/bpf_helpers.h>
   6#include <bpf/bpf_tracing.h>
   7#include <bpf/bpf_core_read.h>
   8#include "../bpf_testmod/bpf_testmod.h"
   9
  10__u32 raw_tp_read_sz = 0;
  11
  12SEC("raw_tp/bpf_testmod_test_read")
  13int BPF_PROG(handle_raw_tp,
  14             struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
  15{
  16        raw_tp_read_sz = BPF_CORE_READ(read_ctx, len);
  17        return 0;
  18}
  19
  20__u32 raw_tp_bare_write_sz = 0;
  21
  22SEC("raw_tp/bpf_testmod_test_write_bare")
  23int BPF_PROG(handle_raw_tp_bare,
  24             struct task_struct *task, struct bpf_testmod_test_write_ctx *write_ctx)
  25{
  26        raw_tp_bare_write_sz = BPF_CORE_READ(write_ctx, len);
  27        return 0;
  28}
  29
  30__u32 tp_btf_read_sz = 0;
  31
  32SEC("tp_btf/bpf_testmod_test_read")
  33int BPF_PROG(handle_tp_btf,
  34             struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
  35{
  36        tp_btf_read_sz = read_ctx->len;
  37        return 0;
  38}
  39
  40__u32 fentry_read_sz = 0;
  41
  42SEC("fentry/bpf_testmod_test_read")
  43int BPF_PROG(handle_fentry,
  44             struct file *file, struct kobject *kobj,
  45             struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
  46{
  47        fentry_read_sz = len;
  48        return 0;
  49}
  50
  51__u32 fentry_manual_read_sz = 0;
  52
  53SEC("fentry/placeholder")
  54int BPF_PROG(handle_fentry_manual,
  55             struct file *file, struct kobject *kobj,
  56             struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
  57{
  58        fentry_manual_read_sz = len;
  59        return 0;
  60}
  61
  62__u32 fexit_read_sz = 0;
  63int fexit_ret = 0;
  64
  65SEC("fexit/bpf_testmod_test_read")
  66int BPF_PROG(handle_fexit,
  67             struct file *file, struct kobject *kobj,
  68             struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len,
  69             int ret)
  70{
  71        fexit_read_sz = len;
  72        fexit_ret = ret;
  73        return 0;
  74}
  75
  76__u32 fmod_ret_read_sz = 0;
  77
  78SEC("fmod_ret/bpf_testmod_test_read")
  79int BPF_PROG(handle_fmod_ret,
  80             struct file *file, struct kobject *kobj,
  81             struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
  82{
  83        fmod_ret_read_sz = len;
  84        return 0; /* don't override the exit code */
  85}
  86
  87char _license[] SEC("license") = "GPL";
  88