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