Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Test weak ksyms.
0004  *
0005  * Copyright (c) 2021 Google
0006  */
0007 
0008 #include "vmlinux.h"
0009 
0010 #include <bpf/bpf_helpers.h>
0011 
0012 int out__existing_typed = -1;
0013 __u64 out__existing_typeless = -1;
0014 
0015 __u64 out__non_existent_typeless = -1;
0016 __u64 out__non_existent_typed = -1;
0017 
0018 /* existing weak symbols */
0019 
0020 /* test existing weak symbols can be resolved. */
0021 extern const struct rq runqueues __ksym __weak; /* typed */
0022 extern const void bpf_prog_active __ksym __weak; /* typeless */
0023 
0024 
0025 /* non-existent weak symbols. */
0026 
0027 /* typeless symbols, default to zero. */
0028 extern const void bpf_link_fops1 __ksym __weak;
0029 
0030 /* typed symbols, default to zero. */
0031 extern const int bpf_link_fops2 __ksym __weak;
0032 
0033 SEC("raw_tp/sys_enter")
0034 int pass_handler(const void *ctx)
0035 {
0036     struct rq *rq;
0037 
0038     /* tests existing symbols. */
0039     rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, 0);
0040     if (rq)
0041         out__existing_typed = rq->cpu;
0042     out__existing_typeless = (__u64)&bpf_prog_active;
0043 
0044     /* tests non-existent symbols. */
0045     out__non_existent_typeless = (__u64)&bpf_link_fops1;
0046 
0047     /* tests non-existent symbols. */
0048     out__non_existent_typed = (__u64)&bpf_link_fops2;
0049 
0050     if (&bpf_link_fops2) /* can't happen */
0051         out__non_existent_typed = (__u64)bpf_per_cpu_ptr(&bpf_link_fops2, 0);
0052 
0053     return 0;
0054 }
0055 
0056 char _license[] SEC("license") = "GPL";