Merge tag 'mips_6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux
[platform/kernel/linux-starfive.git] / samples / bpf / test_overhead_kprobe.bpf.c
1 /* Copyright (c) 2016 Facebook
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of version 2 of the GNU General Public
5  * License as published by the Free Software Foundation.
6  */
7 #include "vmlinux.h"
8 #include <linux/version.h>
9 #include <bpf/bpf_helpers.h>
10 #include <bpf/bpf_tracing.h>
11 #include <bpf/bpf_core_read.h>
12
13 SEC("kprobe/__set_task_comm")
14 int prog(struct pt_regs *ctx)
15 {
16         struct signal_struct *signal;
17         struct task_struct *tsk;
18         char oldcomm[TASK_COMM_LEN] = {};
19         char newcomm[TASK_COMM_LEN] = {};
20         u16 oom_score_adj;
21         u32 pid;
22
23         tsk = (void *)PT_REGS_PARM1_CORE(ctx);
24
25         pid = BPF_CORE_READ(tsk, pid);
26         bpf_core_read_str(oldcomm, sizeof(oldcomm), &tsk->comm);
27         bpf_core_read_str(newcomm, sizeof(newcomm),
28                                   (void *)PT_REGS_PARM2(ctx));
29         signal = BPF_CORE_READ(tsk, signal);
30         oom_score_adj = BPF_CORE_READ(signal, oom_score_adj);
31         return 0;
32 }
33
34 SEC("kprobe/fib_table_lookup")
35 int prog2(struct pt_regs *ctx)
36 {
37         return 0;
38 }
39
40 char _license[] SEC("license") = "GPL";
41 u32 _version SEC("version") = LINUX_VERSION_CODE;