This source file includes following definitions.
- select_unwinder
- unwinder_enqueue
- unwinder_register
- unwind_stack
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/errno.h>
13 #include <linux/list.h>
14 #include <linux/spinlock.h>
15 #include <linux/module.h>
16 #include <asm/unwinder.h>
17 #include <linux/atomic.h>
18
19
20
21
22
23
24
25
26
27
28 static struct list_head unwinder_list;
29 static struct unwinder stack_reader = {
30 .name = "stack-reader",
31 .dump = stack_reader_dump,
32 .rating = 50,
33 .list = {
34 .next = &unwinder_list,
35 .prev = &unwinder_list,
36 },
37 };
38
39
40
41
42
43
44
45
46
47
48
49 static struct unwinder *curr_unwinder = &stack_reader;
50
51 static struct list_head unwinder_list = {
52 .next = &stack_reader.list,
53 .prev = &stack_reader.list,
54 };
55
56 static DEFINE_SPINLOCK(unwinder_lock);
57
58
59
60
61
62
63
64
65
66 static struct unwinder *select_unwinder(void)
67 {
68 struct unwinder *best;
69
70 if (list_empty(&unwinder_list))
71 return NULL;
72
73 best = list_entry(unwinder_list.next, struct unwinder, list);
74 if (best == curr_unwinder)
75 return NULL;
76
77 return best;
78 }
79
80
81
82
83 static int unwinder_enqueue(struct unwinder *ops)
84 {
85 struct list_head *tmp, *entry = &unwinder_list;
86
87 list_for_each(tmp, &unwinder_list) {
88 struct unwinder *o;
89
90 o = list_entry(tmp, struct unwinder, list);
91 if (o == ops)
92 return -EBUSY;
93
94 if (o->rating >= ops->rating)
95 entry = tmp;
96 }
97 list_add(&ops->list, entry);
98
99 return 0;
100 }
101
102
103
104
105
106
107
108
109
110
111 int unwinder_register(struct unwinder *u)
112 {
113 unsigned long flags;
114 int ret;
115
116 spin_lock_irqsave(&unwinder_lock, flags);
117 ret = unwinder_enqueue(u);
118 if (!ret)
119 curr_unwinder = select_unwinder();
120 spin_unlock_irqrestore(&unwinder_lock, flags);
121
122 return ret;
123 }
124
125 int unwinder_faulted = 0;
126
127
128
129
130
131
132 void unwind_stack(struct task_struct *task, struct pt_regs *regs,
133 unsigned long *sp, const struct stacktrace_ops *ops,
134 void *data)
135 {
136 unsigned long flags;
137
138
139
140
141
142
143
144
145
146
147
148
149 if (unwinder_faulted) {
150 spin_lock_irqsave(&unwinder_lock, flags);
151
152
153 if (unwinder_faulted && !list_is_singular(&unwinder_list)) {
154 list_del(&curr_unwinder->list);
155 curr_unwinder = select_unwinder();
156
157 unwinder_faulted = 0;
158 }
159
160 spin_unlock_irqrestore(&unwinder_lock, flags);
161 }
162
163 curr_unwinder->dump(task, regs, sp, ops, data);
164 }
165 EXPORT_SYMBOL_GPL(unwind_stack);