brintos

brintos / linux-shallow public Read only

0
0
Text · 3.3 KiB · cc1a012 Raw
143 lines · c
1// SPDX-License-Identifier: GPL-2.02/* 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 30int raw_tp_writable_bare_in_val = 0;31int raw_tp_writable_bare_early_ret = 0;32int raw_tp_writable_bare_out_val = 0;33 34SEC("raw_tp.w/bpf_testmod_test_writable_bare")35int BPF_PROG(handle_raw_tp_writable_bare,36	     struct bpf_testmod_test_writable_ctx *writable)37{38	raw_tp_writable_bare_in_val = writable->val;39	writable->early_ret = raw_tp_writable_bare_early_ret;40	writable->val = raw_tp_writable_bare_out_val;41	return 0;42}43 44__u32 tp_btf_read_sz = 0;45 46SEC("tp_btf/bpf_testmod_test_read")47int BPF_PROG(handle_tp_btf,48	     struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)49{50	tp_btf_read_sz = read_ctx->len;51	return 0;52}53 54__u32 fentry_read_sz = 0;55 56SEC("fentry/bpf_testmod_test_read")57int BPF_PROG(handle_fentry,58	     struct file *file, struct kobject *kobj,59	     struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)60{61	fentry_read_sz = len;62	return 0;63}64 65__u32 fentry_manual_read_sz = 0;66 67SEC("fentry")68int BPF_PROG(handle_fentry_manual,69	     struct file *file, struct kobject *kobj,70	     struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)71{72	fentry_manual_read_sz = len;73	return 0;74}75 76__u32 fentry_explicit_read_sz = 0;77 78SEC("fentry/bpf_testmod:bpf_testmod_test_read")79int BPF_PROG(handle_fentry_explicit,80	     struct file *file, struct kobject *kobj,81	     struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)82{83	fentry_explicit_read_sz = len;84	return 0;85}86 87 88__u32 fentry_explicit_manual_read_sz = 0;89 90SEC("fentry")91int BPF_PROG(handle_fentry_explicit_manual,92	     struct file *file, struct kobject *kobj,93	     struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)94{95	fentry_explicit_manual_read_sz = len;96	return 0;97}98 99__u32 fexit_read_sz = 0;100int fexit_ret = 0;101 102SEC("fexit/bpf_testmod_test_read")103int BPF_PROG(handle_fexit,104	     struct file *file, struct kobject *kobj,105	     struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len,106	     int ret)107{108	fexit_read_sz = len;109	fexit_ret = ret;110	return 0;111}112 113SEC("fexit/bpf_testmod_return_ptr")114int BPF_PROG(handle_fexit_ret, int arg, struct file *ret)115{116	long buf = 0;117 118	bpf_probe_read_kernel(&buf, 8, ret);119	bpf_probe_read_kernel(&buf, 8, (char *)ret + 256);120	*(volatile long long *)ret;121	*(volatile int *)&ret->f_mode;122	return 0;123}124 125__u32 fmod_ret_read_sz = 0;126 127SEC("fmod_ret/bpf_testmod_test_read")128int BPF_PROG(handle_fmod_ret,129	     struct file *file, struct kobject *kobj,130	     struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)131{132	fmod_ret_read_sz = len;133	return 0; /* don't override the exit code */134}135 136SEC("kprobe.multi/bpf_testmod_test_read")137int BPF_PROG(kprobe_multi)138{139	return 0;140}141 142char _license[] SEC("license") = "GPL";143