Skip to content

Commit a9b3c69

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h
In preparation for wider use, move the ENCODE_FRAME_POINTER macros to a common header and provide inline asm versions. These macros are used to encode a pt_regs frame for the unwinder; see unwind_frame.c:decode_frame_pointer(). Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 5e1246f commit a9b3c69

File tree

3 files changed

+49
-31
lines changed

3 files changed

+49
-31
lines changed

arch/x86/entry/calling.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,6 @@ For 32-bit we have the following conventions - kernel is built with
172172
.endif
173173
.endm
174174

175-
/*
176-
* This is a sneaky trick to help the unwinder find pt_regs on the stack. The
177-
* frame pointer is replaced with an encoded pointer to pt_regs. The encoding
178-
* is just setting the LSB, which makes it an invalid stack address and is also
179-
* a signal to the unwinder that it's a pt_regs pointer in disguise.
180-
*
181-
* NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
182-
* the original rbp.
183-
*/
184-
.macro ENCODE_FRAME_POINTER ptregs_offset=0
185-
#ifdef CONFIG_FRAME_POINTER
186-
leaq 1+\ptregs_offset(%rsp), %rbp
187-
#endif
188-
.endm
189-
190175
#ifdef CONFIG_PAGE_TABLE_ISOLATION
191176

192177
/*

arch/x86/entry/entry_32.S

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,22 +246,6 @@
246246
.Lend_\@:
247247
.endm
248248

249-
/*
250-
* This is a sneaky trick to help the unwinder find pt_regs on the stack. The
251-
* frame pointer is replaced with an encoded pointer to pt_regs. The encoding
252-
* is just clearing the MSB, which makes it an invalid stack address and is also
253-
* a signal to the unwinder that it's a pt_regs pointer in disguise.
254-
*
255-
* NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
256-
* original rbp.
257-
*/
258-
.macro ENCODE_FRAME_POINTER
259-
#ifdef CONFIG_FRAME_POINTER
260-
mov %esp, %ebp
261-
andl $0x7fffffff, %ebp
262-
#endif
263-
.endm
264-
265249
.macro RESTORE_INT_REGS
266250
popl %ebx
267251
popl %ecx

arch/x86/include/asm/frame.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@
2222
pop %_ASM_BP
2323
.endm
2424

25+
#ifdef CONFIG_X86_64
26+
/*
27+
* This is a sneaky trick to help the unwinder find pt_regs on the stack. The
28+
* frame pointer is replaced with an encoded pointer to pt_regs. The encoding
29+
* is just setting the LSB, which makes it an invalid stack address and is also
30+
* a signal to the unwinder that it's a pt_regs pointer in disguise.
31+
*
32+
* NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
33+
* the original rbp.
34+
*/
35+
.macro ENCODE_FRAME_POINTER ptregs_offset=0
36+
leaq 1+\ptregs_offset(%rsp), %rbp
37+
.endm
38+
#else /* !CONFIG_X86_64 */
39+
/*
40+
* This is a sneaky trick to help the unwinder find pt_regs on the stack. The
41+
* frame pointer is replaced with an encoded pointer to pt_regs. The encoding
42+
* is just clearing the MSB, which makes it an invalid stack address and is also
43+
* a signal to the unwinder that it's a pt_regs pointer in disguise.
44+
*
45+
* NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
46+
* original ebp.
47+
*/
48+
.macro ENCODE_FRAME_POINTER
49+
mov %esp, %ebp
50+
andl $0x7fffffff, %ebp
51+
.endm
52+
#endif /* CONFIG_X86_64 */
53+
2554
#else /* !__ASSEMBLY__ */
2655

2756
#define FRAME_BEGIN \
@@ -30,12 +59,32 @@
3059

3160
#define FRAME_END "pop %" _ASM_BP "\n"
3261

62+
#ifdef CONFIG_X86_64
63+
#define ENCODE_FRAME_POINTER \
64+
"lea 1(%rsp), %rbp\n\t"
65+
#else /* !CONFIG_X86_64 */
66+
#define ENCODE_FRAME_POINTER \
67+
"movl %esp, %ebp\n\t" \
68+
"andl $0x7fffffff, %ebp\n\t"
69+
#endif /* CONFIG_X86_64 */
70+
3371
#endif /* __ASSEMBLY__ */
3472

3573
#define FRAME_OFFSET __ASM_SEL(4, 8)
3674

3775
#else /* !CONFIG_FRAME_POINTER */
3876

77+
#ifdef __ASSEMBLY__
78+
79+
.macro ENCODE_FRAME_POINTER ptregs_offset=0
80+
.endm
81+
82+
#else /* !__ASSEMBLY */
83+
84+
#define ENCODE_FRAME_POINTER
85+
86+
#endif
87+
3988
#define FRAME_BEGIN
4089
#define FRAME_END
4190
#define FRAME_OFFSET 0

0 commit comments

Comments
 (0)