]>
Commit | Line | Data |
---|---|---|
2f026037 HS |
1 | /* |
2 | * Stack trace management functions | |
3 | * | |
4 | * Copyright (C) 2007 Atmel Corporation | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | #include <linux/sched.h> | |
68db0cf1 | 11 | #include <linux/sched/task_stack.h> |
2f026037 HS |
12 | #include <linux/stacktrace.h> |
13 | #include <linux/thread_info.h> | |
8b95d917 | 14 | #include <linux/module.h> |
2f026037 HS |
15 | |
16 | register unsigned long current_frame_pointer asm("r7"); | |
17 | ||
18 | struct stackframe { | |
19 | unsigned long lr; | |
20 | unsigned long fp; | |
21 | }; | |
22 | ||
23 | /* | |
24 | * Save stack-backtrace addresses into a stack_trace buffer. | |
25 | */ | |
26 | void save_stack_trace(struct stack_trace *trace) | |
27 | { | |
28 | unsigned long low, high; | |
29 | unsigned long fp; | |
30 | struct stackframe *frame; | |
31 | int skip = trace->skip; | |
32 | ||
33 | low = (unsigned long)task_stack_page(current); | |
34 | high = low + THREAD_SIZE; | |
35 | fp = current_frame_pointer; | |
36 | ||
37 | while (fp >= low && fp <= (high - 8)) { | |
38 | frame = (struct stackframe *)fp; | |
39 | ||
40 | if (skip) { | |
41 | skip--; | |
42 | } else { | |
43 | trace->entries[trace->nr_entries++] = frame->lr; | |
44 | if (trace->nr_entries >= trace->max_entries) | |
45 | break; | |
46 | } | |
47 | ||
48 | /* | |
49 | * The next frame must be at a higher address than the | |
50 | * current frame. | |
51 | */ | |
52 | low = fp + 8; | |
53 | fp = frame->fp; | |
54 | } | |
55 | } | |
7b4c9505 | 56 | EXPORT_SYMBOL_GPL(save_stack_trace); |