blob: cbf1dd5372b2d223f399ab884fd46bfbd83246d1 [file] [log] [blame]
Paul Mundtac4fac82009-10-13 13:10:14 +09001/*
2 * arch/sh/kernel/return_address.c
3 *
4 * Copyright (C) 2009 Matt Fleming
5 * Copyright (C) 2009 Paul Mundt
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/kernel.h>
Paul Mundt5dd6ef52010-04-02 16:02:33 +090012#include <linux/module.h>
Paul Mundtac4fac82009-10-13 13:10:14 +090013#include <asm/dwarf.h>
14
15#ifdef CONFIG_DWARF_UNWINDER
16
17void *return_address(unsigned int depth)
18{
19 struct dwarf_frame *frame;
20 unsigned long ra;
21 int i;
22
23 for (i = 0, frame = NULL, ra = 0; i <= depth; i++) {
24 struct dwarf_frame *tmp;
25
26 tmp = dwarf_unwind_stack(ra, frame);
27
28 if (frame)
29 dwarf_free_frame(frame);
30
31 frame = tmp;
32
33 if (!frame || !frame->return_addr)
34 break;
35
36 ra = frame->return_addr;
37 }
38
39 /* Failed to unwind the stack to the specified depth. */
40 WARN_ON(i != depth + 1);
41
42 if (frame)
43 dwarf_free_frame(frame);
44
45 return (void *)ra;
46}
47
48#else
49
50void *return_address(unsigned int depth)
51{
52 return NULL;
53}
54
55#endif
Paul Mundt5dd6ef52010-04-02 16:02:33 +090056
57EXPORT_SYMBOL_GPL(return_address);