1 // SPDX-License-Identifier: GPL-2.0-only
3 * arch/arm/kernel/return_address.c
5 * Copyright (C) 2009 Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
8 #include <linux/export.h>
9 #include <linux/ftrace.h>
10 #include <linux/sched.h>
12 #include <asm/stacktrace.h>
14 struct return_address_data
{
19 static int save_return_addr(struct stackframe
*frame
, void *d
)
21 struct return_address_data
*data
= d
;
24 data
->addr
= (void *)frame
->pc
;
33 void *return_address(unsigned int level
)
35 struct return_address_data data
;
36 struct stackframe frame
;
38 data
.level
= level
+ 2;
41 frame
.fp
= (unsigned long)__builtin_frame_address(0);
42 frame
.sp
= current_stack_pointer
;
43 frame
.lr
= (unsigned long)__builtin_return_address(0);
44 frame
.pc
= (unsigned long)return_address
;
46 walk_stackframe(&frame
, save_return_addr
, &data
);
54 EXPORT_SYMBOL_GPL(return_address
);