xref: /linux/arch/x86/include/asm/traps.h (revision c01044cc819160323f3ca4acd44fca487c4432e6)
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 bool fault_in_kernel_space(unsigned long address);
39 
40 #ifdef CONFIG_VMAP_STACK
41 void __noreturn handle_stack_overflow(const char *message,
42 				      struct pt_regs *regs,
43 				      unsigned long fault_address);
44 #endif
45 
46 /*
47  * Page fault error code bits:
48  *
49  *   bit 0 ==	 0: no page found	1: protection fault
50  *   bit 1 ==	 0: read access		1: write access
51  *   bit 2 ==	 0: kernel-mode access	1: user-mode access
52  *   bit 3 ==				1: use of reserved bit detected
53  *   bit 4 ==				1: fault was an instruction fetch
54  *   bit 5 ==				1: protection keys block access
55  */
56 enum x86_pf_error_code {
57 	X86_PF_PROT	=		1 << 0,
58 	X86_PF_WRITE	=		1 << 1,
59 	X86_PF_USER	=		1 << 2,
60 	X86_PF_RSVD	=		1 << 3,
61 	X86_PF_INSTR	=		1 << 4,
62 	X86_PF_PK	=		1 << 5,
63 };
64 #endif /* _ASM_X86_TRAPS_H */
65