1 #ifndef _ASM_X86_UNWIND_HINTS_H
2 #define _ASM_X86_UNWIND_HINTS_H
3
4 #include "orc_types.h"
5
6 #ifdef __ASSEMBLY__
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 .macro UNWIND_HINT sp_reg=ORC_REG_SP sp_offset=0 type=ORC_TYPE_CALL end=0
30 #ifdef CONFIG_STACK_VALIDATION
31 .Lunwind_hint_ip_\@:
32 .pushsection .discard.unwind_hints
33
34 .long .Lunwind_hint_ip_\@ - .
35 .short \sp_offset
36 .byte \sp_reg
37 .byte \type
38 .byte \end
39 .balign 4
40 .popsection
41 #endif
42 .endm
43
44 .macro UNWIND_HINT_EMPTY
45 UNWIND_HINT sp_reg=ORC_REG_UNDEFINED end=1
46 .endm
47
48 .macro UNWIND_HINT_REGS base=%rsp offset=0 indirect=0 extra=1 iret=0
49 .if \base == %rsp
50 .if \indirect
51 .set sp_reg, ORC_REG_SP_INDIRECT
52 .else
53 .set sp_reg, ORC_REG_SP
54 .endif
55 .elseif \base == %rbp
56 .set sp_reg, ORC_REG_BP
57 .elseif \base == %rdi
58 .set sp_reg, ORC_REG_DI
59 .elseif \base == %rdx
60 .set sp_reg, ORC_REG_DX
61 .elseif \base == %r10
62 .set sp_reg, ORC_REG_R10
63 .else
64 .error "UNWIND_HINT_REGS: bad base register"
65 .endif
66
67 .set sp_offset, \offset
68
69 .if \iret
70 .set type, ORC_TYPE_REGS_IRET
71 .elseif \extra == 0
72 .set type, ORC_TYPE_REGS_IRET
73 .set sp_offset, \offset + (16*8)
74 .else
75 .set type, ORC_TYPE_REGS
76 .endif
77
78 UNWIND_HINT sp_reg=sp_reg sp_offset=sp_offset type=type
79 .endm
80
81 .macro UNWIND_HINT_IRET_REGS base=%rsp offset=0
82 UNWIND_HINT_REGS base=\base offset=\offset iret=1
83 .endm
84
85 .macro UNWIND_HINT_FUNC sp_offset=8
86 UNWIND_HINT sp_offset=\sp_offset
87 .endm
88
89 #else
90
91 #define UNWIND_HINT(sp_reg, sp_offset, type, end) \
92 "987: \n\t" \
93 ".pushsection .discard.unwind_hints\n\t" \
94 \
95 ".long 987b - .\n\t" \
96 ".short " __stringify(sp_offset) "\n\t" \
97 ".byte " __stringify(sp_reg) "\n\t" \
98 ".byte " __stringify(type) "\n\t" \
99 ".byte " __stringify(end) "\n\t" \
100 ".balign 4 \n\t" \
101 ".popsection\n\t"
102
103 #define UNWIND_HINT_SAVE UNWIND_HINT(0, 0, UNWIND_HINT_TYPE_SAVE, 0)
104
105 #define UNWIND_HINT_RESTORE UNWIND_HINT(0, 0, UNWIND_HINT_TYPE_RESTORE, 0)
106
107 #endif
108
109 #endif