Skip to content

Commit b346103

Browse files
Paolo 'Blaisorblade' GiarrussoLinus Torvalds
authored andcommitted
[PATCH] uml: stack dump fix
Copy (and adapt) to UML the stack code dumper used in i386 when CONFIG_FRAME_POINTER is enabled. Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 37fce85 commit b346103

6 files changed

Lines changed: 100 additions & 36 deletions

File tree

‎arch/um/include/sysrq.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef __UM_SYSRQ_H
22
#define __UM_SYSRQ_H
33

4-
extern void show_trace(unsigned long *stack);
4+
struct task_struct;
5+
extern void show_trace(struct task_struct* task, unsigned long *stack);
56

67
#endif

‎arch/um/kernel/sysrq.c‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the GPL
44
*/
55

6+
#include "linux/config.h"
67
#include "linux/sched.h"
78
#include "linux/kernel.h"
89
#include "linux/module.h"
@@ -12,14 +13,14 @@
1213
#include "sysrq.h"
1314
#include "user_util.h"
1415

15-
void show_trace(unsigned long * stack)
16+
/* Catch non-i386 SUBARCH's. */
17+
#if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT)
18+
void show_trace(struct task_struct *task, unsigned long * stack)
1619
{
17-
/* XXX: Copy the CONFIG_FRAME_POINTER stack-walking backtrace from
18-
* arch/i386/kernel/traps.c, and then move this to sys-i386/sysrq.c.*/
1920
unsigned long addr;
2021

2122
if (!stack) {
22-
stack = (unsigned long*) &stack;
23+
stack = (unsigned long*) &stack;
2324
WARN_ON(1);
2425
}
2526

@@ -35,6 +36,7 @@ void show_trace(unsigned long * stack)
3536
}
3637
printk("\n");
3738
}
39+
#endif
3840

3941
/*
4042
* stack dumps generator - this is used by arch-independent code.
@@ -44,7 +46,7 @@ void dump_stack(void)
4446
{
4547
unsigned long stack;
4648

47-
show_trace(&stack);
49+
show_trace(current, &stack);
4850
}
4951
EXPORT_SYMBOL(dump_stack);
5052

@@ -59,7 +61,11 @@ void show_stack(struct task_struct *task, unsigned long *esp)
5961
int i;
6062

6163
if (esp == NULL) {
62-
if (task != current) {
64+
if (task != current && task != NULL) {
65+
/* XXX: Isn't this bogus? I.e. isn't this the
66+
* *userspace* stack of this task? If not so, use this
67+
* even when task == current (as in i386).
68+
*/
6369
esp = (unsigned long *) KSTK_ESP(task);
6470
/* Which one? No actual difference - just coding style.*/
6571
//esp = (unsigned long *) PT_REGS_IP(&task->thread.regs);
@@ -77,5 +83,6 @@ void show_stack(struct task_struct *task, unsigned long *esp)
7783
printk("%08lx ", *stack++);
7884
}
7985

80-
show_trace(esp);
86+
printk("Call Trace: \n");
87+
show_trace(current, esp);
8188
}

‎arch/um/sys-i386/sysrq.c‎

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
* Licensed under the GPL
44
*/
55

6+
#include "linux/config.h"
67
#include "linux/kernel.h"
78
#include "linux/smp.h"
89
#include "linux/sched.h"
10+
#include "linux/kallsyms.h"
911
#include "asm/ptrace.h"
1012
#include "sysrq.h"
1113

14+
/* This is declared by <linux/sched.h> */
1215
void show_regs(struct pt_regs *regs)
1316
{
1417
printk("\n");
@@ -31,5 +34,80 @@ void show_regs(struct pt_regs *regs)
3134
0xffff & PT_REGS_DS(regs),
3235
0xffff & PT_REGS_ES(regs));
3336

34-
show_trace((unsigned long *) &regs);
37+
show_trace(NULL, (unsigned long *) &regs);
3538
}
39+
40+
/* Copied from i386. */
41+
static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
42+
{
43+
return p > (void *)tinfo &&
44+
p < (void *)tinfo + THREAD_SIZE - 3;
45+
}
46+
47+
/* Adapted from i386 (we also print the address we read from). */
48+
static inline unsigned long print_context_stack(struct thread_info *tinfo,
49+
unsigned long *stack, unsigned long ebp)
50+
{
51+
unsigned long addr;
52+
53+
#ifdef CONFIG_FRAME_POINTER
54+
while (valid_stack_ptr(tinfo, (void *)ebp)) {
55+
addr = *(unsigned long *)(ebp + 4);
56+
printk("%08lx: [<%08lx>]", ebp + 4, addr);
57+
print_symbol(" %s", addr);
58+
printk("\n");
59+
ebp = *(unsigned long *)ebp;
60+
}
61+
#else
62+
while (valid_stack_ptr(tinfo, stack)) {
63+
addr = *stack;
64+
if (__kernel_text_address(addr)) {
65+
printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
66+
print_symbol(" %s", addr);
67+
printk("\n");
68+
}
69+
stack++;
70+
}
71+
#endif
72+
return ebp;
73+
}
74+
75+
void show_trace(struct task_struct* task, unsigned long * stack)
76+
{
77+
unsigned long ebp;
78+
struct thread_info *context;
79+
80+
/* Turn this into BUG_ON if possible. */
81+
if (!stack) {
82+
stack = (unsigned long*) &stack;
83+
printk("show_trace: got NULL stack, implicit assumption task == current");
84+
WARN_ON(1);
85+
}
86+
87+
if (!task)
88+
task = current;
89+
90+
if (task != current) {
91+
//ebp = (unsigned long) KSTK_EBP(task);
92+
/* Which one? No actual difference - just coding style.*/
93+
ebp = (unsigned long) PT_REGS_EBP(&task->thread.regs);
94+
} else {
95+
asm ("movl %%ebp, %0" : "=r" (ebp) : );
96+
}
97+
98+
context = (struct thread_info *)
99+
((unsigned long)stack & (~(THREAD_SIZE - 1)));
100+
print_context_stack(context, stack, ebp);
101+
102+
/*while (((long) stack & (THREAD_SIZE-1)) != 0) {
103+
addr = *stack;
104+
if (__kernel_text_address(addr)) {
105+
printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
106+
print_symbol(" %s", addr);
107+
printk("\n");
108+
}
109+
stack++;
110+
}*/
111+
printk("\n");
112+
}
113+

‎arch/um/sys-ppc/sysrq.c‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,5 @@ void show_regs(struct pt_regs_subarch *regs)
2727
0xffff & regs->xds, 0xffff & regs->xes);
2828
#endif
2929

30-
show_trace(&regs->gpr[1]);
30+
show_trace(current, &regs->gpr[1]);
3131
}
32-
33-
34-
/*
35-
* Overrides for Emacs so that we follow Linus's tabbing style.
36-
* Emacs will notice this stuff at the end of the file and automatically
37-
* adjust the settings for this buffer only. This must remain at the end
38-
* of the file.
39-
* ---------------------------------------------------------------------------
40-
* Local variables:
41-
* c-file-style: "linux"
42-
* End:
43-
*/

‎arch/um/sys-x86_64/sysrq.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,5 @@ void __show_regs(struct pt_regs * regs)
3636
void show_regs(struct pt_regs *regs)
3737
{
3838
__show_regs(regs);
39-
show_trace((unsigned long *) &regs);
39+
show_trace(current, (unsigned long *) &regs);
4040
}
41-
42-
/* Emacs will notice this stuff at the end of the file and automatically
43-
* adjust the settings for this buffer only. This must remain at the end
44-
* of the file.
45-
* ---------------------------------------------------------------------------
46-
* Local variables:
47-
* c-file-style: "linux"
48-
* End:
49-
*/

‎include/asm-um/thread_info.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@ struct thread_info {
4141
#define init_thread_info (init_thread_union.thread_info)
4242
#define init_stack (init_thread_union.stack)
4343

44+
#define THREAD_SIZE ((1 << CONFIG_KERNEL_STACK_ORDER) * PAGE_SIZE)
4445
/* how to get the thread information struct from C */
4546
static inline struct thread_info *current_thread_info(void)
4647
{
4748
struct thread_info *ti;
48-
unsigned long mask = PAGE_SIZE *
49-
(1 << CONFIG_KERNEL_STACK_ORDER) - 1;
50-
ti = (struct thread_info *) (((unsigned long) &ti) & ~mask);
49+
unsigned long mask = THREAD_SIZE - 1;
50+
ti = (struct thread_info *) (((unsigned long) &ti) & ~mask);
5151
return ti;
5252
}
5353

5454
/* thread information allocation */
55-
#define THREAD_SIZE ((1 << CONFIG_KERNEL_STACK_ORDER) * PAGE_SIZE)
5655
#define alloc_thread_info(tsk) \
5756
((struct thread_info *) kmalloc(THREAD_SIZE, GFP_KERNEL))
5857
#define free_thread_info(ti) kfree(ti)

0 commit comments

Comments
 (0)