4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
11 #include <linux/oprofile.h>
12 #include <linux/sched.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>
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
;
30 bytes
= copy_from_user_nmi(bufhead
, head
, sizeof(bufhead
));
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) */
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
))
55 head
= (struct stack_frame_ia32
*) regs
->bp
;
56 while (depth
-- && head
)
57 head
= dump_user_backtrace_32(head
);
64 x86_backtrace_32(struct pt_regs
* const regs
, unsigned int depth
)
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];
76 bytes
= copy_from_user_nmi(bufhead
, head
, sizeof(bufhead
));
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
)
87 return bufhead
[0].next_frame
;
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
;
102 oprofile_add_trace(regs
->ip
);
107 for (unwind_start(&state
, current
, regs
, NULL
);
108 !unwind_done(&state
); unwind_next_frame(&state
)) {
109 addr
= unwind_get_return_address(&state
);
113 oprofile_add_trace(addr
);
122 if (x86_backtrace_32(regs
, depth
))
125 while (depth
-- && head
)
126 head
= dump_user_backtrace(head
);