Back to home page

OSCL-LXR

 
 

    


0001 /* Copyright (c) 2016 Facebook
0002  *
0003  * This program is free software; you can redistribute it and/or
0004  * modify it under the terms of version 2 of the GNU General Public
0005  * License as published by the Free Software Foundation.
0006  */
0007 #include <linux/version.h>
0008 #include <linux/ptrace.h>
0009 #include <linux/sched.h>
0010 #include <uapi/linux/bpf.h>
0011 #include <bpf/bpf_helpers.h>
0012 #include <bpf/bpf_tracing.h>
0013 
0014 #define _(P)                                                                   \
0015     ({                                                                     \
0016         typeof(P) val = 0;                                             \
0017         bpf_probe_read_kernel(&val, sizeof(val), &(P));                \
0018         val;                                                           \
0019     })
0020 
0021 SEC("kprobe/__set_task_comm")
0022 int prog(struct pt_regs *ctx)
0023 {
0024     struct signal_struct *signal;
0025     struct task_struct *tsk;
0026     char oldcomm[TASK_COMM_LEN] = {};
0027     char newcomm[TASK_COMM_LEN] = {};
0028     u16 oom_score_adj;
0029     u32 pid;
0030 
0031     tsk = (void *)PT_REGS_PARM1(ctx);
0032 
0033     pid = _(tsk->pid);
0034     bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm);
0035     bpf_probe_read_kernel_str(newcomm, sizeof(newcomm),
0036                   (void *)PT_REGS_PARM2(ctx));
0037     signal = _(tsk->signal);
0038     oom_score_adj = _(signal->oom_score_adj);
0039     return 0;
0040 }
0041 
0042 SEC("kprobe/urandom_read")
0043 int prog2(struct pt_regs *ctx)
0044 {
0045     return 0;
0046 }
0047 
0048 char _license[] SEC("license") = "GPL";
0049 u32 _version SEC("version") = LINUX_VERSION_CODE;