unwind.h (5bb8d34449c4a2eb94d657b992170afafac274f9) unwind.h (c5ac25e0d78a6f63446b8fef4d8630ccd7a2663d)
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

--- 13 unchanged lines hidden (view full) ---

22 char type; /* UNWINDER_XXX */
23 struct stack_info stack_info;
24 struct task_struct *task;
25 bool first, error, is_ftrace;
26 int graph_idx;
27 unsigned long sp, pc, ra;
28};
29
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

--- 13 unchanged lines hidden (view full) ---

22 char type; /* UNWINDER_XXX */
23 struct stack_info stack_info;
24 struct task_struct *task;
25 bool first, error, is_ftrace;
26 int graph_idx;
27 unsigned long sp, pc, ra;
28};
29
30bool default_next_frame(struct unwind_state *state);
31
30void unwind_start(struct unwind_state *state,
31 struct task_struct *task, struct pt_regs *regs);
32bool unwind_next_frame(struct unwind_state *state);
33unsigned long unwind_get_return_address(struct unwind_state *state);
34
35static inline bool unwind_done(struct unwind_state *state)
36{
37 return state->stack_info.type == STACK_TYPE_UNKNOWN;

--- 7 unchanged lines hidden (view full) ---

45#define GRAPH_FAKE_OFFSET (sizeof(struct pt_regs) - offsetof(struct pt_regs, regs[1]))
46
47static inline unsigned long unwind_graph_addr(struct unwind_state *state,
48 unsigned long pc, unsigned long cfa)
49{
50 return ftrace_graph_ret_addr(state->task, &state->graph_idx,
51 pc, (unsigned long *)(cfa - GRAPH_FAKE_OFFSET));
52}
32void unwind_start(struct unwind_state *state,
33 struct task_struct *task, struct pt_regs *regs);
34bool unwind_next_frame(struct unwind_state *state);
35unsigned long unwind_get_return_address(struct unwind_state *state);
36
37static inline bool unwind_done(struct unwind_state *state)
38{
39 return state->stack_info.type == STACK_TYPE_UNKNOWN;

--- 7 unchanged lines hidden (view full) ---

47#define GRAPH_FAKE_OFFSET (sizeof(struct pt_regs) - offsetof(struct pt_regs, regs[1]))
48
49static inline unsigned long unwind_graph_addr(struct unwind_state *state,
50 unsigned long pc, unsigned long cfa)
51{
52 return ftrace_graph_ret_addr(state->task, &state->graph_idx,
53 pc, (unsigned long *)(cfa - GRAPH_FAKE_OFFSET));
54}
55
56static __always_inline void __unwind_start(struct unwind_state *state,
57 struct task_struct *task, struct pt_regs *regs)
58{
59 memset(state, 0, sizeof(*state));
60 if (regs) {
61 state->sp = regs->regs[3];
62 state->pc = regs->csr_era;
63 state->ra = regs->regs[1];
64 } else if (task && task != current) {
65 state->sp = thread_saved_fp(task);
66 state->pc = thread_saved_ra(task);
67 state->ra = 0;
68 } else {
69 state->sp = (unsigned long)__builtin_frame_address(0);
70 state->pc = (unsigned long)__builtin_return_address(0);
71 state->ra = 0;
72 }
73 state->task = task;
74 get_stack_info(state->sp, state->task, &state->stack_info);
75 state->pc = unwind_graph_addr(state, state->pc, state->sp);
76}
77
78static __always_inline unsigned long __unwind_get_return_address(struct unwind_state *state)
79{
80 return unwind_done(state) ? 0 : state->pc;
81}
53#endif /* _ASM_UNWIND_H */
82#endif /* _ASM_UNWIND_H */