2 * Stack trace management functions
4 * Copyright IBM Corp. 2006
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
8 #include <linux/sched.h>
9 #include <linux/sched/debug.h>
10 #include <linux/stacktrace.h>
11 #include <linux/kallsyms.h>
12 #include <linux/export.h>
14 static int __save_address(void *data
, unsigned long address
, int nosched
)
16 struct stack_trace
*trace
= data
;
18 if (nosched
&& in_sched_functions(address
))
20 if (trace
->skip
> 0) {
24 if (trace
->nr_entries
< trace
->max_entries
) {
25 trace
->entries
[trace
->nr_entries
++] = address
;
31 static int save_address(void *data
, unsigned long address
, int reliable
)
33 return __save_address(data
, address
, 0);
36 static int save_address_nosched(void *data
, unsigned long address
, int reliable
)
38 return __save_address(data
, address
, 1);
41 void save_stack_trace(struct stack_trace
*trace
)
45 sp
= current_stack_pointer();
46 dump_trace(save_address
, trace
, NULL
, sp
);
47 if (trace
->nr_entries
< trace
->max_entries
)
48 trace
->entries
[trace
->nr_entries
++] = ULONG_MAX
;
50 EXPORT_SYMBOL_GPL(save_stack_trace
);
52 void save_stack_trace_tsk(struct task_struct
*tsk
, struct stack_trace
*trace
)
58 sp
= current_stack_pointer();
59 dump_trace(save_address_nosched
, trace
, tsk
, sp
);
60 if (trace
->nr_entries
< trace
->max_entries
)
61 trace
->entries
[trace
->nr_entries
++] = ULONG_MAX
;
63 EXPORT_SYMBOL_GPL(save_stack_trace_tsk
);
65 void save_stack_trace_regs(struct pt_regs
*regs
, struct stack_trace
*trace
)
69 sp
= kernel_stack_pointer(regs
);
70 dump_trace(save_address
, trace
, NULL
, sp
);
71 if (trace
->nr_entries
< trace
->max_entries
)
72 trace
->entries
[trace
->nr_entries
++] = ULONG_MAX
;
74 EXPORT_SYMBOL_GPL(save_stack_trace_regs
);