staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / bpf_helpers.h
blobf804f210244eadf0deb361879f74f6c268c1b34e
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __BPF_HELPERS_H
3 #define __BPF_HELPERS_H
5 /* helper macro to place programs, maps, license in
6 * different sections in elf_bpf file. Section names
7 * are interpreted by elf_bpf loader
8 */
9 #define SEC(NAME) __attribute__((section(NAME), used))
11 #define __uint(name, val) int (*name)[val]
12 #define __type(name, val) val *name
14 /* helper macro to print out debug messages */
15 #define bpf_printk(fmt, ...) \
16 ({ \
17 char ____fmt[] = fmt; \
18 bpf_trace_printk(____fmt, sizeof(____fmt), \
19 ##__VA_ARGS__); \
22 /* helper functions called from eBPF programs written in C */
23 static void *(*bpf_map_lookup_elem)(void *map, const void *key) =
24 (void *) BPF_FUNC_map_lookup_elem;
25 static int (*bpf_map_update_elem)(void *map, const void *key, const void *value,
26 unsigned long long flags) =
27 (void *) BPF_FUNC_map_update_elem;
28 static int (*bpf_map_delete_elem)(void *map, const void *key) =
29 (void *) BPF_FUNC_map_delete_elem;
30 static int (*bpf_map_push_elem)(void *map, const void *value,
31 unsigned long long flags) =
32 (void *) BPF_FUNC_map_push_elem;
33 static int (*bpf_map_pop_elem)(void *map, void *value) =
34 (void *) BPF_FUNC_map_pop_elem;
35 static int (*bpf_map_peek_elem)(void *map, void *value) =
36 (void *) BPF_FUNC_map_peek_elem;
37 static int (*bpf_probe_read)(void *dst, int size, const void *unsafe_ptr) =
38 (void *) BPF_FUNC_probe_read;
39 static unsigned long long (*bpf_ktime_get_ns)(void) =
40 (void *) BPF_FUNC_ktime_get_ns;
41 static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
42 (void *) BPF_FUNC_trace_printk;
43 static void (*bpf_tail_call)(void *ctx, void *map, int index) =
44 (void *) BPF_FUNC_tail_call;
45 static unsigned long long (*bpf_get_smp_processor_id)(void) =
46 (void *) BPF_FUNC_get_smp_processor_id;
47 static unsigned long long (*bpf_get_current_pid_tgid)(void) =
48 (void *) BPF_FUNC_get_current_pid_tgid;
49 static unsigned long long (*bpf_get_current_uid_gid)(void) =
50 (void *) BPF_FUNC_get_current_uid_gid;
51 static int (*bpf_get_current_comm)(void *buf, int buf_size) =
52 (void *) BPF_FUNC_get_current_comm;
53 static unsigned long long (*bpf_perf_event_read)(void *map,
54 unsigned long long flags) =
55 (void *) BPF_FUNC_perf_event_read;
56 static int (*bpf_clone_redirect)(void *ctx, int ifindex, int flags) =
57 (void *) BPF_FUNC_clone_redirect;
58 static int (*bpf_redirect)(int ifindex, int flags) =
59 (void *) BPF_FUNC_redirect;
60 static int (*bpf_redirect_map)(void *map, int key, int flags) =
61 (void *) BPF_FUNC_redirect_map;
62 static int (*bpf_perf_event_output)(void *ctx, void *map,
63 unsigned long long flags, void *data,
64 int size) =
65 (void *) BPF_FUNC_perf_event_output;
66 static int (*bpf_get_stackid)(void *ctx, void *map, int flags) =
67 (void *) BPF_FUNC_get_stackid;
68 static int (*bpf_probe_write_user)(void *dst, const void *src, int size) =
69 (void *) BPF_FUNC_probe_write_user;
70 static int (*bpf_current_task_under_cgroup)(void *map, int index) =
71 (void *) BPF_FUNC_current_task_under_cgroup;
72 static int (*bpf_skb_get_tunnel_key)(void *ctx, void *key, int size, int flags) =
73 (void *) BPF_FUNC_skb_get_tunnel_key;
74 static int (*bpf_skb_set_tunnel_key)(void *ctx, void *key, int size, int flags) =
75 (void *) BPF_FUNC_skb_set_tunnel_key;
76 static int (*bpf_skb_get_tunnel_opt)(void *ctx, void *md, int size) =
77 (void *) BPF_FUNC_skb_get_tunnel_opt;
78 static int (*bpf_skb_set_tunnel_opt)(void *ctx, void *md, int size) =
79 (void *) BPF_FUNC_skb_set_tunnel_opt;
80 static unsigned long long (*bpf_get_prandom_u32)(void) =
81 (void *) BPF_FUNC_get_prandom_u32;
82 static int (*bpf_xdp_adjust_head)(void *ctx, int offset) =
83 (void *) BPF_FUNC_xdp_adjust_head;
84 static int (*bpf_xdp_adjust_meta)(void *ctx, int offset) =
85 (void *) BPF_FUNC_xdp_adjust_meta;
86 static int (*bpf_get_socket_cookie)(void *ctx) =
87 (void *) BPF_FUNC_get_socket_cookie;
88 static int (*bpf_setsockopt)(void *ctx, int level, int optname, void *optval,
89 int optlen) =
90 (void *) BPF_FUNC_setsockopt;
91 static int (*bpf_getsockopt)(void *ctx, int level, int optname, void *optval,
92 int optlen) =
93 (void *) BPF_FUNC_getsockopt;
94 static int (*bpf_sock_ops_cb_flags_set)(void *ctx, int flags) =
95 (void *) BPF_FUNC_sock_ops_cb_flags_set;
96 static int (*bpf_sk_redirect_map)(void *ctx, void *map, int key, int flags) =
97 (void *) BPF_FUNC_sk_redirect_map;
98 static int (*bpf_sk_redirect_hash)(void *ctx, void *map, void *key, int flags) =
99 (void *) BPF_FUNC_sk_redirect_hash;
100 static int (*bpf_sock_map_update)(void *map, void *key, void *value,
101 unsigned long long flags) =
102 (void *) BPF_FUNC_sock_map_update;
103 static int (*bpf_sock_hash_update)(void *map, void *key, void *value,
104 unsigned long long flags) =
105 (void *) BPF_FUNC_sock_hash_update;
106 static int (*bpf_perf_event_read_value)(void *map, unsigned long long flags,
107 void *buf, unsigned int buf_size) =
108 (void *) BPF_FUNC_perf_event_read_value;
109 static int (*bpf_perf_prog_read_value)(void *ctx, void *buf,
110 unsigned int buf_size) =
111 (void *) BPF_FUNC_perf_prog_read_value;
112 static int (*bpf_override_return)(void *ctx, unsigned long rc) =
113 (void *) BPF_FUNC_override_return;
114 static int (*bpf_msg_redirect_map)(void *ctx, void *map, int key, int flags) =
115 (void *) BPF_FUNC_msg_redirect_map;
116 static int (*bpf_msg_redirect_hash)(void *ctx,
117 void *map, void *key, int flags) =
118 (void *) BPF_FUNC_msg_redirect_hash;
119 static int (*bpf_msg_apply_bytes)(void *ctx, int len) =
120 (void *) BPF_FUNC_msg_apply_bytes;
121 static int (*bpf_msg_cork_bytes)(void *ctx, int len) =
122 (void *) BPF_FUNC_msg_cork_bytes;
123 static int (*bpf_msg_pull_data)(void *ctx, int start, int end, int flags) =
124 (void *) BPF_FUNC_msg_pull_data;
125 static int (*bpf_msg_push_data)(void *ctx, int start, int end, int flags) =
126 (void *) BPF_FUNC_msg_push_data;
127 static int (*bpf_msg_pop_data)(void *ctx, int start, int cut, int flags) =
128 (void *) BPF_FUNC_msg_pop_data;
129 static int (*bpf_bind)(void *ctx, void *addr, int addr_len) =
130 (void *) BPF_FUNC_bind;
131 static int (*bpf_xdp_adjust_tail)(void *ctx, int offset) =
132 (void *) BPF_FUNC_xdp_adjust_tail;
133 static int (*bpf_skb_get_xfrm_state)(void *ctx, int index, void *state,
134 int size, int flags) =
135 (void *) BPF_FUNC_skb_get_xfrm_state;
136 static int (*bpf_sk_select_reuseport)(void *ctx, void *map, void *key, __u32 flags) =
137 (void *) BPF_FUNC_sk_select_reuseport;
138 static int (*bpf_get_stack)(void *ctx, void *buf, int size, int flags) =
139 (void *) BPF_FUNC_get_stack;
140 static int (*bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params,
141 int plen, __u32 flags) =
142 (void *) BPF_FUNC_fib_lookup;
143 static int (*bpf_lwt_push_encap)(void *ctx, unsigned int type, void *hdr,
144 unsigned int len) =
145 (void *) BPF_FUNC_lwt_push_encap;
146 static int (*bpf_lwt_seg6_store_bytes)(void *ctx, unsigned int offset,
147 void *from, unsigned int len) =
148 (void *) BPF_FUNC_lwt_seg6_store_bytes;
149 static int (*bpf_lwt_seg6_action)(void *ctx, unsigned int action, void *param,
150 unsigned int param_len) =
151 (void *) BPF_FUNC_lwt_seg6_action;
152 static int (*bpf_lwt_seg6_adjust_srh)(void *ctx, unsigned int offset,
153 unsigned int len) =
154 (void *) BPF_FUNC_lwt_seg6_adjust_srh;
155 static int (*bpf_rc_repeat)(void *ctx) =
156 (void *) BPF_FUNC_rc_repeat;
157 static int (*bpf_rc_keydown)(void *ctx, unsigned int protocol,
158 unsigned long long scancode, unsigned int toggle) =
159 (void *) BPF_FUNC_rc_keydown;
160 static unsigned long long (*bpf_get_current_cgroup_id)(void) =
161 (void *) BPF_FUNC_get_current_cgroup_id;
162 static void *(*bpf_get_local_storage)(void *map, unsigned long long flags) =
163 (void *) BPF_FUNC_get_local_storage;
164 static unsigned long long (*bpf_skb_cgroup_id)(void *ctx) =
165 (void *) BPF_FUNC_skb_cgroup_id;
166 static unsigned long long (*bpf_skb_ancestor_cgroup_id)(void *ctx, int level) =
167 (void *) BPF_FUNC_skb_ancestor_cgroup_id;
168 static struct bpf_sock *(*bpf_sk_lookup_tcp)(void *ctx,
169 struct bpf_sock_tuple *tuple,
170 int size, unsigned long long netns_id,
171 unsigned long long flags) =
172 (void *) BPF_FUNC_sk_lookup_tcp;
173 static struct bpf_sock *(*bpf_skc_lookup_tcp)(void *ctx,
174 struct bpf_sock_tuple *tuple,
175 int size, unsigned long long netns_id,
176 unsigned long long flags) =
177 (void *) BPF_FUNC_skc_lookup_tcp;
178 static struct bpf_sock *(*bpf_sk_lookup_udp)(void *ctx,
179 struct bpf_sock_tuple *tuple,
180 int size, unsigned long long netns_id,
181 unsigned long long flags) =
182 (void *) BPF_FUNC_sk_lookup_udp;
183 static int (*bpf_sk_release)(struct bpf_sock *sk) =
184 (void *) BPF_FUNC_sk_release;
185 static int (*bpf_skb_vlan_push)(void *ctx, __be16 vlan_proto, __u16 vlan_tci) =
186 (void *) BPF_FUNC_skb_vlan_push;
187 static int (*bpf_skb_vlan_pop)(void *ctx) =
188 (void *) BPF_FUNC_skb_vlan_pop;
189 static int (*bpf_rc_pointer_rel)(void *ctx, int rel_x, int rel_y) =
190 (void *) BPF_FUNC_rc_pointer_rel;
191 static void (*bpf_spin_lock)(struct bpf_spin_lock *lock) =
192 (void *) BPF_FUNC_spin_lock;
193 static void (*bpf_spin_unlock)(struct bpf_spin_lock *lock) =
194 (void *) BPF_FUNC_spin_unlock;
195 static struct bpf_sock *(*bpf_sk_fullsock)(struct bpf_sock *sk) =
196 (void *) BPF_FUNC_sk_fullsock;
197 static struct bpf_tcp_sock *(*bpf_tcp_sock)(struct bpf_sock *sk) =
198 (void *) BPF_FUNC_tcp_sock;
199 static struct bpf_sock *(*bpf_get_listener_sock)(struct bpf_sock *sk) =
200 (void *) BPF_FUNC_get_listener_sock;
201 static int (*bpf_skb_ecn_set_ce)(void *ctx) =
202 (void *) BPF_FUNC_skb_ecn_set_ce;
203 static int (*bpf_tcp_check_syncookie)(struct bpf_sock *sk,
204 void *ip, int ip_len, void *tcp, int tcp_len) =
205 (void *) BPF_FUNC_tcp_check_syncookie;
206 static int (*bpf_sysctl_get_name)(void *ctx, char *buf,
207 unsigned long long buf_len,
208 unsigned long long flags) =
209 (void *) BPF_FUNC_sysctl_get_name;
210 static int (*bpf_sysctl_get_current_value)(void *ctx, char *buf,
211 unsigned long long buf_len) =
212 (void *) BPF_FUNC_sysctl_get_current_value;
213 static int (*bpf_sysctl_get_new_value)(void *ctx, char *buf,
214 unsigned long long buf_len) =
215 (void *) BPF_FUNC_sysctl_get_new_value;
216 static int (*bpf_sysctl_set_new_value)(void *ctx, const char *buf,
217 unsigned long long buf_len) =
218 (void *) BPF_FUNC_sysctl_set_new_value;
219 static int (*bpf_strtol)(const char *buf, unsigned long long buf_len,
220 unsigned long long flags, long *res) =
221 (void *) BPF_FUNC_strtol;
222 static int (*bpf_strtoul)(const char *buf, unsigned long long buf_len,
223 unsigned long long flags, unsigned long *res) =
224 (void *) BPF_FUNC_strtoul;
225 static void *(*bpf_sk_storage_get)(void *map, struct bpf_sock *sk,
226 void *value, __u64 flags) =
227 (void *) BPF_FUNC_sk_storage_get;
228 static int (*bpf_sk_storage_delete)(void *map, struct bpf_sock *sk) =
229 (void *)BPF_FUNC_sk_storage_delete;
230 static int (*bpf_send_signal)(unsigned sig) = (void *)BPF_FUNC_send_signal;
232 /* llvm builtin functions that eBPF C program may use to
233 * emit BPF_LD_ABS and BPF_LD_IND instructions
235 struct sk_buff;
236 unsigned long long load_byte(void *skb,
237 unsigned long long off) asm("llvm.bpf.load.byte");
238 unsigned long long load_half(void *skb,
239 unsigned long long off) asm("llvm.bpf.load.half");
240 unsigned long long load_word(void *skb,
241 unsigned long long off) asm("llvm.bpf.load.word");
243 /* a helper structure used by eBPF C program
244 * to describe map attributes to elf_bpf loader
246 struct bpf_map_def {
247 unsigned int type;
248 unsigned int key_size;
249 unsigned int value_size;
250 unsigned int max_entries;
251 unsigned int map_flags;
252 unsigned int inner_map_idx;
253 unsigned int numa_node;
256 #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \
257 struct ____btf_map_##name { \
258 type_key key; \
259 type_val value; \
260 }; \
261 struct ____btf_map_##name \
262 __attribute__ ((section(".maps." #name), used)) \
263 ____btf_map_##name = { }
265 static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =
266 (void *) BPF_FUNC_skb_load_bytes;
267 static int (*bpf_skb_load_bytes_relative)(void *ctx, int off, void *to, int len, __u32 start_header) =
268 (void *) BPF_FUNC_skb_load_bytes_relative;
269 static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
270 (void *) BPF_FUNC_skb_store_bytes;
271 static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) =
272 (void *) BPF_FUNC_l3_csum_replace;
273 static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) =
274 (void *) BPF_FUNC_l4_csum_replace;
275 static int (*bpf_csum_diff)(void *from, int from_size, void *to, int to_size, int seed) =
276 (void *) BPF_FUNC_csum_diff;
277 static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =
278 (void *) BPF_FUNC_skb_under_cgroup;
279 static int (*bpf_skb_change_head)(void *, int len, int flags) =
280 (void *) BPF_FUNC_skb_change_head;
281 static int (*bpf_skb_pull_data)(void *, int len) =
282 (void *) BPF_FUNC_skb_pull_data;
283 static unsigned int (*bpf_get_cgroup_classid)(void *ctx) =
284 (void *) BPF_FUNC_get_cgroup_classid;
285 static unsigned int (*bpf_get_route_realm)(void *ctx) =
286 (void *) BPF_FUNC_get_route_realm;
287 static int (*bpf_skb_change_proto)(void *ctx, __be16 proto, __u64 flags) =
288 (void *) BPF_FUNC_skb_change_proto;
289 static int (*bpf_skb_change_type)(void *ctx, __u32 type) =
290 (void *) BPF_FUNC_skb_change_type;
291 static unsigned int (*bpf_get_hash_recalc)(void *ctx) =
292 (void *) BPF_FUNC_get_hash_recalc;
293 static unsigned long long (*bpf_get_current_task)(void) =
294 (void *) BPF_FUNC_get_current_task;
295 static int (*bpf_skb_change_tail)(void *ctx, __u32 len, __u64 flags) =
296 (void *) BPF_FUNC_skb_change_tail;
297 static long long (*bpf_csum_update)(void *ctx, __u32 csum) =
298 (void *) BPF_FUNC_csum_update;
299 static void (*bpf_set_hash_invalid)(void *ctx) =
300 (void *) BPF_FUNC_set_hash_invalid;
301 static int (*bpf_get_numa_node_id)(void) =
302 (void *) BPF_FUNC_get_numa_node_id;
303 static int (*bpf_probe_read_str)(void *ctx, __u32 size,
304 const void *unsafe_ptr) =
305 (void *) BPF_FUNC_probe_read_str;
306 static unsigned int (*bpf_get_socket_uid)(void *ctx) =
307 (void *) BPF_FUNC_get_socket_uid;
308 static unsigned int (*bpf_set_hash)(void *ctx, __u32 hash) =
309 (void *) BPF_FUNC_set_hash;
310 static int (*bpf_skb_adjust_room)(void *ctx, __s32 len_diff, __u32 mode,
311 unsigned long long flags) =
312 (void *) BPF_FUNC_skb_adjust_room;
314 /* Scan the ARCH passed in from ARCH env variable (see Makefile) */
315 #if defined(__TARGET_ARCH_x86)
316 #define bpf_target_x86
317 #define bpf_target_defined
318 #elif defined(__TARGET_ARCH_s390)
319 #define bpf_target_s390
320 #define bpf_target_defined
321 #elif defined(__TARGET_ARCH_arm)
322 #define bpf_target_arm
323 #define bpf_target_defined
324 #elif defined(__TARGET_ARCH_arm64)
325 #define bpf_target_arm64
326 #define bpf_target_defined
327 #elif defined(__TARGET_ARCH_mips)
328 #define bpf_target_mips
329 #define bpf_target_defined
330 #elif defined(__TARGET_ARCH_powerpc)
331 #define bpf_target_powerpc
332 #define bpf_target_defined
333 #elif defined(__TARGET_ARCH_sparc)
334 #define bpf_target_sparc
335 #define bpf_target_defined
336 #else
337 #undef bpf_target_defined
338 #endif
340 /* Fall back to what the compiler says */
341 #ifndef bpf_target_defined
342 #if defined(__x86_64__)
343 #define bpf_target_x86
344 #elif defined(__s390__)
345 #define bpf_target_s390
346 #elif defined(__arm__)
347 #define bpf_target_arm
348 #elif defined(__aarch64__)
349 #define bpf_target_arm64
350 #elif defined(__mips__)
351 #define bpf_target_mips
352 #elif defined(__powerpc__)
353 #define bpf_target_powerpc
354 #elif defined(__sparc__)
355 #define bpf_target_sparc
356 #endif
357 #endif
359 #if defined(bpf_target_x86)
361 #ifdef __KERNEL__
362 #define PT_REGS_PARM1(x) ((x)->di)
363 #define PT_REGS_PARM2(x) ((x)->si)
364 #define PT_REGS_PARM3(x) ((x)->dx)
365 #define PT_REGS_PARM4(x) ((x)->cx)
366 #define PT_REGS_PARM5(x) ((x)->r8)
367 #define PT_REGS_RET(x) ((x)->sp)
368 #define PT_REGS_FP(x) ((x)->bp)
369 #define PT_REGS_RC(x) ((x)->ax)
370 #define PT_REGS_SP(x) ((x)->sp)
371 #define PT_REGS_IP(x) ((x)->ip)
372 #else
373 #ifdef __i386__
374 /* i386 kernel is built with -mregparm=3 */
375 #define PT_REGS_PARM1(x) ((x)->eax)
376 #define PT_REGS_PARM2(x) ((x)->edx)
377 #define PT_REGS_PARM3(x) ((x)->ecx)
378 #define PT_REGS_PARM4(x) 0
379 #define PT_REGS_PARM5(x) 0
380 #define PT_REGS_RET(x) ((x)->esp)
381 #define PT_REGS_FP(x) ((x)->ebp)
382 #define PT_REGS_RC(x) ((x)->eax)
383 #define PT_REGS_SP(x) ((x)->esp)
384 #define PT_REGS_IP(x) ((x)->eip)
385 #else
386 #define PT_REGS_PARM1(x) ((x)->rdi)
387 #define PT_REGS_PARM2(x) ((x)->rsi)
388 #define PT_REGS_PARM3(x) ((x)->rdx)
389 #define PT_REGS_PARM4(x) ((x)->rcx)
390 #define PT_REGS_PARM5(x) ((x)->r8)
391 #define PT_REGS_RET(x) ((x)->rsp)
392 #define PT_REGS_FP(x) ((x)->rbp)
393 #define PT_REGS_RC(x) ((x)->rax)
394 #define PT_REGS_SP(x) ((x)->rsp)
395 #define PT_REGS_IP(x) ((x)->rip)
396 #endif
397 #endif
399 #elif defined(bpf_target_s390)
401 /* s390 provides user_pt_regs instead of struct pt_regs to userspace */
402 struct pt_regs;
403 #define PT_REGS_S390 const volatile user_pt_regs
404 #define PT_REGS_PARM1(x) (((PT_REGS_S390 *)(x))->gprs[2])
405 #define PT_REGS_PARM2(x) (((PT_REGS_S390 *)(x))->gprs[3])
406 #define PT_REGS_PARM3(x) (((PT_REGS_S390 *)(x))->gprs[4])
407 #define PT_REGS_PARM4(x) (((PT_REGS_S390 *)(x))->gprs[5])
408 #define PT_REGS_PARM5(x) (((PT_REGS_S390 *)(x))->gprs[6])
409 #define PT_REGS_RET(x) (((PT_REGS_S390 *)(x))->gprs[14])
410 /* Works only with CONFIG_FRAME_POINTER */
411 #define PT_REGS_FP(x) (((PT_REGS_S390 *)(x))->gprs[11])
412 #define PT_REGS_RC(x) (((PT_REGS_S390 *)(x))->gprs[2])
413 #define PT_REGS_SP(x) (((PT_REGS_S390 *)(x))->gprs[15])
414 #define PT_REGS_IP(x) (((PT_REGS_S390 *)(x))->psw.addr)
416 #elif defined(bpf_target_arm)
418 #define PT_REGS_PARM1(x) ((x)->uregs[0])
419 #define PT_REGS_PARM2(x) ((x)->uregs[1])
420 #define PT_REGS_PARM3(x) ((x)->uregs[2])
421 #define PT_REGS_PARM4(x) ((x)->uregs[3])
422 #define PT_REGS_PARM5(x) ((x)->uregs[4])
423 #define PT_REGS_RET(x) ((x)->uregs[14])
424 #define PT_REGS_FP(x) ((x)->uregs[11]) /* Works only with CONFIG_FRAME_POINTER */
425 #define PT_REGS_RC(x) ((x)->uregs[0])
426 #define PT_REGS_SP(x) ((x)->uregs[13])
427 #define PT_REGS_IP(x) ((x)->uregs[12])
429 #elif defined(bpf_target_arm64)
431 /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */
432 struct pt_regs;
433 #define PT_REGS_ARM64 const volatile struct user_pt_regs
434 #define PT_REGS_PARM1(x) (((PT_REGS_ARM64 *)(x))->regs[0])
435 #define PT_REGS_PARM2(x) (((PT_REGS_ARM64 *)(x))->regs[1])
436 #define PT_REGS_PARM3(x) (((PT_REGS_ARM64 *)(x))->regs[2])
437 #define PT_REGS_PARM4(x) (((PT_REGS_ARM64 *)(x))->regs[3])
438 #define PT_REGS_PARM5(x) (((PT_REGS_ARM64 *)(x))->regs[4])
439 #define PT_REGS_RET(x) (((PT_REGS_ARM64 *)(x))->regs[30])
440 /* Works only with CONFIG_FRAME_POINTER */
441 #define PT_REGS_FP(x) (((PT_REGS_ARM64 *)(x))->regs[29])
442 #define PT_REGS_RC(x) (((PT_REGS_ARM64 *)(x))->regs[0])
443 #define PT_REGS_SP(x) (((PT_REGS_ARM64 *)(x))->sp)
444 #define PT_REGS_IP(x) (((PT_REGS_ARM64 *)(x))->pc)
446 #elif defined(bpf_target_mips)
448 #define PT_REGS_PARM1(x) ((x)->regs[4])
449 #define PT_REGS_PARM2(x) ((x)->regs[5])
450 #define PT_REGS_PARM3(x) ((x)->regs[6])
451 #define PT_REGS_PARM4(x) ((x)->regs[7])
452 #define PT_REGS_PARM5(x) ((x)->regs[8])
453 #define PT_REGS_RET(x) ((x)->regs[31])
454 #define PT_REGS_FP(x) ((x)->regs[30]) /* Works only with CONFIG_FRAME_POINTER */
455 #define PT_REGS_RC(x) ((x)->regs[1])
456 #define PT_REGS_SP(x) ((x)->regs[29])
457 #define PT_REGS_IP(x) ((x)->cp0_epc)
459 #elif defined(bpf_target_powerpc)
461 #define PT_REGS_PARM1(x) ((x)->gpr[3])
462 #define PT_REGS_PARM2(x) ((x)->gpr[4])
463 #define PT_REGS_PARM3(x) ((x)->gpr[5])
464 #define PT_REGS_PARM4(x) ((x)->gpr[6])
465 #define PT_REGS_PARM5(x) ((x)->gpr[7])
466 #define PT_REGS_RC(x) ((x)->gpr[3])
467 #define PT_REGS_SP(x) ((x)->sp)
468 #define PT_REGS_IP(x) ((x)->nip)
470 #elif defined(bpf_target_sparc)
472 #define PT_REGS_PARM1(x) ((x)->u_regs[UREG_I0])
473 #define PT_REGS_PARM2(x) ((x)->u_regs[UREG_I1])
474 #define PT_REGS_PARM3(x) ((x)->u_regs[UREG_I2])
475 #define PT_REGS_PARM4(x) ((x)->u_regs[UREG_I3])
476 #define PT_REGS_PARM5(x) ((x)->u_regs[UREG_I4])
477 #define PT_REGS_RET(x) ((x)->u_regs[UREG_I7])
478 #define PT_REGS_RC(x) ((x)->u_regs[UREG_I0])
479 #define PT_REGS_SP(x) ((x)->u_regs[UREG_FP])
481 /* Should this also be a bpf_target check for the sparc case? */
482 #if defined(__arch64__)
483 #define PT_REGS_IP(x) ((x)->tpc)
484 #else
485 #define PT_REGS_IP(x) ((x)->pc)
486 #endif
488 #endif
490 #if defined(bpf_target_powerpc)
491 #define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = (ctx)->link; })
492 #define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
493 #elif defined(bpf_target_sparc)
494 #define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = PT_REGS_RET(ctx); })
495 #define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
496 #else
497 #define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ \
498 bpf_probe_read(&(ip), sizeof(ip), (void *)PT_REGS_RET(ctx)); })
499 #define BPF_KRETPROBE_READ_RET_IP(ip, ctx) ({ \
500 bpf_probe_read(&(ip), sizeof(ip), \
501 (void *)(PT_REGS_FP(ctx) + sizeof(ip))); })
502 #endif
504 #endif