]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86/include/asm/stacktrace.h
7646fb2772f801a0950ec7c9ecbbcf4122e9ebcd
[mirror_ubuntu-artful-kernel.git] / arch / x86 / include / asm / stacktrace.h
1 /*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4 */
5
6 #ifndef _ASM_X86_STACKTRACE_H
7 #define _ASM_X86_STACKTRACE_H
8
9 #include <linux/uaccess.h>
10 #include <linux/ptrace.h>
11 #include <asm/switch_to.h>
12
13 extern int kstack_depth_to_print;
14
15 struct thread_info;
16 struct stacktrace_ops;
17
18 typedef unsigned long (*walk_stack_t)(struct task_struct *task,
19 unsigned long *stack,
20 unsigned long bp,
21 const struct stacktrace_ops *ops,
22 void *data,
23 unsigned long *end,
24 int *graph);
25
26 extern unsigned long
27 print_context_stack(struct task_struct *task,
28 unsigned long *stack, unsigned long bp,
29 const struct stacktrace_ops *ops, void *data,
30 unsigned long *end, int *graph);
31
32 extern unsigned long
33 print_context_stack_bp(struct task_struct *task,
34 unsigned long *stack, unsigned long bp,
35 const struct stacktrace_ops *ops, void *data,
36 unsigned long *end, int *graph);
37
38 /* Generic stack tracer with callbacks */
39
40 struct stacktrace_ops {
41 int (*address)(void *data, unsigned long address, int reliable);
42 /* On negative return stop dumping */
43 int (*stack)(void *data, char *name);
44 walk_stack_t walk_stack;
45 };
46
47 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
48 unsigned long *stack, unsigned long bp,
49 const struct stacktrace_ops *ops, void *data);
50
51 #ifdef CONFIG_X86_32
52 #define STACKSLOTS_PER_LINE 8
53 #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :)
54 #else
55 #define STACKSLOTS_PER_LINE 4
56 #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
57 #endif
58
59 #ifdef CONFIG_FRAME_POINTER
60 static inline unsigned long
61 stack_frame(struct task_struct *task, struct pt_regs *regs)
62 {
63 unsigned long bp;
64
65 if (regs)
66 return regs->bp;
67
68 if (task == current) {
69 /* Grab bp right from our regs */
70 get_bp(bp);
71 return bp;
72 }
73
74 return ((struct inactive_task_frame *)task->thread.sp)->bp;
75 }
76 #else
77 static inline unsigned long
78 stack_frame(struct task_struct *task, struct pt_regs *regs)
79 {
80 return 0;
81 }
82 #endif
83
84 extern void
85 show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
86 unsigned long *stack, unsigned long bp, char *log_lvl);
87
88 extern void
89 show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
90 unsigned long *sp, unsigned long bp, char *log_lvl);
91
92 extern unsigned int code_bytes;
93
94 /* The form of the top of the frame on the stack */
95 struct stack_frame {
96 struct stack_frame *next_frame;
97 unsigned long return_address;
98 };
99
100 struct stack_frame_ia32 {
101 u32 next_frame;
102 u32 return_address;
103 };
104
105 static inline unsigned long caller_frame_pointer(void)
106 {
107 struct stack_frame *frame;
108
109 get_bp(frame);
110
111 #ifdef CONFIG_FRAME_POINTER
112 frame = frame->next_frame;
113 #endif
114
115 return (unsigned long)frame;
116 }
117
118 #endif /* _ASM_X86_STACKTRACE_H */