bpf-script-test-prologue.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * bpf-script-test-prologue.c
  3. * Test BPF prologue
  4. */
  5. #ifndef LINUX_VERSION_CODE
  6. # error Need LINUX_VERSION_CODE
  7. # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
  8. #endif
  9. #define SEC(NAME) __attribute__((section(NAME), used))
  10. #include <uapi/linux/fs.h>
  11. /*
  12. * If CONFIG_PROFILE_ALL_BRANCHES is selected,
  13. * 'if' is redefined after include kernel header.
  14. * Recover 'if' for BPF object code.
  15. */
  16. #ifdef if
  17. # undef if
  18. #endif
  19. #define FMODE_READ 0x1
  20. #define FMODE_WRITE 0x2
  21. static void (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
  22. (void *) 6;
  23. SEC("func=null_lseek file->f_mode offset orig")
  24. int bpf_func__null_lseek(void *ctx, int err, unsigned long _f_mode,
  25. unsigned long offset, unsigned long orig)
  26. {
  27. fmode_t f_mode = (fmode_t)_f_mode;
  28. if (err)
  29. return 0;
  30. if (f_mode & FMODE_WRITE)
  31. return 0;
  32. if (offset & 1)
  33. return 0;
  34. if (orig == SEEK_CUR)
  35. return 0;
  36. return 1;
  37. }
  38. char _license[] SEC("license") = "GPL";
  39. int _version SEC("version") = LINUX_VERSION_CODE;