Linux 3.17-rc2
[linux/fpc-iii.git] / arch / arm64 / kernel / return_address.c
blob89102a6ffad58899940123854da556ee59844daf
1 /*
2 * arch/arm64/kernel/return_address.c
4 * Copyright (C) 2013 Linaro Limited
5 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/export.h>
13 #include <linux/ftrace.h>
15 #include <asm/stacktrace.h>
17 struct return_address_data {
18 unsigned int level;
19 void *addr;
22 static int save_return_addr(struct stackframe *frame, void *d)
24 struct return_address_data *data = d;
26 if (!data->level) {
27 data->addr = (void *)frame->pc;
28 return 1;
29 } else {
30 --data->level;
31 return 0;
35 void *return_address(unsigned int level)
37 struct return_address_data data;
38 struct stackframe frame;
39 register unsigned long current_sp asm ("sp");
41 data.level = level + 2;
42 data.addr = NULL;
44 frame.fp = (unsigned long)__builtin_frame_address(0);
45 frame.sp = current_sp;
46 frame.pc = (unsigned long)return_address; /* dummy */
48 walk_stackframe(&frame, save_return_addr, &data);
50 if (!data.level)
51 return data.addr;
52 else
53 return NULL;
55 EXPORT_SYMBOL_GPL(return_address);