1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_core_read.h>
8 struct task_struct___bad {
11 void *fake_field_subprog;
12 } __attribute__((preserve_access_index));
14 SEC("?raw_tp/sys_enter")
15 int bad_relo(const void *ctx)
17 static struct task_struct___bad *t;
19 return bpf_core_field_size(t->fake_field);
22 static __noinline int bad_subprog(void)
24 static struct task_struct___bad *t;
26 /* ugliness below is a field offset relocation */
27 return (void *)&t->fake_field_subprog - (void *)t;
30 SEC("?raw_tp/sys_enter")
31 int bad_relo_subprog(const void *ctx)
33 static struct task_struct___bad *t;
35 return bad_subprog() + bpf_core_field_size(t->pid);
39 __uint(type, BPF_MAP_TYPE_ARRAY);
40 __uint(max_entries, 1);
43 } existing_map SEC(".maps");
46 __uint(type, BPF_MAP_TYPE_ARRAY);
47 __uint(max_entries, 1);
50 } missing_map SEC(".maps");
52 SEC("?raw_tp/sys_enter")
53 int use_missing_map(const void *ctx)
57 value = bpf_map_lookup_elem(&existing_map, &zero);
59 value = bpf_map_lookup_elem(&missing_map, &zero);
64 extern int bpf_nonexistent_kfunc(void) __ksym __weak;
66 SEC("?raw_tp/sys_enter")
67 int use_missing_kfunc(const void *ctx)
69 bpf_nonexistent_kfunc();
74 char _license[] SEC("license") = "GPL";