18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * bpf-script-test-prologue.c 48c2ecf20Sopenharmony_ci * Test BPF prologue 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef LINUX_VERSION_CODE 78c2ecf20Sopenharmony_ci# error Need LINUX_VERSION_CODE 88c2ecf20Sopenharmony_ci# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' 98c2ecf20Sopenharmony_ci#endif 108c2ecf20Sopenharmony_ci#define SEC(NAME) __attribute__((section(NAME), used)) 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <uapi/linux/fs.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* 158c2ecf20Sopenharmony_ci * If CONFIG_PROFILE_ALL_BRANCHES is selected, 168c2ecf20Sopenharmony_ci * 'if' is redefined after include kernel header. 178c2ecf20Sopenharmony_ci * Recover 'if' for BPF object code. 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci#ifdef if 208c2ecf20Sopenharmony_ci# undef if 218c2ecf20Sopenharmony_ci#endif 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define FMODE_READ 0x1 248c2ecf20Sopenharmony_ci#define FMODE_WRITE 0x2 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic void (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) = 278c2ecf20Sopenharmony_ci (void *) 6; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciSEC("func=null_lseek file->f_mode offset orig") 308c2ecf20Sopenharmony_ciint bpf_func__null_lseek(void *ctx, int err, unsigned long _f_mode, 318c2ecf20Sopenharmony_ci unsigned long offset, unsigned long orig) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci fmode_t f_mode = (fmode_t)_f_mode; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci if (err) 368c2ecf20Sopenharmony_ci return 0; 378c2ecf20Sopenharmony_ci if (f_mode & FMODE_WRITE) 388c2ecf20Sopenharmony_ci return 0; 398c2ecf20Sopenharmony_ci if (offset & 1) 408c2ecf20Sopenharmony_ci return 0; 418c2ecf20Sopenharmony_ci if (orig == SEEK_CUR) 428c2ecf20Sopenharmony_ci return 0; 438c2ecf20Sopenharmony_ci return 1; 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cichar _license[] SEC("license") = "GPL"; 478c2ecf20Sopenharmony_ciint _version SEC("version") = LINUX_VERSION_CODE; 48