~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/stacktrace.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /kernel/stacktrace.c (Version linux-6.12-rc7) and /kernel/stacktrace.c (Version linux-5.11.22)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * kernel/stacktrace.c                              3  * kernel/stacktrace.c
  4  *                                                  4  *
  5  * Stack trace management functions                 5  * Stack trace management functions
  6  *                                                  6  *
  7  *  Copyright (C) 2006 Red Hat, Inc., Ingo Mol      7  *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  8  */                                                 8  */
  9 #include <linux/sched/task_stack.h>                 9 #include <linux/sched/task_stack.h>
 10 #include <linux/sched/debug.h>                     10 #include <linux/sched/debug.h>
 11 #include <linux/sched.h>                           11 #include <linux/sched.h>
 12 #include <linux/kernel.h>                          12 #include <linux/kernel.h>
 13 #include <linux/export.h>                          13 #include <linux/export.h>
 14 #include <linux/kallsyms.h>                        14 #include <linux/kallsyms.h>
 15 #include <linux/stacktrace.h>                      15 #include <linux/stacktrace.h>
 16 #include <linux/interrupt.h>                   << 
 17                                                    16 
 18 /**                                                17 /**
 19  * stack_trace_print - Print the entries in th     18  * stack_trace_print - Print the entries in the stack trace
 20  * @entries:    Pointer to storage array           19  * @entries:    Pointer to storage array
 21  * @nr_entries: Number of entries in the stora     20  * @nr_entries: Number of entries in the storage array
 22  * @spaces:     Number of leading spaces to pr     21  * @spaces:     Number of leading spaces to print
 23  */                                                22  */
 24 void stack_trace_print(const unsigned long *en     23 void stack_trace_print(const unsigned long *entries, unsigned int nr_entries,
 25                        int spaces)                 24                        int spaces)
 26 {                                                  25 {
 27         unsigned int i;                            26         unsigned int i;
 28                                                    27 
 29         if (WARN_ON(!entries))                     28         if (WARN_ON(!entries))
 30                 return;                            29                 return;
 31                                                    30 
 32         for (i = 0; i < nr_entries; i++)           31         for (i = 0; i < nr_entries; i++)
 33                 printk("%*c%pS\n", 1 + spaces,     32                 printk("%*c%pS\n", 1 + spaces, ' ', (void *)entries[i]);
 34 }                                                  33 }
 35 EXPORT_SYMBOL_GPL(stack_trace_print);              34 EXPORT_SYMBOL_GPL(stack_trace_print);
 36                                                    35 
 37 /**                                                36 /**
 38  * stack_trace_snprint - Print the entries in      37  * stack_trace_snprint - Print the entries in the stack trace into a buffer
 39  * @buf:        Pointer to the print buffer        38  * @buf:        Pointer to the print buffer
 40  * @size:       Size of the print buffer           39  * @size:       Size of the print buffer
 41  * @entries:    Pointer to storage array           40  * @entries:    Pointer to storage array
 42  * @nr_entries: Number of entries in the stora     41  * @nr_entries: Number of entries in the storage array
 43  * @spaces:     Number of leading spaces to pr     42  * @spaces:     Number of leading spaces to print
 44  *                                                 43  *
 45  * Return: Number of bytes printed.                44  * Return: Number of bytes printed.
 46  */                                                45  */
 47 int stack_trace_snprint(char *buf, size_t size     46 int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
 48                         unsigned int nr_entrie     47                         unsigned int nr_entries, int spaces)
 49 {                                                  48 {
 50         unsigned int generated, i, total = 0;      49         unsigned int generated, i, total = 0;
 51                                                    50 
 52         if (WARN_ON(!entries))                     51         if (WARN_ON(!entries))
 53                 return 0;                          52                 return 0;
 54                                                    53 
 55         for (i = 0; i < nr_entries && size; i+     54         for (i = 0; i < nr_entries && size; i++) {
 56                 generated = snprintf(buf, size     55                 generated = snprintf(buf, size, "%*c%pS\n", 1 + spaces, ' ',
 57                                      (void *)e     56                                      (void *)entries[i]);
 58                                                    57 
 59                 total += generated;                58                 total += generated;
 60                 if (generated >= size) {           59                 if (generated >= size) {
 61                         buf += size;               60                         buf += size;
 62                         size = 0;                  61                         size = 0;
 63                 } else {                           62                 } else {
 64                         buf += generated;          63                         buf += generated;
 65                         size -= generated;         64                         size -= generated;
 66                 }                                  65                 }
 67         }                                          66         }
 68                                                    67 
 69         return total;                              68         return total;
 70 }                                                  69 }
 71 EXPORT_SYMBOL_GPL(stack_trace_snprint);            70 EXPORT_SYMBOL_GPL(stack_trace_snprint);
 72                                                    71 
 73 #ifdef CONFIG_ARCH_STACKWALK                       72 #ifdef CONFIG_ARCH_STACKWALK
 74                                                    73 
 75 struct stacktrace_cookie {                         74 struct stacktrace_cookie {
 76         unsigned long   *store;                    75         unsigned long   *store;
 77         unsigned int    size;                      76         unsigned int    size;
 78         unsigned int    skip;                      77         unsigned int    skip;
 79         unsigned int    len;                       78         unsigned int    len;
 80 };                                                 79 };
 81                                                    80 
 82 static bool stack_trace_consume_entry(void *co     81 static bool stack_trace_consume_entry(void *cookie, unsigned long addr)
 83 {                                                  82 {
 84         struct stacktrace_cookie *c = cookie;      83         struct stacktrace_cookie *c = cookie;
 85                                                    84 
 86         if (c->len >= c->size)                     85         if (c->len >= c->size)
 87                 return false;                      86                 return false;
 88                                                    87 
 89         if (c->skip > 0) {                         88         if (c->skip > 0) {
 90                 c->skip--;                         89                 c->skip--;
 91                 return true;                       90                 return true;
 92         }                                          91         }
 93         c->store[c->len++] = addr;                 92         c->store[c->len++] = addr;
 94         return c->len < c->size;                   93         return c->len < c->size;
 95 }                                                  94 }
 96                                                    95 
 97 static bool stack_trace_consume_entry_nosched(     96 static bool stack_trace_consume_entry_nosched(void *cookie, unsigned long addr)
 98 {                                                  97 {
 99         if (in_sched_functions(addr))              98         if (in_sched_functions(addr))
100                 return true;                       99                 return true;
101         return stack_trace_consume_entry(cooki    100         return stack_trace_consume_entry(cookie, addr);
102 }                                                 101 }
103                                                   102 
104 /**                                               103 /**
105  * stack_trace_save - Save a stack trace into     104  * stack_trace_save - Save a stack trace into a storage array
106  * @store:      Pointer to storage array          105  * @store:      Pointer to storage array
107  * @size:       Size of the storage array         106  * @size:       Size of the storage array
108  * @skipnr:     Number of entries to skip at t    107  * @skipnr:     Number of entries to skip at the start of the stack trace
109  *                                                108  *
110  * Return: Number of trace entries stored.        109  * Return: Number of trace entries stored.
111  */                                               110  */
112 unsigned int stack_trace_save(unsigned long *s    111 unsigned int stack_trace_save(unsigned long *store, unsigned int size,
113                               unsigned int ski    112                               unsigned int skipnr)
114 {                                                 113 {
115         stack_trace_consume_fn consume_entry =    114         stack_trace_consume_fn consume_entry = stack_trace_consume_entry;
116         struct stacktrace_cookie c = {            115         struct stacktrace_cookie c = {
117                 .store  = store,                  116                 .store  = store,
118                 .size   = size,                   117                 .size   = size,
119                 .skip   = skipnr + 1,             118                 .skip   = skipnr + 1,
120         };                                        119         };
121                                                   120 
122         arch_stack_walk(consume_entry, &c, cur    121         arch_stack_walk(consume_entry, &c, current, NULL);
123         return c.len;                             122         return c.len;
124 }                                                 123 }
125 EXPORT_SYMBOL_GPL(stack_trace_save);              124 EXPORT_SYMBOL_GPL(stack_trace_save);
126                                                   125 
127 /**                                               126 /**
128  * stack_trace_save_tsk - Save a task stack tr    127  * stack_trace_save_tsk - Save a task stack trace into a storage array
129  * @tsk:        The task to examine            !! 128  * @task:       The task to examine
130  * @store:      Pointer to storage array          129  * @store:      Pointer to storage array
131  * @size:       Size of the storage array         130  * @size:       Size of the storage array
132  * @skipnr:     Number of entries to skip at t    131  * @skipnr:     Number of entries to skip at the start of the stack trace
133  *                                                132  *
134  * Return: Number of trace entries stored.        133  * Return: Number of trace entries stored.
135  */                                               134  */
136 unsigned int stack_trace_save_tsk(struct task_    135 unsigned int stack_trace_save_tsk(struct task_struct *tsk, unsigned long *store,
137                                   unsigned int    136                                   unsigned int size, unsigned int skipnr)
138 {                                                 137 {
139         stack_trace_consume_fn consume_entry =    138         stack_trace_consume_fn consume_entry = stack_trace_consume_entry_nosched;
140         struct stacktrace_cookie c = {            139         struct stacktrace_cookie c = {
141                 .store  = store,                  140                 .store  = store,
142                 .size   = size,                   141                 .size   = size,
143                 /* skip this function if they     142                 /* skip this function if they are tracing us */
144                 .skip   = skipnr + (current ==    143                 .skip   = skipnr + (current == tsk),
145         };                                        144         };
146                                                   145 
147         if (!try_get_task_stack(tsk))             146         if (!try_get_task_stack(tsk))
148                 return 0;                         147                 return 0;
149                                                   148 
150         arch_stack_walk(consume_entry, &c, tsk    149         arch_stack_walk(consume_entry, &c, tsk, NULL);
151         put_task_stack(tsk);                      150         put_task_stack(tsk);
152         return c.len;                             151         return c.len;
153 }                                                 152 }
154 EXPORT_SYMBOL_GPL(stack_trace_save_tsk);       << 
155                                                   153 
156 /**                                               154 /**
157  * stack_trace_save_regs - Save a stack trace     155  * stack_trace_save_regs - Save a stack trace based on pt_regs into a storage array
158  * @regs:       Pointer to pt_regs to examine     156  * @regs:       Pointer to pt_regs to examine
159  * @store:      Pointer to storage array          157  * @store:      Pointer to storage array
160  * @size:       Size of the storage array         158  * @size:       Size of the storage array
161  * @skipnr:     Number of entries to skip at t    159  * @skipnr:     Number of entries to skip at the start of the stack trace
162  *                                                160  *
163  * Return: Number of trace entries stored.        161  * Return: Number of trace entries stored.
164  */                                               162  */
165 unsigned int stack_trace_save_regs(struct pt_r    163 unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
166                                    unsigned in    164                                    unsigned int size, unsigned int skipnr)
167 {                                                 165 {
168         stack_trace_consume_fn consume_entry =    166         stack_trace_consume_fn consume_entry = stack_trace_consume_entry;
169         struct stacktrace_cookie c = {            167         struct stacktrace_cookie c = {
170                 .store  = store,                  168                 .store  = store,
171                 .size   = size,                   169                 .size   = size,
172                 .skip   = skipnr,                 170                 .skip   = skipnr,
173         };                                        171         };
174                                                   172 
175         arch_stack_walk(consume_entry, &c, cur    173         arch_stack_walk(consume_entry, &c, current, regs);
176         return c.len;                             174         return c.len;
177 }                                                 175 }
178                                                   176 
179 #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE            177 #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE
180 /**                                               178 /**
181  * stack_trace_save_tsk_reliable - Save task s    179  * stack_trace_save_tsk_reliable - Save task stack with verification
182  * @tsk:        Pointer to the task to examine    180  * @tsk:        Pointer to the task to examine
183  * @store:      Pointer to storage array          181  * @store:      Pointer to storage array
184  * @size:       Size of the storage array         182  * @size:       Size of the storage array
185  *                                                183  *
186  * Return:      An error if it detects any unr    184  * Return:      An error if it detects any unreliable features of the
187  *              stack. Otherwise it guarantees    185  *              stack. Otherwise it guarantees that the stack trace is
188  *              reliable and returns the numbe    186  *              reliable and returns the number of entries stored.
189  *                                                187  *
190  * If the task is not 'current', the caller *m    188  * If the task is not 'current', the caller *must* ensure the task is inactive.
191  */                                               189  */
192 int stack_trace_save_tsk_reliable(struct task_    190 int stack_trace_save_tsk_reliable(struct task_struct *tsk, unsigned long *store,
193                                   unsigned int    191                                   unsigned int size)
194 {                                                 192 {
195         stack_trace_consume_fn consume_entry =    193         stack_trace_consume_fn consume_entry = stack_trace_consume_entry;
196         struct stacktrace_cookie c = {            194         struct stacktrace_cookie c = {
197                 .store  = store,                  195                 .store  = store,
198                 .size   = size,                   196                 .size   = size,
199         };                                        197         };
200         int ret;                                  198         int ret;
201                                                   199 
202         /*                                        200         /*
203          * If the task doesn't have a stack (e    201          * If the task doesn't have a stack (e.g., a zombie), the stack is
204          * "reliably" empty.                      202          * "reliably" empty.
205          */                                       203          */
206         if (!try_get_task_stack(tsk))             204         if (!try_get_task_stack(tsk))
207                 return 0;                         205                 return 0;
208                                                   206 
209         ret = arch_stack_walk_reliable(consume    207         ret = arch_stack_walk_reliable(consume_entry, &c, tsk);
210         put_task_stack(tsk);                      208         put_task_stack(tsk);
211         return ret ? ret : c.len;                 209         return ret ? ret : c.len;
212 }                                                 210 }
213 #endif                                            211 #endif
214                                                   212 
215 #ifdef CONFIG_USER_STACKTRACE_SUPPORT             213 #ifdef CONFIG_USER_STACKTRACE_SUPPORT
216 /**                                               214 /**
217  * stack_trace_save_user - Save a user space s    215  * stack_trace_save_user - Save a user space stack trace into a storage array
218  * @store:      Pointer to storage array          216  * @store:      Pointer to storage array
219  * @size:       Size of the storage array         217  * @size:       Size of the storage array
220  *                                                218  *
221  * Return: Number of trace entries stored.        219  * Return: Number of trace entries stored.
222  */                                               220  */
223 unsigned int stack_trace_save_user(unsigned lo    221 unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
224 {                                                 222 {
225         stack_trace_consume_fn consume_entry =    223         stack_trace_consume_fn consume_entry = stack_trace_consume_entry;
226         struct stacktrace_cookie c = {            224         struct stacktrace_cookie c = {
227                 .store  = store,                  225                 .store  = store,
228                 .size   = size,                   226                 .size   = size,
229         };                                        227         };
                                                   >> 228         mm_segment_t fs;
230                                                   229 
231         /* Trace user stack if not a kernel th    230         /* Trace user stack if not a kernel thread */
232         if (current->flags & PF_KTHREAD)          231         if (current->flags & PF_KTHREAD)
233                 return 0;                         232                 return 0;
234                                                   233 
                                                   >> 234         fs = force_uaccess_begin();
235         arch_stack_walk_user(consume_entry, &c    235         arch_stack_walk_user(consume_entry, &c, task_pt_regs(current));
                                                   >> 236         force_uaccess_end(fs);
236                                                   237 
237         return c.len;                             238         return c.len;
238 }                                                 239 }
239 #endif                                            240 #endif
240                                                   241 
241 #else /* CONFIG_ARCH_STACKWALK */                 242 #else /* CONFIG_ARCH_STACKWALK */
242                                                   243 
243 /*                                                244 /*
244  * Architectures that do not implement save_st    245  * Architectures that do not implement save_stack_trace_*()
245  * get these weak aliases and once-per-bootup     246  * get these weak aliases and once-per-bootup warnings
246  * (whenever this facility is utilized - for e    247  * (whenever this facility is utilized - for example by procfs):
247  */                                               248  */
248 __weak void                                       249 __weak void
249 save_stack_trace_tsk(struct task_struct *tsk,     250 save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
250 {                                                 251 {
251         WARN_ONCE(1, KERN_INFO "save_stack_tra    252         WARN_ONCE(1, KERN_INFO "save_stack_trace_tsk() not implemented yet.\n");
252 }                                                 253 }
253                                                   254 
254 __weak void                                       255 __weak void
255 save_stack_trace_regs(struct pt_regs *regs, st    256 save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
256 {                                                 257 {
257         WARN_ONCE(1, KERN_INFO "save_stack_tra    258         WARN_ONCE(1, KERN_INFO "save_stack_trace_regs() not implemented yet.\n");
258 }                                                 259 }
259                                                   260 
260 /**                                               261 /**
261  * stack_trace_save - Save a stack trace into     262  * stack_trace_save - Save a stack trace into a storage array
262  * @store:      Pointer to storage array          263  * @store:      Pointer to storage array
263  * @size:       Size of the storage array         264  * @size:       Size of the storage array
264  * @skipnr:     Number of entries to skip at t    265  * @skipnr:     Number of entries to skip at the start of the stack trace
265  *                                                266  *
266  * Return: Number of trace entries stored         267  * Return: Number of trace entries stored
267  */                                               268  */
268 unsigned int stack_trace_save(unsigned long *s    269 unsigned int stack_trace_save(unsigned long *store, unsigned int size,
269                               unsigned int ski    270                               unsigned int skipnr)
270 {                                                 271 {
271         struct stack_trace trace = {              272         struct stack_trace trace = {
272                 .entries        = store,          273                 .entries        = store,
273                 .max_entries    = size,           274                 .max_entries    = size,
274                 .skip           = skipnr + 1,     275                 .skip           = skipnr + 1,
275         };                                        276         };
276                                                   277 
277         save_stack_trace(&trace);                 278         save_stack_trace(&trace);
278         return trace.nr_entries;                  279         return trace.nr_entries;
279 }                                                 280 }
280 EXPORT_SYMBOL_GPL(stack_trace_save);              281 EXPORT_SYMBOL_GPL(stack_trace_save);
281                                                   282 
282 /**                                               283 /**
283  * stack_trace_save_tsk - Save a task stack tr    284  * stack_trace_save_tsk - Save a task stack trace into a storage array
284  * @task:       The task to examine               285  * @task:       The task to examine
285  * @store:      Pointer to storage array          286  * @store:      Pointer to storage array
286  * @size:       Size of the storage array         287  * @size:       Size of the storage array
287  * @skipnr:     Number of entries to skip at t    288  * @skipnr:     Number of entries to skip at the start of the stack trace
288  *                                                289  *
289  * Return: Number of trace entries stored         290  * Return: Number of trace entries stored
290  */                                               291  */
291 unsigned int stack_trace_save_tsk(struct task_    292 unsigned int stack_trace_save_tsk(struct task_struct *task,
292                                   unsigned lon    293                                   unsigned long *store, unsigned int size,
293                                   unsigned int    294                                   unsigned int skipnr)
294 {                                                 295 {
295         struct stack_trace trace = {              296         struct stack_trace trace = {
296                 .entries        = store,          297                 .entries        = store,
297                 .max_entries    = size,           298                 .max_entries    = size,
298                 /* skip this function if they     299                 /* skip this function if they are tracing us */
299                 .skip   = skipnr + (current ==    300                 .skip   = skipnr + (current == task),
300         };                                        301         };
301                                                   302 
302         save_stack_trace_tsk(task, &trace);       303         save_stack_trace_tsk(task, &trace);
303         return trace.nr_entries;                  304         return trace.nr_entries;
304 }                                                 305 }
305 EXPORT_SYMBOL_GPL(stack_trace_save_tsk);       << 
306                                                   306 
307 /**                                               307 /**
308  * stack_trace_save_regs - Save a stack trace     308  * stack_trace_save_regs - Save a stack trace based on pt_regs into a storage array
309  * @regs:       Pointer to pt_regs to examine     309  * @regs:       Pointer to pt_regs to examine
310  * @store:      Pointer to storage array          310  * @store:      Pointer to storage array
311  * @size:       Size of the storage array         311  * @size:       Size of the storage array
312  * @skipnr:     Number of entries to skip at t    312  * @skipnr:     Number of entries to skip at the start of the stack trace
313  *                                                313  *
314  * Return: Number of trace entries stored         314  * Return: Number of trace entries stored
315  */                                               315  */
316 unsigned int stack_trace_save_regs(struct pt_r    316 unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
317                                    unsigned in    317                                    unsigned int size, unsigned int skipnr)
318 {                                                 318 {
319         struct stack_trace trace = {              319         struct stack_trace trace = {
320                 .entries        = store,          320                 .entries        = store,
321                 .max_entries    = size,           321                 .max_entries    = size,
322                 .skip           = skipnr,         322                 .skip           = skipnr,
323         };                                        323         };
324                                                   324 
325         save_stack_trace_regs(regs, &trace);      325         save_stack_trace_regs(regs, &trace);
326         return trace.nr_entries;                  326         return trace.nr_entries;
327 }                                                 327 }
328                                                   328 
329 #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE            329 #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE
330 /**                                               330 /**
331  * stack_trace_save_tsk_reliable - Save task s    331  * stack_trace_save_tsk_reliable - Save task stack with verification
332  * @tsk:        Pointer to the task to examine    332  * @tsk:        Pointer to the task to examine
333  * @store:      Pointer to storage array          333  * @store:      Pointer to storage array
334  * @size:       Size of the storage array         334  * @size:       Size of the storage array
335  *                                                335  *
336  * Return:      An error if it detects any unr    336  * Return:      An error if it detects any unreliable features of the
337  *              stack. Otherwise it guarantees    337  *              stack. Otherwise it guarantees that the stack trace is
338  *              reliable and returns the numbe    338  *              reliable and returns the number of entries stored.
339  *                                                339  *
340  * If the task is not 'current', the caller *m    340  * If the task is not 'current', the caller *must* ensure the task is inactive.
341  */                                               341  */
342 int stack_trace_save_tsk_reliable(struct task_    342 int stack_trace_save_tsk_reliable(struct task_struct *tsk, unsigned long *store,
343                                   unsigned int    343                                   unsigned int size)
344 {                                                 344 {
345         struct stack_trace trace = {              345         struct stack_trace trace = {
346                 .entries        = store,          346                 .entries        = store,
347                 .max_entries    = size,           347                 .max_entries    = size,
348         };                                        348         };
349         int ret = save_stack_trace_tsk_reliabl    349         int ret = save_stack_trace_tsk_reliable(tsk, &trace);
350                                                   350 
351         return ret ? ret : trace.nr_entries;      351         return ret ? ret : trace.nr_entries;
352 }                                                 352 }
353 #endif                                            353 #endif
354                                                   354 
355 #ifdef CONFIG_USER_STACKTRACE_SUPPORT             355 #ifdef CONFIG_USER_STACKTRACE_SUPPORT
356 /**                                               356 /**
357  * stack_trace_save_user - Save a user space s    357  * stack_trace_save_user - Save a user space stack trace into a storage array
358  * @store:      Pointer to storage array          358  * @store:      Pointer to storage array
359  * @size:       Size of the storage array         359  * @size:       Size of the storage array
360  *                                                360  *
361  * Return: Number of trace entries stored         361  * Return: Number of trace entries stored
362  */                                               362  */
363 unsigned int stack_trace_save_user(unsigned lo    363 unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
364 {                                                 364 {
365         struct stack_trace trace = {              365         struct stack_trace trace = {
366                 .entries        = store,          366                 .entries        = store,
367                 .max_entries    = size,           367                 .max_entries    = size,
368         };                                        368         };
369                                                   369 
370         save_stack_trace_user(&trace);            370         save_stack_trace_user(&trace);
371         return trace.nr_entries;                  371         return trace.nr_entries;
372 }                                                 372 }
373 #endif /* CONFIG_USER_STACKTRACE_SUPPORT */       373 #endif /* CONFIG_USER_STACKTRACE_SUPPORT */
374                                                   374 
375 #endif /* !CONFIG_ARCH_STACKWALK */               375 #endif /* !CONFIG_ARCH_STACKWALK */
376                                                << 
377 static inline bool in_irqentry_text(unsigned l << 
378 {                                              << 
379         return (ptr >= (unsigned long)&__irqen << 
380                 ptr < (unsigned long)&__irqent << 
381                 (ptr >= (unsigned long)&__soft << 
382                  ptr < (unsigned long)&__softi << 
383 }                                              << 
384                                                << 
385 /**                                            << 
386  * filter_irq_stacks - Find first IRQ stack en << 
387  * @entries:    Pointer to stack trace array   << 
388  * @nr_entries: Number of entries in the stora << 
389  *                                             << 
390  * Return: Number of trace entries until IRQ s << 
391  */                                            << 
392 unsigned int filter_irq_stacks(unsigned long * << 
393 {                                              << 
394         unsigned int i;                        << 
395                                                << 
396         for (i = 0; i < nr_entries; i++) {     << 
397                 if (in_irqentry_text(entries[i << 
398                         /* Include the irqentr << 
399                         return i + 1;          << 
400                 }                              << 
401         }                                      << 
402         return nr_entries;                     << 
403 }                                              << 
404 EXPORT_SYMBOL_GPL(filter_irq_stacks);          << 
405                                                   376 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php