Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2019 Facebook */
0003 
0004 #include <stdint.h>
0005 #include <stdbool.h>
0006 #include <linux/ptrace.h>
0007 #include <linux/bpf.h>
0008 #include <bpf/bpf_helpers.h>
0009 
0010 /* non-existing BPF helper, to test dead code elimination */
0011 static int (*bpf_missing_helper)(const void *arg1, int arg2) = (void *) 999;
0012 
0013 extern int LINUX_KERNEL_VERSION __kconfig;
0014 extern int LINUX_UNKNOWN_VIRTUAL_EXTERN __kconfig __weak;
0015 extern bool CONFIG_BPF_SYSCALL __kconfig; /* strong */
0016 extern enum libbpf_tristate CONFIG_TRISTATE __kconfig __weak;
0017 extern bool CONFIG_BOOL __kconfig __weak;
0018 extern char CONFIG_CHAR __kconfig __weak;
0019 extern uint16_t CONFIG_USHORT __kconfig __weak;
0020 extern int CONFIG_INT __kconfig __weak;
0021 extern uint64_t CONFIG_ULONG __kconfig __weak;
0022 extern const char CONFIG_STR[8] __kconfig __weak;
0023 extern uint64_t CONFIG_MISSING __kconfig __weak;
0024 
0025 uint64_t kern_ver = -1;
0026 uint64_t unkn_virt_val = -1;
0027 uint64_t bpf_syscall = -1;
0028 uint64_t tristate_val = -1;
0029 uint64_t bool_val = -1;
0030 uint64_t char_val = -1;
0031 uint64_t ushort_val = -1;
0032 uint64_t int_val = -1;
0033 uint64_t ulong_val = -1;
0034 char str_val[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
0035 uint64_t missing_val = -1;
0036 
0037 SEC("raw_tp/sys_enter")
0038 int handle_sys_enter(struct pt_regs *ctx)
0039 {
0040     int i;
0041 
0042     kern_ver = LINUX_KERNEL_VERSION;
0043     unkn_virt_val = LINUX_UNKNOWN_VIRTUAL_EXTERN;
0044     bpf_syscall = CONFIG_BPF_SYSCALL;
0045     tristate_val = CONFIG_TRISTATE;
0046     bool_val = CONFIG_BOOL;
0047     char_val = CONFIG_CHAR;
0048     ushort_val = CONFIG_USHORT;
0049     int_val = CONFIG_INT;
0050     ulong_val = CONFIG_ULONG;
0051 
0052     for (i = 0; i < sizeof(CONFIG_STR); i++) {
0053         str_val[i] = CONFIG_STR[i];
0054     }
0055 
0056     if (CONFIG_MISSING)
0057         /* invalid, but dead code - never executed */
0058         missing_val = bpf_missing_helper(ctx, 123);
0059     else
0060         missing_val = 0xDEADC0DE;
0061 
0062     return 0;
0063 }
0064 
0065 char _license[] SEC("license") = "GPL";