arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / x86 / oprofile / backtrace.c
bloba2488b6e27d6c20aefcfff006ae63da03eec9b22
1 /**
2 * @file backtrace.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon
8 * @author David Smith
9 */
11 #include <linux/oprofile.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/compat.h>
15 #include <linux/uaccess.h>
17 #include <asm/ptrace.h>
18 #include <asm/stacktrace.h>
19 #include <asm/unwind.h>
21 #ifdef CONFIG_COMPAT
22 static struct stack_frame_ia32 *
23 dump_user_backtrace_32(struct stack_frame_ia32 *head)
25 /* Also check accessibility of one struct frame_head beyond: */
26 struct stack_frame_ia32 bufhead[2];
27 struct stack_frame_ia32 *fp;
28 unsigned long bytes;
30 bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
31 if (bytes != 0)
32 return NULL;
34 fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
36 oprofile_add_trace(bufhead[0].return_address);
38 /* frame pointers should strictly progress back up the stack
39 * (towards higher addresses) */
40 if (head >= fp)
41 return NULL;
43 return fp;
46 static inline int
47 x86_backtrace_32(struct pt_regs * const regs, unsigned int depth)
49 struct stack_frame_ia32 *head;
51 /* User process is IA32 */
52 if (!current || !test_thread_flag(TIF_IA32))
53 return 0;
55 head = (struct stack_frame_ia32 *) regs->bp;
56 while (depth-- && head)
57 head = dump_user_backtrace_32(head);
59 return 1;
62 #else
63 static inline int
64 x86_backtrace_32(struct pt_regs * const regs, unsigned int depth)
66 return 0;
68 #endif /* CONFIG_COMPAT */
70 static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
72 /* Also check accessibility of one struct frame_head beyond: */
73 struct stack_frame bufhead[2];
74 unsigned long bytes;
76 bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
77 if (bytes != 0)
78 return NULL;
80 oprofile_add_trace(bufhead[0].return_address);
82 /* frame pointers should strictly progress back up the stack
83 * (towards higher addresses) */
84 if (head >= bufhead[0].next_frame)
85 return NULL;
87 return bufhead[0].next_frame;
90 void
91 x86_backtrace(struct pt_regs * const regs, unsigned int depth)
93 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
95 if (!user_mode(regs)) {
96 struct unwind_state state;
97 unsigned long addr;
99 if (!depth)
100 return;
102 oprofile_add_trace(regs->ip);
104 if (!--depth)
105 return;
107 for (unwind_start(&state, current, regs, NULL);
108 !unwind_done(&state); unwind_next_frame(&state)) {
109 addr = unwind_get_return_address(&state);
110 if (!addr)
111 break;
113 oprofile_add_trace(addr);
115 if (!--depth)
116 break;
119 return;
122 if (x86_backtrace_32(regs, depth))
123 return;
125 while (depth-- && head)
126 head = dump_user_backtrace(head);