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/bpf_helpers.h> 7 #include <bpf/bpf_core_read.h> 8 9 char _license[] SEC("license") = "GPL"; 10 11 struct { 12 char in[256]; 13 char out[256]; 14 } data = {}; 15 16 struct core_reloc_arrays_output { 17 int a2; 18 int a3; 19 char b123; 20 int c1c; 21 int d00d; 22 int f01c; 23 }; 24 25 struct core_reloc_arrays_substruct { 26 int c; 27 int d; 28 }; 29 30 struct core_reloc_arrays { 31 int a[5]; 32 char b[2][3][4]; 33 struct core_reloc_arrays_substruct c[3]; 34 struct core_reloc_arrays_substruct d[1][2]; 35 struct core_reloc_arrays_substruct f[][2]; 36 }; 37 38 #define CORE_READ(dst, src) bpf_core_read(dst, sizeof(*(dst)), src) 39 40 SEC("raw_tracepoint/sys_enter") test_core_arrays(void * ctx)41int test_core_arrays(void *ctx) 42 { 43 struct core_reloc_arrays *in = (void *)&data.in; 44 struct core_reloc_arrays_output *out = (void *)&data.out; 45 int *a; 46 47 if (CORE_READ(&out->a2, &in->a[2])) 48 return 1; 49 if (CORE_READ(&out->b123, &in->b[1][2][3])) 50 return 1; 51 if (CORE_READ(&out->c1c, &in->c[1].c)) 52 return 1; 53 if (CORE_READ(&out->d00d, &in->d[0][0].d)) 54 return 1; 55 if (CORE_READ(&out->f01c, &in->f[0][1].c)) 56 return 1; 57 58 a = __builtin_preserve_access_index(({ in->a; })); 59 out->a3 = a[0] + a[1] + a[2] + a[3]; 60 61 return 0; 62 } 63 64