1 /* Copyright (c) 2016 Facebook
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.
7 #include <linux/version.h>
8 #include <linux/ptrace.h>
9 #include <uapi/linux/bpf.h>
10 #include <bpf/bpf_helpers.h>
11 #include <bpf/bpf_tracing.h>
13 #define _(P) ({typeof(P) val = 0; bpf_probe_read(&val, sizeof(val), &P); val;})
15 SEC("kprobe/__set_task_comm")
16 int prog(struct pt_regs
*ctx
)
18 struct signal_struct
*signal
;
19 struct task_struct
*tsk
;
20 char oldcomm
[16] = {};
21 char newcomm
[16] = {};
25 tsk
= (void *)PT_REGS_PARM1(ctx
);
28 bpf_probe_read(oldcomm
, sizeof(oldcomm
), &tsk
->comm
);
29 bpf_probe_read(newcomm
, sizeof(newcomm
), (void *)PT_REGS_PARM2(ctx
));
30 signal
= _(tsk
->signal
);
31 oom_score_adj
= _(signal
->oom_score_adj
);
35 SEC("kprobe/urandom_read")
36 int prog2(struct pt_regs
*ctx
)
41 char _license
[] SEC("license") = "GPL";
42 u32 _version
SEC("version") = LINUX_VERSION_CODE
;