Debian Codegraph @

gcc/testsuite/gcc.target/bpf/core-support.h

raw
1 struct my_struct {
2 int a;
3 };
4
5 union my_union {
6 int b;
7 int c;
8 };
9
10 typedef struct my_struct named_struct_tdef;
11 typedef int (*func_tdef)(void *);
12
13 typedef struct {
14 int d, e;
15 } *tdef_struct_ptr;
16
17 enum my_enum {
18 MY_ENUM_VAL1 = 1,
19 MY_ENUM_VAL2 = 2,
20 };
21 typedef enum { TE1, TE2, TE3 } enum_tdef;
22
23 typedef int int_tdef;
24 typedef void *void_ptr_tdef;
25 typedef int *restrict restrict_ptr_tdef;
26 typedef int (*func_tdef)(void *);
27 typedef char array_tdef[10];
28
29 struct my_complex_struct {
30 int a;
31 int b;
32 union {
33 int *a;
34 struct my_struct *s;
35 } c;
36 };
37
38 typedef struct {
39 int a;
40 } anon_struct_tdef;
41
42 typedef struct my_struct *struct_ptr_tdef;
43
44 enum named_ue64 {
45 UE64_VAL1 = 0x1ffffffffULL,
46 UE64_VAL2 = 0x01fffffffULL,
47 UE64_VAL3 = 0x001ffffffULL,
48 };
49
50 enum named_se64 {
51 SE64_VAL1 = 0x1ffffffffLL,
52 SE64_VAL2 = 0x01fffffffLL,
53 SE64_VAL3 = -1,
54 };
55
56 enum named_ue {
57 UE_VAL1 = 0x1ffffff,
58 UE_VAL2 = 0x01fffff,
59 UE_VAL3 = 0x001ffff,
60 };
61
62 enum named_se {
63 SE_VAL1 = 0x1fffffff,
64 SE_VAL2 = 0x01ffffff,
65 SE_VAL3 = -1,
66 };
67
68
69 /* BPF specific code */
70
71 enum bpf_type_id_kind {
72 BPF_TYPE_ID_LOCAL = 0,
73 BPF_TYPE_ID_TARGET = 1,
74 };
75
76 enum bpf_type_info_kind {
77 BPF_TYPE_EXISTS = 0,
78 BPF_TYPE_SIZE = 1,
79 BPF_TYPE_MATCHES = 2,
80 };
81
82 enum bpf_enum_value_kind {
83 BPF_ENUMVAL_EXISTS = 0,
84 BPF_ENUMVAL_VALUE = 1,
85 };
86
87 #define COMPOSE_VAR(t,s) t##s
88 #define bpf_type1(type, NR) ({ \
89 extern typeof(type) *COMPOSE_VAR(bpf_type_tmp_, NR); \
90 COMPOSE_VAR(bpf_type_tmp_, NR); \
91 })
92 #define bpf_type(type) bpf_type1(type, __COUNTER__)
93
94 #define bpf_core_type_id_local(type) \
95 __builtin_btf_type_id(*bpf_type(type), BPF_TYPE_ID_LOCAL)
96 #define bpf_core_type_id_target(type) \
97 __builtin_btf_type_id(*bpf_type(type), BPF_TYPE_ID_TARGET)
98
99 #define bpf_core_type_exists(type) \
100 __builtin_preserve_type_info(*bpf_type(type), BPF_TYPE_EXISTS)
101 #define bpf_core_type_matches(type) \
102 __builtin_preserve_type_info(*bpf_type(type), BPF_TYPE_MATCHES)
103 #define bpf_core_type_size(type) \
104 __builtin_preserve_type_info(*bpf_type(type), BPF_TYPE_SIZE)
105
106 #define bpf_core_enum_value_exists(enum_type, enum_value) \
107 __builtin_preserve_enum_value(bpf_type(enum_type), enum_value, BPF_ENUMVAL_EXISTS)
108 #define bpf_core_enum_value(enum_type, enum_value) \
109 __builtin_preserve_enum_value(bpf_type(enum_type), enum_value, BPF_ENUMVAL_VALUE)