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>
11 #if defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND)
12 #include <linux/sched.h>
14 #include <asm/stacktrace.h>
16 struct return_address_data
{
21 static int save_return_addr(struct stackframe
*frame
, void *d
)
23 struct return_address_data
*data
= d
;
26 data
->addr
= (void *)frame
->pc
;
35 void *return_address(unsigned int level
)
37 struct return_address_data data
;
38 struct stackframe frame
;
40 data
.level
= level
+ 2;
43 frame
.fp
= (unsigned long)__builtin_frame_address(0);
44 frame
.sp
= current_stack_pointer
;
45 frame
.lr
= (unsigned long)__builtin_return_address(0);
46 frame
.pc
= (unsigned long)return_address
;
48 walk_stackframe(&frame
, save_return_addr
, &data
);
56 #endif /* if defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND) */
58 EXPORT_SYMBOL_GPL(return_address
);