162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __ASM_EXTABLE_H
362306a36Sopenharmony_ci#define __ASM_EXTABLE_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci * The exception table consists of pairs of relative offsets: the first
762306a36Sopenharmony_ci * is the relative offset to an instruction that is allowed to fault,
862306a36Sopenharmony_ci * and the second is the relative offset at which the program should
962306a36Sopenharmony_ci * continue. No registers are modified, so it is entirely up to the
1062306a36Sopenharmony_ci * continuation code to figure out what to do.
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * All the routines below use bits of fixup code that are out of line
1362306a36Sopenharmony_ci * with the main instruction path.  This means when everything is well,
1462306a36Sopenharmony_ci * we don't even have to jump over them.  Further, they do not intrude
1562306a36Sopenharmony_ci * on our cache or tlb entries.
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct exception_table_entry
1962306a36Sopenharmony_ci{
2062306a36Sopenharmony_ci	int insn, fixup;
2162306a36Sopenharmony_ci	short type, data;
2262306a36Sopenharmony_ci};
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define ARCH_HAS_RELATIVE_EXTABLE
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define swap_ex_entry_fixup(a, b, tmp, delta)		\
2762306a36Sopenharmony_cido {							\
2862306a36Sopenharmony_ci	(a)->fixup = (b)->fixup + (delta);		\
2962306a36Sopenharmony_ci	(b)->fixup = (tmp).fixup - (delta);		\
3062306a36Sopenharmony_ci	(a)->type = (b)->type;				\
3162306a36Sopenharmony_ci	(b)->type = (tmp).type;				\
3262306a36Sopenharmony_ci	(a)->data = (b)->data;				\
3362306a36Sopenharmony_ci	(b)->data = (tmp).data;				\
3462306a36Sopenharmony_ci} while (0)
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#ifdef CONFIG_BPF_JIT
3762306a36Sopenharmony_cibool ex_handler_bpf(const struct exception_table_entry *ex,
3862306a36Sopenharmony_ci		    struct pt_regs *regs);
3962306a36Sopenharmony_ci#else /* !CONFIG_BPF_JIT */
4062306a36Sopenharmony_cistatic inline
4162306a36Sopenharmony_cibool ex_handler_bpf(const struct exception_table_entry *ex,
4262306a36Sopenharmony_ci		    struct pt_regs *regs)
4362306a36Sopenharmony_ci{
4462306a36Sopenharmony_ci	return false;
4562306a36Sopenharmony_ci}
4662306a36Sopenharmony_ci#endif /* !CONFIG_BPF_JIT */
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cibool fixup_exception(struct pt_regs *regs);
4962306a36Sopenharmony_ci#endif
50