2 * SH specific backtracing code for oprofile
4 * Copyright 2007 STMicroelectronics Ltd.
6 * Author: Dave Peverley <dpeverley@mpc-data.co.uk>
8 * Based on ARM oprofile backtrace code by Richard Purdie and in turn, i386
9 * oprofile backtrace code by John Levon, David Smith
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/oprofile.h>
17 #include <linux/sched.h>
18 #include <linux/kallsyms.h>
20 #include <asm/unwinder.h>
21 #include <asm/ptrace.h>
22 #include <linux/uaccess.h>
23 #include <asm/sections.h>
24 #include <asm/stacktrace.h>
26 static int backtrace_stack(void *data
, char *name
)
28 /* Yes, we want all stacks */
32 static void backtrace_address(void *data
, unsigned long addr
, int reliable
)
34 unsigned int *depth
= data
;
37 oprofile_add_trace(addr
);
40 static struct stacktrace_ops backtrace_ops
= {
41 .stack
= backtrace_stack
,
42 .address
= backtrace_address
,
45 /* Limit to stop backtracing too far. */
46 static int backtrace_limit
= 20;
48 static unsigned long *
49 user_backtrace(unsigned long *stackaddr
, struct pt_regs
*regs
)
51 unsigned long buf_stack
;
53 /* Also check accessibility of address */
54 if (!access_ok(VERIFY_READ
, stackaddr
, sizeof(unsigned long)))
57 if (__copy_from_user_inatomic(&buf_stack
, stackaddr
, sizeof(unsigned long)))
60 /* Quick paranoia check */
64 oprofile_add_trace(buf_stack
);
71 void sh_backtrace(struct pt_regs
* const regs
, unsigned int depth
)
73 unsigned long *stackaddr
;
76 * Paranoia - clip max depth as we could get lost in the weeds.
78 if (depth
> backtrace_limit
)
79 depth
= backtrace_limit
;
81 stackaddr
= (unsigned long *)kernel_stack_pointer(regs
);
82 if (!user_mode(regs
)) {
84 unwind_stack(NULL
, regs
, stackaddr
,
85 &backtrace_ops
, &depth
);
89 while (depth
-- && (stackaddr
!= NULL
))
90 stackaddr
= user_backtrace(stackaddr
, regs
);