blob: 6407a3df0f3ba1ab5b4775c36f208d2689fb7c7d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Alexei Starovoitov249b8122014-12-01 15:06:37 -08002#ifndef __BPF_HELPERS_H
3#define __BPF_HELPERS_H
4
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))
10
11/* helper functions called from eBPF programs written in C */
12static void *(*bpf_map_lookup_elem)(void *map, void *key) =
13 (void *) BPF_FUNC_map_lookup_elem;
14static int (*bpf_map_update_elem)(void *map, void *key, void *value,
15 unsigned long long flags) =
16 (void *) BPF_FUNC_map_update_elem;
17static int (*bpf_map_delete_elem)(void *map, void *key) =
18 (void *) BPF_FUNC_map_delete_elem;
Mauricio Vasquez B43b987d2018-10-18 15:16:41 +020019static int (*bpf_map_push_elem)(void *map, void *value,
20 unsigned long long flags) =
21 (void *) BPF_FUNC_map_push_elem;
22static int (*bpf_map_pop_elem)(void *map, void *value) =
23 (void *) BPF_FUNC_map_pop_elem;
24static int (*bpf_map_peek_elem)(void *map, void *value) =
25 (void *) BPF_FUNC_map_peek_elem;
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070026static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
27 (void *) BPF_FUNC_probe_read;
28static unsigned long long (*bpf_ktime_get_ns)(void) =
29 (void *) BPF_FUNC_ktime_get_ns;
30static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
31 (void *) BPF_FUNC_trace_printk;
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070032static void (*bpf_tail_call)(void *ctx, void *map, int index) =
33 (void *) BPF_FUNC_tail_call;
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070034static unsigned long long (*bpf_get_smp_processor_id)(void) =
35 (void *) BPF_FUNC_get_smp_processor_id;
Alexei Starovoitovffeedaf2015-06-12 19:39:12 -070036static unsigned long long (*bpf_get_current_pid_tgid)(void) =
37 (void *) BPF_FUNC_get_current_pid_tgid;
38static unsigned long long (*bpf_get_current_uid_gid)(void) =
39 (void *) BPF_FUNC_get_current_uid_gid;
40static int (*bpf_get_current_comm)(void *buf, int buf_size) =
41 (void *) BPF_FUNC_get_current_comm;
Teng Qin41e9a802017-06-02 21:03:53 -070042static unsigned long long (*bpf_perf_event_read)(void *map,
43 unsigned long long flags) =
Kaixu Xia47efb302015-08-06 07:02:36 +000044 (void *) BPF_FUNC_perf_event_read;
Alexei Starovoitov27b29f62015-09-15 23:05:43 -070045static int (*bpf_clone_redirect)(void *ctx, int ifindex, int flags) =
46 (void *) BPF_FUNC_clone_redirect;
47static int (*bpf_redirect)(int ifindex, int flags) =
48 (void *) BPF_FUNC_redirect;
John Fastabend9d6e0052017-07-17 09:30:25 -070049static int (*bpf_redirect_map)(void *map, int key, int flags) =
50 (void *) BPF_FUNC_redirect_map;
Adam Barth05b8ad22016-08-10 09:45:39 -070051static int (*bpf_perf_event_output)(void *ctx, void *map,
52 unsigned long long flags, void *data,
53 int size) =
Alexei Starovoitov39111692015-10-20 20:02:35 -070054 (void *) BPF_FUNC_perf_event_output;
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080055static int (*bpf_get_stackid)(void *ctx, void *map, int flags) =
56 (void *) BPF_FUNC_get_stackid;
Sargun Dhillon96ae5222016-07-25 05:54:46 -070057static int (*bpf_probe_write_user)(void *dst, void *src, int size) =
58 (void *) BPF_FUNC_probe_write_user;
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070059static int (*bpf_current_task_under_cgroup)(void *map, int index) =
60 (void *) BPF_FUNC_current_task_under_cgroup;
William Tu6afb1e22016-08-19 11:55:44 -070061static int (*bpf_skb_get_tunnel_key)(void *ctx, void *key, int size, int flags) =
62 (void *) BPF_FUNC_skb_get_tunnel_key;
63static int (*bpf_skb_set_tunnel_key)(void *ctx, void *key, int size, int flags) =
64 (void *) BPF_FUNC_skb_set_tunnel_key;
65static int (*bpf_skb_get_tunnel_opt)(void *ctx, void *md, int size) =
66 (void *) BPF_FUNC_skb_get_tunnel_opt;
67static int (*bpf_skb_set_tunnel_opt)(void *ctx, void *md, int size) =
68 (void *) BPF_FUNC_skb_set_tunnel_opt;
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070069static unsigned long long (*bpf_get_prandom_u32)(void) =
70 (void *) BPF_FUNC_get_prandom_u32;
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -080071static int (*bpf_xdp_adjust_head)(void *ctx, int offset) =
72 (void *) BPF_FUNC_xdp_adjust_head;
Daniel Borkmann22c88522017-09-25 02:25:53 +020073static int (*bpf_xdp_adjust_meta)(void *ctx, int offset) =
74 (void *) BPF_FUNC_xdp_adjust_meta;
Andrey Ignatov0289a2c2018-07-30 17:42:30 -070075static int (*bpf_get_socket_cookie)(void *ctx) =
76 (void *) BPF_FUNC_get_socket_cookie;
Lawrence Brakmo8c4b4c72017-06-30 20:02:46 -070077static int (*bpf_setsockopt)(void *ctx, int level, int optname, void *optval,
78 int optlen) =
79 (void *) BPF_FUNC_setsockopt;
Lawrence Brakmocd86d1f2017-10-20 11:05:40 -070080static int (*bpf_getsockopt)(void *ctx, int level, int optname, void *optval,
81 int optlen) =
82 (void *) BPF_FUNC_getsockopt;
Lawrence Brakmod6d4f602018-01-25 16:14:16 -080083static int (*bpf_sock_ops_cb_flags_set)(void *ctx, int flags) =
84 (void *) BPF_FUNC_sock_ops_cb_flags_set;
John Fastabend34f795022017-10-18 07:10:36 -070085static int (*bpf_sk_redirect_map)(void *ctx, void *map, int key, int flags) =
John Fastabend69e8cc12017-08-15 22:33:32 -070086 (void *) BPF_FUNC_sk_redirect_map;
John Fastabendb8b394f2018-05-14 10:00:18 -070087static int (*bpf_sk_redirect_hash)(void *ctx, void *map, void *key, int flags) =
88 (void *) BPF_FUNC_sk_redirect_hash;
John Fastabend69e8cc12017-08-15 22:33:32 -070089static int (*bpf_sock_map_update)(void *map, void *key, void *value,
John Fastabend464bc0f2017-08-28 07:10:04 -070090 unsigned long long flags) =
John Fastabend69e8cc12017-08-15 22:33:32 -070091 (void *) BPF_FUNC_sock_map_update;
John Fastabendb8b394f2018-05-14 10:00:18 -070092static int (*bpf_sock_hash_update)(void *map, void *key, void *value,
93 unsigned long long flags) =
94 (void *) BPF_FUNC_sock_hash_update;
Yonghong Song020a32d2017-10-05 09:19:21 -070095static int (*bpf_perf_event_read_value)(void *map, unsigned long long flags,
96 void *buf, unsigned int buf_size) =
97 (void *) BPF_FUNC_perf_event_read_value;
Yonghong Song81b9cf82017-10-05 09:19:23 -070098static int (*bpf_perf_prog_read_value)(void *ctx, void *buf,
99 unsigned int buf_size) =
100 (void *) BPF_FUNC_perf_prog_read_value;
Josef Bacik965de872017-12-11 11:36:49 -0500101static int (*bpf_override_return)(void *ctx, unsigned long rc) =
102 (void *) BPF_FUNC_override_return;
John Fastabend4c4c3c22018-03-18 12:57:41 -0700103static int (*bpf_msg_redirect_map)(void *ctx, void *map, int key, int flags) =
104 (void *) BPF_FUNC_msg_redirect_map;
John Fastabendb8b394f2018-05-14 10:00:18 -0700105static int (*bpf_msg_redirect_hash)(void *ctx,
106 void *map, void *key, int flags) =
107 (void *) BPF_FUNC_msg_redirect_hash;
John Fastabend1c16c312018-03-18 12:57:56 -0700108static int (*bpf_msg_apply_bytes)(void *ctx, int len) =
109 (void *) BPF_FUNC_msg_apply_bytes;
John Fastabend468b3fd2018-03-18 12:58:02 -0700110static int (*bpf_msg_cork_bytes)(void *ctx, int len) =
111 (void *) BPF_FUNC_msg_cork_bytes;
John Fastabend0dcbbf62018-03-18 12:58:12 -0700112static int (*bpf_msg_pull_data)(void *ctx, int start, int end, int flags) =
113 (void *) BPF_FUNC_msg_pull_data;
Andrey Ignatov622adaf2018-03-30 15:08:06 -0700114static int (*bpf_bind)(void *ctx, void *addr, int addr_len) =
115 (void *) BPF_FUNC_bind;
Nikita V. Shirokov0367d0a2018-04-17 21:42:22 -0700116static int (*bpf_xdp_adjust_tail)(void *ctx, int offset) =
117 (void *) BPF_FUNC_xdp_adjust_tail;
Eyal Birger29a36f92018-04-24 17:50:30 +0300118static int (*bpf_skb_get_xfrm_state)(void *ctx, int index, void *state,
119 int size, int flags) =
120 (void *) BPF_FUNC_skb_get_xfrm_state;
Martin KaFai Lau91134d82018-08-08 01:01:31 -0700121static int (*bpf_sk_select_reuseport)(void *ctx, void *map, void *key, __u32 flags) =
122 (void *) BPF_FUNC_sk_select_reuseport;
Yonghong Songde2ff052018-04-28 22:28:12 -0700123static int (*bpf_get_stack)(void *ctx, void *buf, int size, int flags) =
124 (void *) BPF_FUNC_get_stack;
David Ahernfe616052018-05-09 20:34:27 -0700125static int (*bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params,
126 int plen, __u32 flags) =
127 (void *) BPF_FUNC_fib_lookup;
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +0100128static int (*bpf_lwt_push_encap)(void *ctx, unsigned int type, void *hdr,
129 unsigned int len) =
130 (void *) BPF_FUNC_lwt_push_encap;
131static int (*bpf_lwt_seg6_store_bytes)(void *ctx, unsigned int offset,
132 void *from, unsigned int len) =
133 (void *) BPF_FUNC_lwt_seg6_store_bytes;
134static int (*bpf_lwt_seg6_action)(void *ctx, unsigned int action, void *param,
135 unsigned int param_len) =
136 (void *) BPF_FUNC_lwt_seg6_action;
137static int (*bpf_lwt_seg6_adjust_srh)(void *ctx, unsigned int offset,
138 unsigned int len) =
139 (void *) BPF_FUNC_lwt_seg6_adjust_srh;
Sean Young6bdd5332018-05-27 12:24:10 +0100140static int (*bpf_rc_repeat)(void *ctx) =
141 (void *) BPF_FUNC_rc_repeat;
142static int (*bpf_rc_keydown)(void *ctx, unsigned int protocol,
143 unsigned long long scancode, unsigned int toggle) =
144 (void *) BPF_FUNC_rc_keydown;
Yonghong Songc7ddbba2018-06-03 15:59:42 -0700145static unsigned long long (*bpf_get_current_cgroup_id)(void) =
146 (void *) BPF_FUNC_get_current_cgroup_id;
Roman Gushchind4c9f572018-08-02 14:27:28 -0700147static void *(*bpf_get_local_storage)(void *map, unsigned long long flags) =
148 (void *) BPF_FUNC_get_local_storage;
Andrey Ignatov02f6ac72018-08-12 10:49:29 -0700149static unsigned long long (*bpf_skb_cgroup_id)(void *ctx) =
150 (void *) BPF_FUNC_skb_cgroup_id;
151static unsigned long long (*bpf_skb_ancestor_cgroup_id)(void *ctx, int level) =
152 (void *) BPF_FUNC_skb_ancestor_cgroup_id;
Joe Stringer6acc9b42018-10-02 13:35:36 -0700153static struct bpf_sock *(*bpf_sk_lookup_tcp)(void *ctx,
154 struct bpf_sock_tuple *tuple,
155 int size, unsigned int netns_id,
156 unsigned long long flags) =
157 (void *) BPF_FUNC_sk_lookup_tcp;
158static struct bpf_sock *(*bpf_sk_lookup_udp)(void *ctx,
159 struct bpf_sock_tuple *tuple,
160 int size, unsigned int netns_id,
161 unsigned long long flags) =
162 (void *) BPF_FUNC_sk_lookup_udp;
163static int (*bpf_sk_release)(struct bpf_sock *sk) =
164 (void *) BPF_FUNC_sk_release;
Jesper Dangaard Brouer4f775442018-10-09 12:04:48 +0200165static int (*bpf_skb_vlan_push)(void *ctx, __be16 vlan_proto, __u16 vlan_tci) =
166 (void *) BPF_FUNC_skb_vlan_push;
167static int (*bpf_skb_vlan_pop)(void *ctx) =
168 (void *) BPF_FUNC_skb_vlan_pop;
Alexei Starovoitov249b8122014-12-01 15:06:37 -0800169
170/* llvm builtin functions that eBPF C program may use to
171 * emit BPF_LD_ABS and BPF_LD_IND instructions
172 */
173struct sk_buff;
174unsigned long long load_byte(void *skb,
175 unsigned long long off) asm("llvm.bpf.load.byte");
176unsigned long long load_half(void *skb,
177 unsigned long long off) asm("llvm.bpf.load.half");
178unsigned long long load_word(void *skb,
179 unsigned long long off) asm("llvm.bpf.load.word");
180
181/* a helper structure used by eBPF C program
182 * to describe map attributes to elf_bpf loader
183 */
184struct bpf_map_def {
185 unsigned int type;
186 unsigned int key_size;
187 unsigned int value_size;
188 unsigned int max_entries;
Alexei Starovoitov89b97602016-03-07 21:57:20 -0800189 unsigned int map_flags;
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -0700190 unsigned int inner_map_idx;
Martin KaFai Lauad17d0e2017-08-18 11:28:01 -0700191 unsigned int numa_node;
Alexei Starovoitov249b8122014-12-01 15:06:37 -0800192};
193
Martin KaFai Lau38d5d3b2018-07-24 08:40:22 -0700194#define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \
195 struct ____btf_map_##name { \
196 type_key key; \
197 type_val value; \
198 }; \
199 struct ____btf_map_##name \
200 __attribute__ ((section(".maps." #name), used)) \
201 ____btf_map_##name = { }
202
Thomas Graff74599f2016-11-30 17:10:11 +0100203static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =
204 (void *) BPF_FUNC_skb_load_bytes;
Martin KaFai Lau91134d82018-08-08 01:01:31 -0700205static int (*bpf_skb_load_bytes_relative)(void *ctx, int off, void *to, int len, __u32 start_header) =
206 (void *) BPF_FUNC_skb_load_bytes_relative;
Alexei Starovoitov91bc48222015-04-01 17:12:13 -0700207static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
208 (void *) BPF_FUNC_skb_store_bytes;
209static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) =
210 (void *) BPF_FUNC_l3_csum_replace;
211static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) =
212 (void *) BPF_FUNC_l4_csum_replace;
Nikita V. Shirokovc6ffd1f2018-04-17 21:42:23 -0700213static int (*bpf_csum_diff)(void *from, int from_size, void *to, int to_size, int seed) =
214 (void *) BPF_FUNC_csum_diff;
Daniel Borkmann747ea552016-08-12 22:17:17 +0200215static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =
216 (void *) BPF_FUNC_skb_under_cgroup;
Thomas Graff74599f2016-11-30 17:10:11 +0100217static int (*bpf_skb_change_head)(void *, int len, int flags) =
218 (void *) BPF_FUNC_skb_change_head;
John Fastabend82a86162018-03-18 12:57:31 -0700219static int (*bpf_skb_pull_data)(void *, int len) =
220 (void *) BPF_FUNC_skb_pull_data;
Alexei Starovoitov91bc48222015-04-01 17:12:13 -0700221
Joel Fernandesb655fc12017-09-20 09:11:58 -0700222/* Scan the ARCH passed in from ARCH env variable (see Makefile) */
223#if defined(__TARGET_ARCH_x86)
224 #define bpf_target_x86
225 #define bpf_target_defined
226#elif defined(__TARGET_ARCH_s930x)
227 #define bpf_target_s930x
228 #define bpf_target_defined
229#elif defined(__TARGET_ARCH_arm64)
230 #define bpf_target_arm64
231 #define bpf_target_defined
232#elif defined(__TARGET_ARCH_mips)
233 #define bpf_target_mips
234 #define bpf_target_defined
235#elif defined(__TARGET_ARCH_powerpc)
236 #define bpf_target_powerpc
237 #define bpf_target_defined
238#elif defined(__TARGET_ARCH_sparc)
239 #define bpf_target_sparc
240 #define bpf_target_defined
241#else
242 #undef bpf_target_defined
243#endif
244
245/* Fall back to what the compiler says */
246#ifndef bpf_target_defined
Michael Holzheud9125572015-07-06 16:20:07 +0200247#if defined(__x86_64__)
Joel Fernandesb655fc12017-09-20 09:11:58 -0700248 #define bpf_target_x86
249#elif defined(__s390x__)
250 #define bpf_target_s930x
251#elif defined(__aarch64__)
252 #define bpf_target_arm64
253#elif defined(__mips__)
254 #define bpf_target_mips
255#elif defined(__powerpc__)
256 #define bpf_target_powerpc
257#elif defined(__sparc__)
258 #define bpf_target_sparc
259#endif
260#endif
261
262#if defined(bpf_target_x86)
Michael Holzheud9125572015-07-06 16:20:07 +0200263
264#define PT_REGS_PARM1(x) ((x)->di)
265#define PT_REGS_PARM2(x) ((x)->si)
266#define PT_REGS_PARM3(x) ((x)->dx)
267#define PT_REGS_PARM4(x) ((x)->cx)
268#define PT_REGS_PARM5(x) ((x)->r8)
269#define PT_REGS_RET(x) ((x)->sp)
270#define PT_REGS_FP(x) ((x)->bp)
271#define PT_REGS_RC(x) ((x)->ax)
272#define PT_REGS_SP(x) ((x)->sp)
Naveen N. Rao138d6152016-04-04 22:31:34 +0530273#define PT_REGS_IP(x) ((x)->ip)
Michael Holzheud9125572015-07-06 16:20:07 +0200274
Joel Fernandesb655fc12017-09-20 09:11:58 -0700275#elif defined(bpf_target_s390x)
Michael Holzheud9125572015-07-06 16:20:07 +0200276
277#define PT_REGS_PARM1(x) ((x)->gprs[2])
278#define PT_REGS_PARM2(x) ((x)->gprs[3])
279#define PT_REGS_PARM3(x) ((x)->gprs[4])
280#define PT_REGS_PARM4(x) ((x)->gprs[5])
281#define PT_REGS_PARM5(x) ((x)->gprs[6])
282#define PT_REGS_RET(x) ((x)->gprs[14])
283#define PT_REGS_FP(x) ((x)->gprs[11]) /* Works only with CONFIG_FRAME_POINTER */
284#define PT_REGS_RC(x) ((x)->gprs[2])
285#define PT_REGS_SP(x) ((x)->gprs[15])
Michael Holzheu2dbb4c02016-11-28 13:48:30 +0100286#define PT_REGS_IP(x) ((x)->psw.addr)
Michael Holzheud9125572015-07-06 16:20:07 +0200287
Joel Fernandesb655fc12017-09-20 09:11:58 -0700288#elif defined(bpf_target_arm64)
Yang Shi85ff8a432015-10-26 17:02:19 -0700289
290#define PT_REGS_PARM1(x) ((x)->regs[0])
291#define PT_REGS_PARM2(x) ((x)->regs[1])
292#define PT_REGS_PARM3(x) ((x)->regs[2])
293#define PT_REGS_PARM4(x) ((x)->regs[3])
294#define PT_REGS_PARM5(x) ((x)->regs[4])
295#define PT_REGS_RET(x) ((x)->regs[30])
296#define PT_REGS_FP(x) ((x)->regs[29]) /* Works only with CONFIG_FRAME_POINTER */
297#define PT_REGS_RC(x) ((x)->regs[0])
298#define PT_REGS_SP(x) ((x)->sp)
Naveen N. Rao138d6152016-04-04 22:31:34 +0530299#define PT_REGS_IP(x) ((x)->pc)
300
Joel Fernandesb655fc12017-09-20 09:11:58 -0700301#elif defined(bpf_target_mips)
David Daneyc1932cd2017-06-13 16:49:37 -0700302
303#define PT_REGS_PARM1(x) ((x)->regs[4])
304#define PT_REGS_PARM2(x) ((x)->regs[5])
305#define PT_REGS_PARM3(x) ((x)->regs[6])
306#define PT_REGS_PARM4(x) ((x)->regs[7])
307#define PT_REGS_PARM5(x) ((x)->regs[8])
308#define PT_REGS_RET(x) ((x)->regs[31])
309#define PT_REGS_FP(x) ((x)->regs[30]) /* Works only with CONFIG_FRAME_POINTER */
310#define PT_REGS_RC(x) ((x)->regs[1])
311#define PT_REGS_SP(x) ((x)->regs[29])
312#define PT_REGS_IP(x) ((x)->cp0_epc)
313
Joel Fernandesb655fc12017-09-20 09:11:58 -0700314#elif defined(bpf_target_powerpc)
Naveen N. Rao138d6152016-04-04 22:31:34 +0530315
316#define PT_REGS_PARM1(x) ((x)->gpr[3])
317#define PT_REGS_PARM2(x) ((x)->gpr[4])
318#define PT_REGS_PARM3(x) ((x)->gpr[5])
319#define PT_REGS_PARM4(x) ((x)->gpr[6])
320#define PT_REGS_PARM5(x) ((x)->gpr[7])
321#define PT_REGS_RC(x) ((x)->gpr[3])
322#define PT_REGS_SP(x) ((x)->sp)
323#define PT_REGS_IP(x) ((x)->nip)
Yang Shi85ff8a432015-10-26 17:02:19 -0700324
Joel Fernandesb655fc12017-09-20 09:11:58 -0700325#elif defined(bpf_target_sparc)
David S. Millerb0c47802017-04-22 12:31:05 -0700326
327#define PT_REGS_PARM1(x) ((x)->u_regs[UREG_I0])
328#define PT_REGS_PARM2(x) ((x)->u_regs[UREG_I1])
329#define PT_REGS_PARM3(x) ((x)->u_regs[UREG_I2])
330#define PT_REGS_PARM4(x) ((x)->u_regs[UREG_I3])
331#define PT_REGS_PARM5(x) ((x)->u_regs[UREG_I4])
332#define PT_REGS_RET(x) ((x)->u_regs[UREG_I7])
333#define PT_REGS_RC(x) ((x)->u_regs[UREG_I0])
334#define PT_REGS_SP(x) ((x)->u_regs[UREG_FP])
Joel Fernandesb655fc12017-09-20 09:11:58 -0700335
336/* Should this also be a bpf_target check for the sparc case? */
David S. Millerb0c47802017-04-22 12:31:05 -0700337#if defined(__arch64__)
338#define PT_REGS_IP(x) ((x)->tpc)
339#else
340#define PT_REGS_IP(x) ((x)->pc)
341#endif
342
Michael Holzheud9125572015-07-06 16:20:07 +0200343#endif
Naveen N. Rao138d6152016-04-04 22:31:34 +0530344
Joel Fernandesb655fc12017-09-20 09:11:58 -0700345#ifdef bpf_target_powerpc
Naveen N. Rao138d6152016-04-04 22:31:34 +0530346#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = (ctx)->link; })
347#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
Joel Fernandesb655fc12017-09-20 09:11:58 -0700348#elif bpf_target_sparc
David S. Millerb0c47802017-04-22 12:31:05 -0700349#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = PT_REGS_RET(ctx); })
350#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
Naveen N. Rao138d6152016-04-04 22:31:34 +0530351#else
352#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ \
353 bpf_probe_read(&(ip), sizeof(ip), (void *)PT_REGS_RET(ctx)); })
354#define BPF_KRETPROBE_READ_RET_IP(ip, ctx) ({ \
355 bpf_probe_read(&(ip), sizeof(ip), \
356 (void *)(PT_REGS_FP(ctx) + sizeof(ip))); })
357#endif
358
Alexei Starovoitov249b8122014-12-01 15:06:37 -0800359#endif