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

TOMOYO Linux Cross Reference
Linux/arch/unicore32/kernel/stacktrace.c

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/arch/unicore32/kernel/stacktrace.c
  3  *
  4  * Code specific to PKUnity SoC and UniCore ISA
  5  *
  6  * Copyright (C) 2001-2010 GUAN Xue-tao
  7  *
  8  * This program is free software; you can redistribute it and/or modify
  9  * it under the terms of the GNU General Public License version 2 as
 10  * published by the Free Software Foundation.
 11  */
 12 #include <linux/module.h>
 13 #include <linux/sched.h>
 14 #include <linux/sched/debug.h>
 15 #include <linux/stacktrace.h>
 16 
 17 #include <asm/stacktrace.h>
 18 
 19 #if defined(CONFIG_FRAME_POINTER)
 20 /*
 21  * Unwind the current stack frame and store the new register values in the
 22  * structure passed as argument. Unwinding is equivalent to a function return,
 23  * hence the new PC value rather than LR should be used for backtrace.
 24  *
 25  * With framepointer enabled, a simple function prologue looks like this:
 26  *      mov     ip, sp
 27  *      stmdb   sp!, {fp, ip, lr, pc}
 28  *      sub     fp, ip, #4
 29  *
 30  * A simple function epilogue looks like this:
 31  *      ldm     sp, {fp, sp, pc}
 32  *
 33  * Note that with framepointer enabled, even the leaf functions have the same
 34  * prologue and epilogue, therefore we can ignore the LR value in this case.
 35  */
 36 int notrace unwind_frame(struct stackframe *frame)
 37 {
 38         unsigned long high, low;
 39         unsigned long fp = frame->fp;
 40 
 41         /* only go to a higher address on the stack */
 42         low = frame->sp;
 43         high = ALIGN(low, THREAD_SIZE);
 44 
 45         /* check current frame pointer is within bounds */
 46         if (fp < (low + 12) || fp + 4 >= high)
 47                 return -EINVAL;
 48 
 49         /* restore the registers from the stack frame */
 50         frame->fp = *(unsigned long *)(fp - 12);
 51         frame->sp = *(unsigned long *)(fp - 8);
 52         frame->pc = *(unsigned long *)(fp - 4);
 53 
 54         return 0;
 55 }
 56 #endif
 57 
 58 void notrace walk_stackframe(struct stackframe *frame,
 59                      int (*fn)(struct stackframe *, void *), void *data)
 60 {
 61         while (1) {
 62                 int ret;
 63 
 64                 if (fn(frame, data))
 65                         break;
 66                 ret = unwind_frame(frame);
 67                 if (ret < 0)
 68                         break;
 69         }
 70 }
 71 EXPORT_SYMBOL(walk_stackframe);
 72 
 73 #ifdef CONFIG_STACKTRACE
 74 struct stack_trace_data {
 75         struct stack_trace *trace;
 76         unsigned int no_sched_functions;
 77         unsigned int skip;
 78 };
 79 
 80 static int save_trace(struct stackframe *frame, void *d)
 81 {
 82         struct stack_trace_data *data = d;
 83         struct stack_trace *trace = data->trace;
 84         unsigned long addr = frame->pc;
 85 
 86         if (data->no_sched_functions && in_sched_functions(addr))
 87                 return 0;
 88         if (data->skip) {
 89                 data->skip--;
 90                 return 0;
 91         }
 92 
 93         trace->entries[trace->nr_entries++] = addr;
 94 
 95         return trace->nr_entries >= trace->max_entries;
 96 }
 97 
 98 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 99 {
100         struct stack_trace_data data;
101         struct stackframe frame;
102 
103         data.trace = trace;
104         data.skip = trace->skip;
105 
106         if (tsk != current) {
107                 data.no_sched_functions = 1;
108                 frame.fp = thread_saved_fp(tsk);
109                 frame.sp = thread_saved_sp(tsk);
110                 frame.lr = 0;           /* recovered from the stack */
111                 frame.pc = thread_saved_pc(tsk);
112         } else {
113                 register unsigned long current_sp asm("sp");
114 
115                 data.no_sched_functions = 0;
116                 frame.fp = (unsigned long)__builtin_frame_address(0);
117                 frame.sp = current_sp;
118                 frame.lr = (unsigned long)__builtin_return_address(0);
119                 frame.pc = (unsigned long)save_stack_trace_tsk;
120         }
121 
122         walk_stackframe(&frame, save_trace, &data);
123         if (trace->nr_entries < trace->max_entries)
124                 trace->entries[trace->nr_entries++] = ULONG_MAX;
125 }
126 
127 void save_stack_trace(struct stack_trace *trace)
128 {
129         save_stack_trace_tsk(current, trace);
130 }
131 EXPORT_SYMBOL_GPL(save_stack_trace);
132 #endif
133 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp