Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / metag / oprofile / backtrace.c
blob7cc3f37cb40e4653a0bd5daae1107f9b3e1ff45b
1 /*
2 * Copyright (C) 2010-2013 Imagination Technologies Ltd.
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
9 #include <linux/oprofile.h>
10 #include <linux/uaccess.h>
11 #include <asm/processor.h>
12 #include <asm/stacktrace.h>
14 #include "backtrace.h"
16 static void user_backtrace_fp(unsigned long __user *fp, unsigned int depth)
18 while (depth-- && access_ok(VERIFY_READ, fp, 8)) {
19 unsigned long addr;
20 unsigned long __user *fpnew;
21 if (__copy_from_user_inatomic(&addr, fp + 1, sizeof(addr)))
22 break;
23 addr -= 4;
25 oprofile_add_trace(addr);
27 /* stack grows up, so frame pointers must decrease */
28 if (__copy_from_user_inatomic(&fpnew, fp + 0, sizeof(fpnew)))
29 break;
30 if (fpnew >= fp)
31 break;
32 fp = fpnew;
36 static int kernel_backtrace_frame(struct stackframe *frame, void *data)
38 unsigned int *depth = data;
40 oprofile_add_trace(frame->pc);
42 /* decrement depth and stop if we reach 0 */
43 if ((*depth)-- == 0)
44 return 1;
46 /* otherwise onto the next frame */
47 return 0;
50 void metag_backtrace(struct pt_regs * const regs, unsigned int depth)
52 if (user_mode(regs)) {
53 unsigned long *fp = (unsigned long *)regs->ctx.AX[1].U0;
54 user_backtrace_fp((unsigned long __user __force *)fp, depth);
55 } else {
56 struct stackframe frame;
57 frame.fp = regs->ctx.AX[1].U0; /* A0FrP */
58 frame.sp = user_stack_pointer(regs); /* A0StP */
59 frame.lr = 0; /* from stack */
60 frame.pc = regs->ctx.CurrPC; /* PC */
61 walk_stackframe(&frame, &kernel_backtrace_frame, &depth);