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 #include "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 char b123; 19 int c1c; 20 int d00d; 21 }; 22 23 struct core_reloc_arrays_substruct { 24 int c; 25 int d; 26 }; 27 28 struct core_reloc_arrays { 29 int a[5]; 30 char b[2][3][4]; 31 struct core_reloc_arrays_substruct c[3]; 32 struct core_reloc_arrays_substruct d[1][2]; 33 }; 34 35 #define CORE_READ(dst, src) bpf_core_read(dst, sizeof(*(dst)), src) 36 37 SEC("raw_tracepoint/sys_enter") 38 int test_core_arrays(void *ctx) 39 { 40 struct core_reloc_arrays *in = (void *)&data.in; 41 struct core_reloc_arrays_output *out = (void *)&data.out; 42 43 /* in->a[2] */ 44 if (CORE_READ(&out->a2, &in->a[2])) 45 return 1; 46 /* in->b[1][2][3] */ 47 if (CORE_READ(&out->b123, &in->b[1][2][3])) 48 return 1; 49 /* in->c[1].c */ 50 if (CORE_READ(&out->c1c, &in->c[1].c)) 51 return 1; 52 /* in->d[0][0].d */ 53 if (CORE_READ(&out->d00d, &in->d[0][0].d)) 54 return 1; 55 56 return 0; 57 } 58 59