bpf-script-test-prologue.c 1.1 KB

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