github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/testdata/errors.c (about)

     1  #include "common.h"
     2  #include "../btf/testdata/bpf_core_read.h"
     3  
     4  struct nonexist {
     5  	int non_exist;
     6  };
     7  
     8  enum nonexist_enum { NON_EXIST = 1 };
     9  
    10  __section("socket") int poisoned_single() {
    11  	struct nonexist ne;
    12  	return core_access(ne.non_exist);
    13  }
    14  
    15  __section("socket") int poisoned_double() {
    16  	return bpf_core_enum_value(enum nonexist_enum, NON_EXIST);
    17  }
    18  
    19  extern int invalid_kfunc(void) __ksym __weak;
    20  
    21  __section("socket") int poisoned_kfunc() {
    22  	// NB: This doesn't go via CO-RE but uses a similar mechanism to generate
    23  	// an invalid instruction. We test it here for convenience.
    24  	return invalid_kfunc();
    25  }