xref: /linux/arch/x86/include/asm/traps.h (revision 0f69403d2535ffc7200a8414cf3ca66a49b0d741)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_TRAPS_H
3 #define _ASM_X86_TRAPS_H
4 
5 #include <linux/context_tracking_state.h>
6 #include <linux/kprobes.h>
7 
8 #include <asm/debugreg.h>
9 #include <asm/idtentry.h>
10 #include <asm/siginfo.h>			/* TRAP_TRACE, ... */
11 
12 #ifdef CONFIG_X86_64
13 asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs);
14 asmlinkage __visible notrace
15 struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s);
16 void __init trap_init(void);
17 #endif
18 
19 #ifdef CONFIG_X86_F00F_BUG
20 /* For handling the FOOF bug */
21 void handle_invalid_op(struct pt_regs *regs);
22 #endif
23 
24 static inline int get_si_code(unsigned long condition)
25 {
26 	if (condition & DR_STEP)
27 		return TRAP_TRACE;
28 	else if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3))
29 		return TRAP_HWBKPT;
30 	else
31 		return TRAP_BRKPT;
32 }
33 
34 extern int panic_on_unrecovered_nmi;
35 
36 void math_emulate(struct math_emu_info *);
37 
38 #ifdef CONFIG_VMAP_STACK
39 void __noreturn handle_stack_overflow(const char *message,
40 				      struct pt_regs *regs,
41 				      unsigned long fault_address);
42 #endif
43 
44 /*
45  * Page fault error code bits:
46  *
47  *   bit 0 ==	 0: no page found	1: protection fault
48  *   bit 1 ==	 0: read access		1: write access
49  *   bit 2 ==	 0: kernel-mode access	1: user-mode access
50  *   bit 3 ==				1: use of reserved bit detected
51  *   bit 4 ==				1: fault was an instruction fetch
52  *   bit 5 ==				1: protection keys block access
53  */
54 enum x86_pf_error_code {
55 	X86_PF_PROT	=		1 << 0,
56 	X86_PF_WRITE	=		1 << 1,
57 	X86_PF_USER	=		1 << 2,
58 	X86_PF_RSVD	=		1 << 3,
59 	X86_PF_INSTR	=		1 << 4,
60 	X86_PF_PK	=		1 << 5,
61 };
62 #endif /* _ASM_X86_TRAPS_H */
63