blob: 8b811c29dc7996272c987a3f7a76ddaeff009aaf [file] [log] [blame]
Alexei Starovoitove3edfde2016-04-06 18:43:31 -07001/* 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 <linux/version.h>
8#include <linux/ptrace.h>
9#include <uapi/linux/bpf.h>
Toke Høiland-Jørgensen7cf245a2020-01-20 14:06:49 +010010#include <bpf/bpf_helpers.h>
11#include <bpf/bpf_tracing.h>
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070012
13#define _(P) ({typeof(P) val = 0; bpf_probe_read(&val, sizeof(val), &P); val;})
14
15SEC("kprobe/__set_task_comm")
16int prog(struct pt_regs *ctx)
17{
18 struct signal_struct *signal;
19 struct task_struct *tsk;
20 char oldcomm[16] = {};
21 char newcomm[16] = {};
22 u16 oom_score_adj;
23 u32 pid;
24
25 tsk = (void *)PT_REGS_PARM1(ctx);
26
27 pid = _(tsk->pid);
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);
32 return 0;
33}
34
35SEC("kprobe/urandom_read")
36int prog2(struct pt_regs *ctx)
37{
38 return 0;
39}
40
41char _license[] SEC("license") = "GPL";
42u32 _version SEC("version") = LINUX_VERSION_CODE;