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

TOMOYO Linux Cross Reference
Linux/arch/loongarch/include/asm/unwind.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * Most of this ideas comes from x86.
  4  *
  5  * Copyright (C) 2022 Loongson Technology Corporation Limited
  6  */
  7 #ifndef _ASM_UNWIND_H
  8 #define _ASM_UNWIND_H
  9 
 10 #include <linux/sched.h>
 11 #include <linux/ftrace.h>
 12 
 13 #include <asm/ptrace.h>
 14 #include <asm/stacktrace.h>
 15 
 16 enum unwinder_type {
 17         UNWINDER_GUESS,
 18         UNWINDER_PROLOGUE,
 19         UNWINDER_ORC,
 20 };
 21 
 22 struct unwind_state {
 23         char type; /* UNWINDER_XXX */
 24         struct stack_info stack_info;
 25         struct task_struct *task;
 26         bool first, error, reset;
 27         int graph_idx;
 28         unsigned long sp, fp, pc, ra;
 29 };
 30 
 31 bool default_next_frame(struct unwind_state *state);
 32 
 33 void unwind_start(struct unwind_state *state,
 34                   struct task_struct *task, struct pt_regs *regs);
 35 bool unwind_next_frame(struct unwind_state *state);
 36 unsigned long unwind_get_return_address(struct unwind_state *state);
 37 
 38 static inline bool unwind_done(struct unwind_state *state)
 39 {
 40         return state->stack_info.type == STACK_TYPE_UNKNOWN;
 41 }
 42 
 43 static inline bool unwind_error(struct unwind_state *state)
 44 {
 45         return state->error;
 46 }
 47 
 48 #define GRAPH_FAKE_OFFSET (sizeof(struct pt_regs) - offsetof(struct pt_regs, regs[1]))
 49 
 50 static inline unsigned long unwind_graph_addr(struct unwind_state *state,
 51                                         unsigned long pc, unsigned long cfa)
 52 {
 53         return ftrace_graph_ret_addr(state->task, &state->graph_idx,
 54                                      pc, (unsigned long *)(cfa - GRAPH_FAKE_OFFSET));
 55 }
 56 
 57 static __always_inline void __unwind_start(struct unwind_state *state,
 58                                         struct task_struct *task, struct pt_regs *regs)
 59 {
 60         memset(state, 0, sizeof(*state));
 61         if (regs) {
 62                 state->sp = regs->regs[3];
 63                 state->pc = regs->csr_era;
 64                 state->ra = regs->regs[1];
 65                 state->fp = regs->regs[22];
 66         } else if (task && task != current) {
 67                 state->sp = thread_saved_fp(task);
 68                 state->pc = thread_saved_ra(task);
 69                 state->ra = 0;
 70                 state->fp = 0;
 71         } else {
 72                 state->sp = (unsigned long)__builtin_frame_address(0);
 73                 state->pc = (unsigned long)__builtin_return_address(0);
 74                 state->ra = 0;
 75                 state->fp = 0;
 76         }
 77         state->task = task;
 78         get_stack_info(state->sp, state->task, &state->stack_info);
 79         state->pc = unwind_graph_addr(state, state->pc, state->sp);
 80 }
 81 
 82 static __always_inline unsigned long __unwind_get_return_address(struct unwind_state *state)
 83 {
 84         if (unwind_done(state))
 85                 return 0;
 86 
 87         return __kernel_text_address(state->pc) ? state->pc : 0;
 88 }
 89 
 90 #ifdef CONFIG_UNWINDER_ORC
 91 void unwind_init(void);
 92 void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size, void *orc, size_t orc_size);
 93 #else
 94 static inline void unwind_init(void) {}
 95 static inline void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size, void *orc, size_t orc_size) {}
 96 #endif
 97 
 98 #endif /* _ASM_UNWIND_H */
 99 

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