1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
7 #include <bpf/bpf_helpers.h>
8 #include <bpf/bpf_core_read.h>
10 char _license[] SEC("license") = "GPL";
27 typedef struct a_struct named_struct_typedef;
29 typedef struct { int x, y, z; } anon_struct_typedef;
33 } *struct_ptr_typedef;
41 typedef int int_typedef;
43 typedef enum { TYPEDEF_ENUM_VAL1, TYPEDEF_ENUM_VAL2 } enum_typedef;
45 typedef void *void_ptr_typedef;
47 typedef int (*func_proto_typedef)(long);
49 typedef char arr_typedef[20];
51 struct core_reloc_type_based_output {
55 bool typedef_named_struct_exists;
56 bool typedef_anon_struct_exists;
57 bool typedef_struct_ptr_exists;
58 bool typedef_int_exists;
59 bool typedef_enum_exists;
60 bool typedef_void_ptr_exists;
61 bool typedef_func_proto_exists;
62 bool typedef_arr_exists;
67 int typedef_named_struct_sz;
68 int typedef_anon_struct_sz;
69 int typedef_struct_ptr_sz;
72 int typedef_void_ptr_sz;
73 int typedef_func_proto_sz;
77 SEC("raw_tracepoint/sys_enter")
78 int test_core_type_based(void *ctx)
80 #if __has_builtin(__builtin_preserve_type_info)
81 struct core_reloc_type_based_output *out = (void *)&data.out;
83 out->struct_exists = bpf_core_type_exists(struct a_struct);
84 out->union_exists = bpf_core_type_exists(union a_union);
85 out->enum_exists = bpf_core_type_exists(enum an_enum);
86 out->typedef_named_struct_exists = bpf_core_type_exists(named_struct_typedef);
87 out->typedef_anon_struct_exists = bpf_core_type_exists(anon_struct_typedef);
88 out->typedef_struct_ptr_exists = bpf_core_type_exists(struct_ptr_typedef);
89 out->typedef_int_exists = bpf_core_type_exists(int_typedef);
90 out->typedef_enum_exists = bpf_core_type_exists(enum_typedef);
91 out->typedef_void_ptr_exists = bpf_core_type_exists(void_ptr_typedef);
92 out->typedef_func_proto_exists = bpf_core_type_exists(func_proto_typedef);
93 out->typedef_arr_exists = bpf_core_type_exists(arr_typedef);
95 out->struct_sz = bpf_core_type_size(struct a_struct);
96 out->union_sz = bpf_core_type_size(union a_union);
97 out->enum_sz = bpf_core_type_size(enum an_enum);
98 out->typedef_named_struct_sz = bpf_core_type_size(named_struct_typedef);
99 out->typedef_anon_struct_sz = bpf_core_type_size(anon_struct_typedef);
100 out->typedef_struct_ptr_sz = bpf_core_type_size(struct_ptr_typedef);
101 out->typedef_int_sz = bpf_core_type_size(int_typedef);
102 out->typedef_enum_sz = bpf_core_type_size(enum_typedef);
103 out->typedef_void_ptr_sz = bpf_core_type_size(void_ptr_typedef);
104 out->typedef_func_proto_sz = bpf_core_type_size(func_proto_typedef);
105 out->typedef_arr_sz = bpf_core_type_size(arr_typedef);