1
2#ifndef __BPF_HELPERS_H
3#define __BPF_HELPERS_H
4
5
6
7
8
9#define SEC(NAME) __attribute__((section(NAME), used))
10
11#define __uint(name, val) int (*name)[val]
12#define __type(name, val) val *name
13
14
15#define bpf_printk(fmt, ...) \
16({ \
17 char ____fmt[] = fmt; \
18 bpf_trace_printk(____fmt, sizeof(____fmt), \
19 ##__VA_ARGS__); \
20})
21
22
23static void *(*bpf_map_lookup_elem)(void *map, const void *key) =
24 (void *) BPF_FUNC_map_lookup_elem;
25static 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;
28static int (*bpf_map_delete_elem)(void *map, const void *key) =
29 (void *) BPF_FUNC_map_delete_elem;
30static int (*bpf_map_push_elem)(void *map, const void *value,
31 unsigned long long flags) =
32 (void *) BPF_FUNC_map_push_elem;
33static int (*bpf_map_pop_elem)(void *map, void *value) =
34 (void *) BPF_FUNC_map_pop_elem;
35static int (*bpf_map_peek_elem)(void *map, void *value) =
36 (void *) BPF_FUNC_map_peek_elem;
37static int (*bpf_probe_read)(void *dst, int size, const void *unsafe_ptr) =
38 (void *) BPF_FUNC_probe_read;
39static unsigned long long (*bpf_ktime_get_ns)(void) =
40 (void *) BPF_FUNC_ktime_get_ns;
41static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
42 (void *) BPF_FUNC_trace_printk;
43static void (*bpf_tail_call)(void *ctx, void *map, int index) =
44 (void *) BPF_FUNC_tail_call;
45static unsigned long long (*bpf_get_smp_processor_id)(void) =
46 (void *) BPF_FUNC_get_smp_processor_id;
47static unsigned long long (*bpf_get_current_pid_tgid)(void) =
48 (void *) BPF_FUNC_get_current_pid_tgid;
49static unsigned long long (*bpf_get_current_uid_gid)(void) =
50 (void *) BPF_FUNC_get_current_uid_gid;
51static int (*bpf_get_current_comm)(void *buf, int buf_size) =
52 (void *) BPF_FUNC_get_current_comm;
53static unsigned long long (*bpf_perf_event_read)(void *map,
54 unsigned long long flags) =
55 (void *) BPF_FUNC_perf_event_read;
56static int (*bpf_clone_redirect)(void *ctx, int ifindex, int flags) =
57 (void *) BPF_FUNC_clone_redirect;
58static int (*bpf_redirect)(int ifindex, int flags) =
59 (void *) BPF_FUNC_redirect;
60static int (*bpf_redirect_map)(void *map, int key, int flags) =
61 (void *) BPF_FUNC_redirect_map;
62static 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;
66static int (*bpf_get_stackid)(void *ctx, void *map, int flags) =
67 (void *) BPF_FUNC_get_stackid;
68static int (*bpf_probe_write_user)(void *dst, const void *src, int size) =
69 (void *) BPF_FUNC_probe_write_user;
70static int (*bpf_current_task_under_cgroup)(void *map, int index) =
71 (void *) BPF_FUNC_current_task_under_cgroup;
72static int (*bpf_skb_get_tunnel_key)(void *ctx, void *key, int size, int flags) =
73 (void *) BPF_FUNC_skb_get_tunnel_key;
74static int (*bpf_skb_set_tunnel_key)(void *ctx, void *key, int size, int flags) =
75 (void *) BPF_FUNC_skb_set_tunnel_key;
76static int (*bpf_skb_get_tunnel_opt)(void *ctx, void *md, int size) =
77 (void *) BPF_FUNC_skb_get_tunnel_opt;
78static int (*bpf_skb_set_tunnel_opt)(void *ctx, void *md, int size) =
79 (void *) BPF_FUNC_skb_set_tunnel_opt;
80static unsigned long long (*bpf_get_prandom_u32)(void) =
81 (void *) BPF_FUNC_get_prandom_u32;
82static int (*bpf_xdp_adjust_head)(void *ctx, int offset) =
83 (void *) BPF_FUNC_xdp_adjust_head;
84static int (*bpf_xdp_adjust_meta)(void *ctx, int offset) =
85 (void *) BPF_FUNC_xdp_adjust_meta;
86static int (*bpf_get_socket_cookie)(void *ctx) =
87 (void *) BPF_FUNC_get_socket_cookie;
88static int (*bpf_setsockopt)(void *ctx, int level, int optname, void *optval,
89 int optlen) =
90 (void *) BPF_FUNC_setsockopt;
91static int (*bpf_getsockopt)(void *ctx, int level, int optname, void *optval,
92 int optlen) =
93 (void *) BPF_FUNC_getsockopt;
94static int (*bpf_sock_ops_cb_flags_set)(void *ctx, int flags) =
95 (void *) BPF_FUNC_sock_ops_cb_flags_set;
96static int (*bpf_sk_redirect_map)(void *ctx, void *map, int key, int flags) =
97 (void *) BPF_FUNC_sk_redirect_map;
98static int (*bpf_sk_redirect_hash)(void *ctx, void *map, void *key, int flags) =
99 (void *) BPF_FUNC_sk_redirect_hash;
100static int (*bpf_sock_map_update)(void *map, void *key, void *value,
101 unsigned long long flags) =
102 (void *) BPF_FUNC_sock_map_update;
103static int (*bpf_sock_hash_update)(void *map, void *key, void *value,
104 unsigned long long flags) =
105 (void *) BPF_FUNC_sock_hash_update;
106static 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;
109static int (*bpf_perf_prog_read_value)(void *ctx, void *buf,
110 unsigned int buf_size) =
111 (void *) BPF_FUNC_perf_prog_read_value;
112static int (*bpf_override_return)(void *ctx, unsigned long rc) =
113 (void *) BPF_FUNC_override_return;
114static int (*bpf_msg_redirect_map)(void *ctx, void *map, int key, int flags) =
115 (void *) BPF_FUNC_msg_redirect_map;
116static int (*bpf_msg_redirect_hash)(void *ctx,
117 void *map, void *key, int flags) =
118 (void *) BPF_FUNC_msg_redirect_hash;
119static int (*bpf_msg_apply_bytes)(void *ctx, int len) =
120 (void *) BPF_FUNC_msg_apply_bytes;
121static int (*bpf_msg_cork_bytes)(void *ctx, int len) =
122 (void *) BPF_FUNC_msg_cork_bytes;
123static int (*bpf_msg_pull_data)(void *ctx, int start, int end, int flags) =
124 (void *) BPF_FUNC_msg_pull_data;
125static int (*bpf_msg_push_data)(void *ctx, int start, int end, int flags) =
126 (void *) BPF_FUNC_msg_push_data;
127static int (*bpf_msg_pop_data)(void *ctx, int start, int cut, int flags) =
128 (void *) BPF_FUNC_msg_pop_data;
129static int (*bpf_bind)(void *ctx, void *addr, int addr_len) =
130 (void *) BPF_FUNC_bind;
131static int (*bpf_xdp_adjust_tail)(void *ctx, int offset) =
132 (void *) BPF_FUNC_xdp_adjust_tail;
133static 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;
136static int (*bpf_sk_select_reuseport)(void *ctx, void *map, void *key, __u32 flags) =
137 (void *) BPF_FUNC_sk_select_reuseport;
138static int (*bpf_get_stack)(void *ctx, void *buf, int size, int flags) =
139 (void *) BPF_FUNC_get_stack;
140static int (*bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params,
141 int plen, __u32 flags) =
142 (void *) BPF_FUNC_fib_lookup;
143static int (*bpf_lwt_push_encap)(void *ctx, unsigned int type, void *hdr,
144 unsigned int len) =
145 (void *) BPF_FUNC_lwt_push_encap;
146static 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;
149static int (*bpf_lwt_seg6_action)(void *ctx, unsigned int action, void *param,
150 unsigned int param_len) =
151 (void *) BPF_FUNC_lwt_seg6_action;
152static int (*bpf_lwt_seg6_adjust_srh)(void *ctx, unsigned int offset,
153 unsigned int len) =
154 (void *) BPF_FUNC_lwt_seg6_adjust_srh;
155static int (*bpf_rc_repeat)(void *ctx) =
156 (void *) BPF_FUNC_rc_repeat;
157static int (*bpf_rc_keydown)(void *ctx, unsigned int protocol,
158 unsigned long long scancode, unsigned int toggle) =
159 (void *) BPF_FUNC_rc_keydown;
160static unsigned long long (*bpf_get_current_cgroup_id)(void) =
161 (void *) BPF_FUNC_get_current_cgroup_id;
162static void *(*bpf_get_local_storage)(void *map, unsigned long long flags) =
163 (void *) BPF_FUNC_get_local_storage;
164static unsigned long long (*bpf_skb_cgroup_id)(void *ctx) =
165 (void *) BPF_FUNC_skb_cgroup_id;
166static unsigned long long (*bpf_skb_ancestor_cgroup_id)(void *ctx, int level) =
167 (void *) BPF_FUNC_skb_ancestor_cgroup_id;
168static 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;
173static 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;
178static 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;
183static int (*bpf_sk_release)(struct bpf_sock *sk) =
184 (void *) BPF_FUNC_sk_release;
185static int (*bpf_skb_vlan_push)(void *ctx, __be16 vlan_proto, __u16 vlan_tci) =
186 (void *) BPF_FUNC_skb_vlan_push;
187static int (*bpf_skb_vlan_pop)(void *ctx) =
188 (void *) BPF_FUNC_skb_vlan_pop;
189static int (*bpf_rc_pointer_rel)(void *ctx, int rel_x, int rel_y) =
190 (void *) BPF_FUNC_rc_pointer_rel;
191static void (*bpf_spin_lock)(struct bpf_spin_lock *lock) =
192 (void *) BPF_FUNC_spin_lock;
193static void (*bpf_spin_unlock)(struct bpf_spin_lock *lock) =
194 (void *) BPF_FUNC_spin_unlock;
195static struct bpf_sock *(*bpf_sk_fullsock)(struct bpf_sock *sk) =
196 (void *) BPF_FUNC_sk_fullsock;
197static struct bpf_tcp_sock *(*bpf_tcp_sock)(struct bpf_sock *sk) =
198 (void *) BPF_FUNC_tcp_sock;
199static struct bpf_sock *(*bpf_get_listener_sock)(struct bpf_sock *sk) =
200 (void *) BPF_FUNC_get_listener_sock;
201static int (*bpf_skb_ecn_set_ce)(void *ctx) =
202 (void *) BPF_FUNC_skb_ecn_set_ce;
203static 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;
206static 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;
210static int (*bpf_sysctl_get_current_value)(void *ctx, char *buf,
211 unsigned long long buf_len) =
212 (void *) BPF_FUNC_sysctl_get_current_value;
213static int (*bpf_sysctl_get_new_value)(void *ctx, char *buf,
214 unsigned long long buf_len) =
215 (void *) BPF_FUNC_sysctl_get_new_value;
216static 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;
219static int (*bpf_strtol)(const char *buf, unsigned long long buf_len,
220 unsigned long long flags, long *res) =
221 (void *) BPF_FUNC_strtol;
222static int (*bpf_strtoul)(const char *buf, unsigned long long buf_len,
223 unsigned long long flags, unsigned long *res) =
224 (void *) BPF_FUNC_strtoul;
225static void *(*bpf_sk_storage_get)(void *map, struct bpf_sock *sk,
226 void *value, __u64 flags) =
227 (void *) BPF_FUNC_sk_storage_get;
228static int (*bpf_sk_storage_delete)(void *map, struct bpf_sock *sk) =
229 (void *)BPF_FUNC_sk_storage_delete;
230static int (*bpf_send_signal)(unsigned sig) = (void *)BPF_FUNC_send_signal;
231
232
233
234
235struct sk_buff;
236unsigned long long load_byte(void *skb,
237 unsigned long long off) asm("llvm.bpf.load.byte");
238unsigned long long load_half(void *skb,
239 unsigned long long off) asm("llvm.bpf.load.half");
240unsigned long long load_word(void *skb,
241 unsigned long long off) asm("llvm.bpf.load.word");
242
243
244
245
246struct 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;
254};
255
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 = { }
264
265static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =
266 (void *) BPF_FUNC_skb_load_bytes;
267static 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;
269static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
270 (void *) BPF_FUNC_skb_store_bytes;
271static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) =
272 (void *) BPF_FUNC_l3_csum_replace;
273static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) =
274 (void *) BPF_FUNC_l4_csum_replace;
275static int (*bpf_csum_diff)(void *from, int from_size, void *to, int to_size, int seed) =
276 (void *) BPF_FUNC_csum_diff;
277static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =
278 (void *) BPF_FUNC_skb_under_cgroup;
279static int (*bpf_skb_change_head)(void *, int len, int flags) =
280 (void *) BPF_FUNC_skb_change_head;
281static int (*bpf_skb_pull_data)(void *, int len) =
282 (void *) BPF_FUNC_skb_pull_data;
283static unsigned int (*bpf_get_cgroup_classid)(void *ctx) =
284 (void *) BPF_FUNC_get_cgroup_classid;
285static unsigned int (*bpf_get_route_realm)(void *ctx) =
286 (void *) BPF_FUNC_get_route_realm;
287static int (*bpf_skb_change_proto)(void *ctx, __be16 proto, __u64 flags) =
288 (void *) BPF_FUNC_skb_change_proto;
289static int (*bpf_skb_change_type)(void *ctx, __u32 type) =
290 (void *) BPF_FUNC_skb_change_type;
291static unsigned int (*bpf_get_hash_recalc)(void *ctx) =
292 (void *) BPF_FUNC_get_hash_recalc;
293static unsigned long long (*bpf_get_current_task)(void) =
294 (void *) BPF_FUNC_get_current_task;
295static int (*bpf_skb_change_tail)(void *ctx, __u32 len, __u64 flags) =
296 (void *) BPF_FUNC_skb_change_tail;
297static long long (*bpf_csum_update)(void *ctx, __u32 csum) =
298 (void *) BPF_FUNC_csum_update;
299static void (*bpf_set_hash_invalid)(void *ctx) =
300 (void *) BPF_FUNC_set_hash_invalid;
301static int (*bpf_get_numa_node_id)(void) =
302 (void *) BPF_FUNC_get_numa_node_id;
303static int (*bpf_probe_read_str)(void *ctx, __u32 size,
304 const void *unsafe_ptr) =
305 (void *) BPF_FUNC_probe_read_str;
306static unsigned int (*bpf_get_socket_uid)(void *ctx) =
307 (void *) BPF_FUNC_get_socket_uid;
308static unsigned int (*bpf_set_hash)(void *ctx, __u32 hash) =
309 (void *) BPF_FUNC_set_hash;
310static int (*bpf_skb_adjust_room)(void *ctx, __s32 len_diff, __u32 mode,
311 unsigned long long flags) =
312 (void *) BPF_FUNC_skb_adjust_room;
313
314
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
339
340
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
358
359#if defined(bpf_target_x86)
360
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
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
398
399#elif defined(bpf_target_s390)
400
401
402struct 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
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)
415
416#elif defined(bpf_target_arm)
417
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])
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])
428
429#elif defined(bpf_target_arm64)
430
431
432struct 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
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)
445
446#elif defined(bpf_target_mips)
447
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])
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)
458
459#elif defined(bpf_target_powerpc)
460
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)
469
470#elif defined(bpf_target_sparc)
471
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])
480
481
482#if defined(__arch64__)
483#define PT_REGS_IP(x) ((x)->tpc)
484#else
485#define PT_REGS_IP(x) ((x)->pc)
486#endif
487
488#endif
489
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
503
504#endif
505