Linux 4.18.10
[linux/fpc-iii.git] / arch / sh / kernel / return_address.c
blob5124aeb28c3f333d9b7ff7755d8f01e738a044d1
1 /*
2 * arch/sh/kernel/return_address.c
4 * Copyright (C) 2009 Matt Fleming
5 * Copyright (C) 2009 Paul Mundt
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.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <asm/dwarf.h>
15 #ifdef CONFIG_DWARF_UNWINDER
17 void *return_address(unsigned int depth)
19 struct dwarf_frame *frame;
20 unsigned long ra;
21 int i;
23 for (i = 0, frame = NULL, ra = 0; i <= depth; i++) {
24 struct dwarf_frame *tmp;
26 tmp = dwarf_unwind_stack(ra, frame);
27 if (!tmp)
28 return NULL;
30 if (frame)
31 dwarf_free_frame(frame);
33 frame = tmp;
35 if (!frame || !frame->return_addr)
36 break;
38 ra = frame->return_addr;
41 /* Failed to unwind the stack to the specified depth. */
42 WARN_ON(i != depth + 1);
44 if (frame)
45 dwarf_free_frame(frame);
47 return (void *)ra;
50 #else
52 void *return_address(unsigned int depth)
54 return NULL;
57 #endif
59 EXPORT_SYMBOL_GPL(return_address);