extable.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_EXTABLE_H
  3. #define _ASM_X86_EXTABLE_H
  4. #include <asm/extable_fixup_types.h>
  5. /*
  6. * The exception table consists of two addresses relative to the
  7. * exception table entry itself and a type selector field.
  8. *
  9. * The first address is of an instruction that is allowed to fault, the
  10. * second is the target at which the program should continue.
  11. *
  12. * The type entry is used by fixup_exception() to select the handler to
  13. * deal with the fault caused by the instruction in the first field.
  14. *
  15. * All the routines below use bits of fixup code that are out of line
  16. * with the main instruction path. This means when everything is well,
  17. * we don't even have to jump over them. Further, they do not intrude
  18. * on our cache or tlb entries.
  19. */
  20. struct exception_table_entry {
  21. int insn, fixup, data;
  22. };
  23. struct pt_regs;
  24. #define ARCH_HAS_RELATIVE_EXTABLE
  25. #define swap_ex_entry_fixup(a, b, tmp, delta) \
  26. do { \
  27. (a)->fixup = (b)->fixup + (delta); \
  28. (b)->fixup = (tmp).fixup - (delta); \
  29. (a)->data = (b)->data; \
  30. (b)->data = (tmp).data; \
  31. } while (0)
  32. extern int fixup_exception(struct pt_regs *regs, int trapnr,
  33. unsigned long error_code, unsigned long fault_addr);
  34. extern int fixup_bug(struct pt_regs *regs, int trapnr);
  35. extern int ex_get_fixup_type(unsigned long ip);
  36. extern void early_fixup_exception(struct pt_regs *regs, int trapnr);
  37. #ifdef CONFIG_X86_MCE
  38. extern void __noreturn ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr);
  39. #else
  40. static inline void __noreturn ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr)
  41. {
  42. for (;;)
  43. cpu_relax();
  44. }
  45. #endif
  46. #if defined(CONFIG_BPF_JIT) && defined(CONFIG_X86_64)
  47. bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs);
  48. #else
  49. static inline bool ex_handler_bpf(const struct exception_table_entry *x,
  50. struct pt_regs *regs) { return false; }
  51. #endif
  52. #endif