1 /* 2 * arch/arm64/kernel/return_address.c 3 * 4 * Copyright (C) 2013 Linaro Limited 5 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org> 6 * 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. 10 */ 11 12 #include <linux/export.h> 13 #include <linux/ftrace.h> 14 #include <linux/kprobes.h> 15 16 #include <asm/stack_pointer.h> 17 #include <asm/stacktrace.h> 18 19 struct return_address_data { 20 unsigned int level; 21 void *addr; 22 }; 23 save_return_addr(struct stackframe * frame,void * d)24static int save_return_addr(struct stackframe *frame, void *d) 25 { 26 struct return_address_data *data = d; 27 28 if (!data->level) { 29 data->addr = (void *)frame->pc; 30 return 1; 31 } else { 32 --data->level; 33 return 0; 34 } 35 } 36 NOKPROBE_SYMBOL(save_return_addr); 37 return_address(unsigned int level)38void *return_address(unsigned int level) 39 { 40 struct return_address_data data; 41 struct stackframe frame; 42 43 data.level = level + 2; 44 data.addr = NULL; 45 46 frame.fp = (unsigned long)__builtin_frame_address(0); 47 frame.pc = (unsigned long)return_address; /* dummy */ 48 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 49 frame.graph = current->curr_ret_stack; 50 #endif 51 52 walk_stackframe(current, &frame, save_return_addr, &data); 53 54 if (!data.level) 55 return data.addr; 56 else 57 return NULL; 58 } 59 EXPORT_SYMBOL_GPL(return_address); 60 NOKPROBE_SYMBOL(return_address); 61