test_overhead_kprobe.bpf.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. SEC("kprobe/__set_task_comm")
  13. int prog(struct pt_regs *ctx)
  14. {
  15. struct signal_struct *signal;
  16. struct task_struct *tsk;
  17. char oldcomm[TASK_COMM_LEN] = {};
  18. char newcomm[TASK_COMM_LEN] = {};
  19. u16 oom_score_adj;
  20. u32 pid;
  21. tsk = (void *)PT_REGS_PARM1_CORE(ctx);
  22. pid = BPF_CORE_READ(tsk, pid);
  23. bpf_core_read_str(oldcomm, sizeof(oldcomm), &tsk->comm);
  24. bpf_core_read_str(newcomm, sizeof(newcomm),
  25. (void *)PT_REGS_PARM2(ctx));
  26. signal = BPF_CORE_READ(tsk, signal);
  27. oom_score_adj = BPF_CORE_READ(signal, oom_score_adj);
  28. return 0;
  29. }
  30. SEC("kprobe/fib_table_lookup")
  31. int prog2(struct pt_regs *ctx)
  32. {
  33. return 0;
  34. }
  35. char _license[] SEC("license") = "GPL";
  36. u32 _version SEC("version") = LINUX_VERSION_CODE;