diff options
author | Jan Beulich <jbeulich@novell.com> | 2006-06-26 07:57:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-26 13:48:17 -0400 |
commit | b538ed278b80641ee6d7b75497d5e14de1bb1137 (patch) | |
tree | fe508a2f950ec08c832474a253f41b188ceece75 /include | |
parent | 4552d5dc08b79868829b4be8951b29b07284753f (diff) |
[PATCH] x86_64: reliable stack trace support (x86-64)
These are the x86_64-specific pieces to enable reliable stack traces. The
only restriction with this is that it currently cannot unwind across the
interrupt->normal stack boundary, as that transition is lacking proper
annotation.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-x86_64/proto.h | 2 | ||||
-rw-r--r-- | include/asm-x86_64/unwind.h | 106 |
2 files changed, 107 insertions, 1 deletions
diff --git a/include/asm-x86_64/proto.h b/include/asm-x86_64/proto.h index 1064533e0959..105476ff8039 100644 --- a/include/asm-x86_64/proto.h +++ b/include/asm-x86_64/proto.h | |||
@@ -75,7 +75,7 @@ extern void main_timer_handler(struct pt_regs *regs); | |||
75 | 75 | ||
76 | extern unsigned long end_pfn_map; | 76 | extern unsigned long end_pfn_map; |
77 | 77 | ||
78 | extern void show_trace(unsigned long * rsp); | 78 | extern void show_trace(struct task_struct *, struct pt_regs *, unsigned long * rsp); |
79 | extern void show_registers(struct pt_regs *regs); | 79 | extern void show_registers(struct pt_regs *regs); |
80 | 80 | ||
81 | extern void exception_table_check(void); | 81 | extern void exception_table_check(void); |
diff --git a/include/asm-x86_64/unwind.h b/include/asm-x86_64/unwind.h new file mode 100644 index 000000000000..4f61de246179 --- /dev/null +++ b/include/asm-x86_64/unwind.h | |||
@@ -0,0 +1,106 @@ | |||
1 | #ifndef _ASM_X86_64_UNWIND_H | ||
2 | #define _ASM_X86_64_UNWIND_H | ||
3 | |||
4 | /* | ||
5 | * Copyright (C) 2002-2006 Novell, Inc. | ||
6 | * Jan Beulich <jbeulich@novell.com> | ||
7 | * This code is released under version 2 of the GNU GPL. | ||
8 | */ | ||
9 | |||
10 | #ifdef CONFIG_STACK_UNWIND | ||
11 | |||
12 | #include <linux/sched.h> | ||
13 | #include <asm/ptrace.h> | ||
14 | #include <asm/uaccess.h> | ||
15 | #include <asm/vsyscall.h> | ||
16 | |||
17 | struct unwind_frame_info | ||
18 | { | ||
19 | struct pt_regs regs; | ||
20 | struct task_struct *task; | ||
21 | }; | ||
22 | |||
23 | #define UNW_PC(frame) (frame)->regs.rip | ||
24 | #define UNW_SP(frame) (frame)->regs.rsp | ||
25 | #ifdef CONFIG_FRAME_POINTER | ||
26 | #define UNW_FP(frame) (frame)->regs.rbp | ||
27 | #define FRAME_RETADDR_OFFSET 8 | ||
28 | #define FRAME_LINK_OFFSET 0 | ||
29 | #define STACK_BOTTOM(tsk) (((tsk)->thread.rsp0 - 1) & ~(THREAD_SIZE - 1)) | ||
30 | #define STACK_TOP(tsk) ((tsk)->thread.rsp0) | ||
31 | #endif | ||
32 | /* Might need to account for the special exception and interrupt handling | ||
33 | stacks here, since normally | ||
34 | EXCEPTION_STACK_ORDER < THREAD_ORDER < IRQSTACK_ORDER, | ||
35 | but the construct is needed only for getting across the stack switch to | ||
36 | the interrupt stack - thus considering the IRQ stack itself is unnecessary, | ||
37 | and the overhead of comparing against all exception handling stacks seems | ||
38 | not desirable. */ | ||
39 | #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1)) | ||
40 | |||
41 | #define UNW_REGISTER_INFO \ | ||
42 | PTREGS_INFO(rax), \ | ||
43 | PTREGS_INFO(rdx), \ | ||
44 | PTREGS_INFO(rcx), \ | ||
45 | PTREGS_INFO(rbx), \ | ||
46 | PTREGS_INFO(rsi), \ | ||
47 | PTREGS_INFO(rdi), \ | ||
48 | PTREGS_INFO(rbp), \ | ||
49 | PTREGS_INFO(rsp), \ | ||
50 | PTREGS_INFO(r8), \ | ||
51 | PTREGS_INFO(r9), \ | ||
52 | PTREGS_INFO(r10), \ | ||
53 | PTREGS_INFO(r11), \ | ||
54 | PTREGS_INFO(r12), \ | ||
55 | PTREGS_INFO(r13), \ | ||
56 | PTREGS_INFO(r14), \ | ||
57 | PTREGS_INFO(r15), \ | ||
58 | PTREGS_INFO(rip) | ||
59 | |||
60 | static inline void arch_unw_init_frame_info(struct unwind_frame_info *info, | ||
61 | /*const*/ struct pt_regs *regs) | ||
62 | { | ||
63 | info->regs = *regs; | ||
64 | } | ||
65 | |||
66 | static inline void arch_unw_init_blocked(struct unwind_frame_info *info) | ||
67 | { | ||
68 | extern const char thread_return[]; | ||
69 | |||
70 | memset(&info->regs, 0, sizeof(info->regs)); | ||
71 | info->regs.rip = (unsigned long)thread_return; | ||
72 | info->regs.cs = __KERNEL_CS; | ||
73 | __get_user(info->regs.rbp, (unsigned long *)info->task->thread.rsp); | ||
74 | info->regs.rsp = info->task->thread.rsp; | ||
75 | info->regs.ss = __KERNEL_DS; | ||
76 | } | ||
77 | |||
78 | extern void arch_unwind_init_running(struct unwind_frame_info *, | ||
79 | void (*callback)(struct unwind_frame_info *, | ||
80 | void *arg), | ||
81 | void *arg); | ||
82 | |||
83 | static inline int arch_unw_user_mode(const struct unwind_frame_info *info) | ||
84 | { | ||
85 | #if 0 /* This can only work when selector register saves/restores | ||
86 | are properly annotated (and tracked in UNW_REGISTER_INFO). */ | ||
87 | return user_mode(&info->regs); | ||
88 | #else | ||
89 | return (long)info->regs.rip >= 0 | ||
90 | || (info->regs.rip >= VSYSCALL_START && info->regs.rip < VSYSCALL_END) | ||
91 | || (long)info->regs.rsp >= 0; | ||
92 | #endif | ||
93 | } | ||
94 | |||
95 | #else | ||
96 | |||
97 | #define UNW_PC(frame) ((void)(frame), 0) | ||
98 | |||
99 | static inline int arch_unw_user_mode(const void *info) | ||
100 | { | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | #endif | ||
105 | |||
106 | #endif /* _ASM_X86_64_UNWIND_H */ | ||