| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* arch/sh/kernel/return_address.c |
| 4 |
* |
| 5 |
* Copyright (C) 2009 Matt Fleming |
| 6 |
* Copyright (C) 2009 Paul Mundt |
| 7 |
*/ |
| 8 |
#include <linux/kernel.h> |
| 9 |
#include <linux/module.h> |
| 10 |
|
| 11 |
#include <asm/dwarf.h> |
| 12 |
#include <asm/ftrace.h> |
| 13 |
|
| 14 |
#ifdef CONFIG_DWARF_UNWINDER |
| 15 |
|
| 16 |
void *return_address(unsigned int depth) |
| 17 |
{ |
| 18 |
struct dwarf_frame *frame; |
| 19 |
unsigned long ra; |
| 20 |
int i; |
| 21 |
|
| 22 |
for (i = 0, frame = NULL, ra = 0; i <= depth; i++) { |
| 23 |
struct dwarf_frame *tmp; |
| 24 |
|
| 25 |
tmp = dwarf_unwind_stack(ra, frame); |
| 26 |
if (!tmp) |
| 27 |
return NULL; |
| 28 |
|
| 29 |
if (frame) |
| 30 |
dwarf_free_frame(frame); |
| 31 |
|
| 32 |
frame = tmp; |
| 33 |
|
| 34 |
if (!frame || !frame->return_addr) |
| 35 |
break; |
| 36 |
|
| 37 |
ra = frame->return_addr; |
| 38 |
} |
| 39 |
|
| 40 |
/* Failed to unwind the stack to the specified depth. */ |
| 41 |
WARN_ON(i != depth + 1); |
| 42 |
|
| 43 |
if (frame) |
| 44 |
dwarf_free_frame(frame); |
| 45 |
|
| 46 |
return (void *)ra; |
| 47 |
} |
| 48 |
|
| 49 |
#else |
| 50 |
|
| 51 |
void *return_address(unsigned int depth) |
| 52 |
{ |
| 53 |
return NULL; |
| 54 |
} |
| 55 |
|
| 56 |
#endif |
| 57 |
|
| 58 |
EXPORT_SYMBOL_GPL(return_address); |