1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/kernel/return_address.c
5 * Copyright (C) 2009 Matt Fleming
6 * Copyright (C) 2009 Paul Mundt
8 #include <linux/kernel.h>
9 #include <linux/module.h>
11 #include <asm/dwarf.h>
12 #include <asm/ftrace.h>
14 #ifdef CONFIG_DWARF_UNWINDER
16 void *return_address(unsigned int depth
)
18 struct dwarf_frame
*frame
;
22 for (i
= 0, frame
= NULL
, ra
= 0; i
<= depth
; i
++) {
23 struct dwarf_frame
*tmp
;
25 tmp
= dwarf_unwind_stack(ra
, frame
);
30 dwarf_free_frame(frame
);
34 if (!frame
|| !frame
->return_addr
)
37 ra
= frame
->return_addr
;
40 /* Failed to unwind the stack to the specified depth. */
41 WARN_ON(i
!= depth
+ 1);
44 dwarf_free_frame(frame
);
51 void *return_address(unsigned int depth
)
58 EXPORT_SYMBOL_GPL(return_address
);