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/stacktrace.h>
10 #include <linux/kallsyms.h>
11 #include <linux/module.h>
13 static unsigned long save_context_stack(struct stack_trace *trace,
19 struct stack_frame *sf;
24 if (sp < low || sp > high)
26 sf = (struct stack_frame *)sp;
30 trace->entries[trace->nr_entries++] = addr;
33 if (trace->nr_entries >= trace->max_entries)
39 if (sp <= low || sp > high - sizeof(*sf))
41 sf = (struct stack_frame *)sp;
43 /* Zero backchain detected, check for interrupt frame. */
44 sp = (unsigned long)(sf + 1);
45 if (sp <= low || sp > high - sizeof(*regs))
47 regs = (struct pt_regs *)sp;
48 addr = regs->psw.addr;
49 if (savesched || !in_sched_functions(addr)) {
51 trace->entries[trace->nr_entries++] = addr;
55 if (trace->nr_entries >= trace->max_entries)
62 void save_stack_trace(struct stack_trace *trace)
64 register unsigned long sp asm ("15");
65 unsigned long orig_sp, new_sp, frame_size;
67 frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
69 new_sp = save_context_stack(trace, orig_sp,
70 S390_lowcore.panic_stack + frame_size - PAGE_SIZE,
71 S390_lowcore.panic_stack + frame_size, 1);
72 if (new_sp != orig_sp)
74 new_sp = save_context_stack(trace, new_sp,
75 S390_lowcore.async_stack + frame_size - ASYNC_SIZE,
76 S390_lowcore.async_stack + frame_size, 1);
77 if (new_sp != orig_sp)
79 save_context_stack(trace, new_sp,
80 S390_lowcore.thread_info,
81 S390_lowcore.thread_info + THREAD_SIZE, 1);
83 EXPORT_SYMBOL_GPL(save_stack_trace);
85 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
87 unsigned long sp, low, high;
91 /* Get current stack pointer. */
92 asm volatile("la %0,0(15)" : "=a" (sp));
94 low = (unsigned long) task_stack_page(tsk);
95 high = (unsigned long) task_pt_regs(tsk);
96 save_context_stack(trace, sp, low, high, 0);
97 if (trace->nr_entries < trace->max_entries)
98 trace->entries[trace->nr_entries++] = ULONG_MAX;
100 EXPORT_SYMBOL_GPL(save_stack_trace_tsk);