cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

test_ksyms_weak.c (1303B)


      1// SPDX-License-Identifier: GPL-2.0
      2/*
      3 * Test weak ksyms.
      4 *
      5 * Copyright (c) 2021 Google
      6 */
      7
      8#include "vmlinux.h"
      9
     10#include <bpf/bpf_helpers.h>
     11
     12int out__existing_typed = -1;
     13__u64 out__existing_typeless = -1;
     14
     15__u64 out__non_existent_typeless = -1;
     16__u64 out__non_existent_typed = -1;
     17
     18/* existing weak symbols */
     19
     20/* test existing weak symbols can be resolved. */
     21extern const struct rq runqueues __ksym __weak; /* typed */
     22extern const void bpf_prog_active __ksym __weak; /* typeless */
     23
     24
     25/* non-existent weak symbols. */
     26
     27/* typeless symbols, default to zero. */
     28extern const void bpf_link_fops1 __ksym __weak;
     29
     30/* typed symbols, default to zero. */
     31extern const int bpf_link_fops2 __ksym __weak;
     32
     33SEC("raw_tp/sys_enter")
     34int pass_handler(const void *ctx)
     35{
     36	struct rq *rq;
     37
     38	/* tests existing symbols. */
     39	rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, 0);
     40	if (rq)
     41		out__existing_typed = rq->cpu;
     42	out__existing_typeless = (__u64)&bpf_prog_active;
     43
     44	/* tests non-existent symbols. */
     45	out__non_existent_typeless = (__u64)&bpf_link_fops1;
     46
     47	/* tests non-existent symbols. */
     48	out__non_existent_typed = (__u64)&bpf_link_fops2;
     49
     50	if (&bpf_link_fops2) /* can't happen */
     51		out__non_existent_typed = (__u64)bpf_per_cpu_ptr(&bpf_link_fops2, 0);
     52
     53	return 0;
     54}
     55
     56char _license[] SEC("license") = "GPL";