Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_S390_UNWIND_H
0003 #define _ASM_S390_UNWIND_H
0004 
0005 #include <linux/sched.h>
0006 #include <linux/ftrace.h>
0007 #include <linux/kprobes.h>
0008 #include <linux/llist.h>
0009 #include <asm/ptrace.h>
0010 #include <asm/stacktrace.h>
0011 
0012 /*
0013  * To use the stack unwinder it has to be initialized with unwind_start.
0014  * There four combinations for task and regs:
0015  * 1) task==NULL, regs==NULL: the unwind starts for the task that is currently
0016  *    running, sp/ip picked up from the CPU registers
0017  * 2) task==NULL, regs!=NULL: the unwind starts from the sp/ip found in
0018  *    the struct pt_regs of an interrupt frame for the current task
0019  * 3) task!=NULL, regs==NULL: the unwind starts for an inactive task with
0020  *    the sp picked up from task->thread.ksp and the ip picked up from the
0021  *    return address stored by __switch_to
0022  * 4) task!=NULL, regs!=NULL: the sp/ip are picked up from the interrupt
0023  *    frame 'regs' of a inactive task
0024  * If 'first_frame' is not zero unwind_start skips unwind frames until it
0025  * reaches the specified stack pointer.
0026  * The end of the unwinding is indicated with unwind_done, this can be true
0027  * right after unwind_start, e.g. with first_frame!=0 that can not be found.
0028  * unwind_next_frame skips to the next frame.
0029  * Once the unwind is completed unwind_error() can be used to check if there
0030  * has been a situation where the unwinder could not correctly understand
0031  * the tasks call chain.
0032  */
0033 
0034 struct unwind_state {
0035     struct stack_info stack_info;
0036     unsigned long stack_mask;
0037     struct task_struct *task;
0038     struct pt_regs *regs;
0039     unsigned long sp, ip;
0040     int graph_idx;
0041     struct llist_node *kr_cur;
0042     bool reliable;
0043     bool error;
0044 };
0045 
0046 /* Recover the return address modified by kretprobe and ftrace_graph. */
0047 static inline unsigned long unwind_recover_ret_addr(struct unwind_state *state,
0048                             unsigned long ip)
0049 {
0050     ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, (void *)state->sp);
0051     if (is_kretprobe_trampoline(ip))
0052         ip = kretprobe_find_ret_addr(state->task, (void *)state->sp, &state->kr_cur);
0053     return ip;
0054 }
0055 
0056 void __unwind_start(struct unwind_state *state, struct task_struct *task,
0057             struct pt_regs *regs, unsigned long first_frame);
0058 bool unwind_next_frame(struct unwind_state *state);
0059 unsigned long unwind_get_return_address(struct unwind_state *state);
0060 
0061 static inline bool unwind_done(struct unwind_state *state)
0062 {
0063     return state->stack_info.type == STACK_TYPE_UNKNOWN;
0064 }
0065 
0066 static inline bool unwind_error(struct unwind_state *state)
0067 {
0068     return state->error;
0069 }
0070 
0071 static __always_inline void unwind_start(struct unwind_state *state,
0072                      struct task_struct *task,
0073                      struct pt_regs *regs,
0074                      unsigned long first_frame)
0075 {
0076     task = task ?: current;
0077     first_frame = first_frame ?: get_stack_pointer(task, regs);
0078     __unwind_start(state, task, regs, first_frame);
0079 }
0080 
0081 static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
0082 {
0083     return unwind_done(state) ? NULL : state->regs;
0084 }
0085 
0086 #define unwind_for_each_frame(state, task, regs, first_frame)   \
0087     for (unwind_start(state, task, regs, first_frame);  \
0088          !unwind_done(state);               \
0089          unwind_next_frame(state))
0090 
0091 static inline void unwind_init(void) {}
0092 static inline void unwind_module_init(struct module *mod, void *orc_ip,
0093                       size_t orc_ip_size, void *orc,
0094                       size_t orc_size) {}
0095 
0096 #endif /* _ASM_S390_UNWIND_H */