~ [ 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.15.171)


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

~ [ 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