1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2019 Facebook 3 4 #include <linux/bpf.h> 5 #include <stdint.h> 6 #include "bpf_helpers.h" 7 8 char _license[] SEC("license") = "GPL"; 9 10 static volatile struct data { 11 char in[256]; 12 char out[256]; 13 } data; 14 15 struct core_reloc_flavors { 16 int a; 17 int b; 18 int c; 19 }; 20 21 /* local flavor with reversed layout */ 22 struct core_reloc_flavors___reversed { 23 int c; 24 int b; 25 int a; 26 }; 27 28 /* local flavor with nested/overlapping layout */ 29 struct core_reloc_flavors___weird { 30 struct { 31 int b; 32 }; 33 /* a and c overlap in local flavor, but this should still work 34 * correctly with target original flavor 35 */ 36 union { 37 int a; 38 int c; 39 }; 40 }; 41 42 SEC("raw_tracepoint/sys_enter") 43 int test_core_flavors(void *ctx) 44 { 45 struct core_reloc_flavors *in_orig = (void *)&data.in; 46 struct core_reloc_flavors___reversed *in_rev = (void *)&data.in; 47 struct core_reloc_flavors___weird *in_weird = (void *)&data.in; 48 struct core_reloc_flavors *out = (void *)&data.out; 49 50 /* read a using weird layout */ 51 if (BPF_CORE_READ(&out->a, &in_weird->a)) 52 return 1; 53 /* read b using reversed layout */ 54 if (BPF_CORE_READ(&out->b, &in_rev->b)) 55 return 1; 56 /* read c using original layout */ 57 if (BPF_CORE_READ(&out->c, &in_orig->c)) 58 return 1; 59 60 return 0; 61 } 62 63