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_nesting_substruct {
17 	int a;
18 };
19 
20 union core_reloc_nesting_subunion {
21 	int b;
22 };
23 
24 /* int a.a.a and b.b.b accesses */
25 struct core_reloc_nesting {
26 	union {
27 		struct core_reloc_nesting_substruct a;
28 	} a;
29 	struct {
30 		union core_reloc_nesting_subunion b;
31 	} b;
32 };
33 
34 #define CORE_READ(dst, src) bpf_core_read(dst, sizeof(*(dst)), src)
35 
36 SEC("raw_tracepoint/sys_enter")
37 int test_core_nesting(void *ctx)
38 {
39 	struct core_reloc_nesting *in = (void *)&data.in;
40 	struct core_reloc_nesting *out = (void *)&data.out;
41 
42 	if (CORE_READ(&out->a.a.a, &in->a.a.a))
43 		return 1;
44 	if (CORE_READ(&out->b.b.b, &in->b.b.b))
45 		return 1;
46 
47 	return 0;
48 }
49 
50