1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
6 #include <linux/types.h> /* for u32 */
22 #ifdef CONFIG_DEBUG_INFO_BTF
24 #include <linux/compiler.h> /* for __PASTE */
27 * Following macros help to define lists of BTF IDs placed
28 * in .BTF_ids section. They are initially filled with zeros
29 * (during compilation) and resolved later during the
30 * linking phase by resolve_btfids tool.
32 * Any change in list layout must be reflected in resolve_btfids
36 #define BTF_IDS_SECTION ".BTF_ids"
38 #define ____BTF_ID(symbol) \
40 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
41 ".local " #symbol " ; \n" \
42 ".type " #symbol ", STT_OBJECT; \n" \
43 ".size " #symbol ", 4; \n" \
48 #define __BTF_ID(symbol) \
51 #define __ID(prefix) \
52 __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
55 * The BTF_ID defines unique symbol for each ID pointing
58 #define BTF_ID(prefix, name) \
59 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
62 * The BTF_ID_LIST macro defines pure (unsorted) list
63 * of BTF IDs, with following layout:
66 * BTF_ID(type1, name1)
67 * BTF_ID(type2, name2)
70 * __BTF_ID__type1__name1__1:
72 * __BTF_ID__type2__name2__2:
76 #define __BTF_ID_LIST(name, scope) \
78 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
79 "." #scope " " #name "; \n" \
83 #define BTF_ID_LIST(name) \
84 __BTF_ID_LIST(name, local) \
87 #define BTF_ID_LIST_GLOBAL(name, n) \
88 __BTF_ID_LIST(name, globl)
90 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
93 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \
95 BTF_ID(prefix, typename)
96 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
97 BTF_ID_LIST_GLOBAL(name, 1) \
98 BTF_ID(prefix, typename)
101 * The BTF_ID_UNUSED macro defines 4 zero bytes.
102 * It's used when we want to define 'unused' entry
103 * in BTF_ID_LIST, like:
105 * BTF_ID_LIST(bpf_skb_output_btf_ids)
106 * BTF_ID(struct, sk_buff)
108 * BTF_ID(struct, task_struct)
111 #define BTF_ID_UNUSED \
113 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
118 * The BTF_SET_START/END macros pair defines sorted list of
119 * BTF IDs plus its members count, with following layout:
121 * BTF_SET_START(list)
122 * BTF_ID(type1, name1)
123 * BTF_ID(type2, name2)
126 * __BTF_ID__set__list:
129 * __BTF_ID__type1__name1__3:
131 * __BTF_ID__type2__name2__4:
135 #define __BTF_SET_START(name, scope) \
137 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
138 "." #scope " __BTF_ID__set__" #name "; \n" \
139 "__BTF_ID__set__" #name ":; \n" \
143 #define BTF_SET_START(name) \
144 __BTF_ID_LIST(name, local) \
145 __BTF_SET_START(name, local)
147 #define BTF_SET_START_GLOBAL(name) \
148 __BTF_ID_LIST(name, globl) \
149 __BTF_SET_START(name, globl)
151 #define BTF_SET_END(name) \
153 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
154 ".size __BTF_ID__set__" #name ", .-" #name " \n" \
155 ".popsection; \n"); \
156 extern struct btf_id_set name;
160 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
161 #define BTF_ID(prefix, name)
162 #define BTF_ID_UNUSED
163 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
164 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
165 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
166 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
167 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
168 #define BTF_SET_END(name)
170 #endif /* CONFIG_DEBUG_INFO_BTF */
173 /* Define a list of socket types which can be the argument for
174 * skc_to_*_sock() helpers. All these sockets should have
175 * sock_common as the first argument in its memory layout.
177 #define BTF_SOCK_TYPE_xxx \
178 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
179 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
180 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
181 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
182 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
183 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
184 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
185 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
186 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
187 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
188 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
189 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
190 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
191 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
192 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
193 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
196 #define BTF_SOCK_TYPE(name, str) name,
202 extern u32 btf_sock_ids
[];
205 #define BTF_TRACING_TYPE_xxx \
206 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
207 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
208 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
211 #define BTF_TRACING_TYPE(name, type) name,
213 #undef BTF_TRACING_TYPE
214 MAX_BTF_TRACING_TYPE
,
217 extern u32 btf_tracing_ids
[];