0001
0002
0003
0004
0005
0006 #ifndef LINUX_VERSION_CODE
0007 # error Need LINUX_VERSION_CODE
0008 # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
0009 #endif
0010 #define SEC(NAME) __attribute__((section(NAME), used))
0011
0012 #include <uapi/linux/fs.h>
0013
0014
0015
0016
0017
0018
0019 #ifdef if
0020 # undef if
0021 #endif
0022
0023 #define FMODE_READ 0x1
0024 #define FMODE_WRITE 0x2
0025
0026 static void (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
0027 (void *) 6;
0028
0029 SEC("func=null_lseek file->f_mode offset orig")
0030 int bpf_func__null_lseek(void *ctx, int err, unsigned long _f_mode,
0031 unsigned long offset, unsigned long orig)
0032 {
0033 fmode_t f_mode = (fmode_t)_f_mode;
0034
0035 if (err)
0036 return 0;
0037 if (f_mode & FMODE_WRITE)
0038 return 0;
0039 if (offset & 1)
0040 return 0;
0041 if (orig == SEEK_CUR)
0042 return 0;
0043 return 1;
0044 }
0045
0046 char _license[] SEC("license") = "GPL";
0047 int _version SEC("version") = LINUX_VERSION_CODE;