xref: /OK3568_Linux_fs/kernel/arch/s390/include/asm/unwind.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_S390_UNWIND_H
3*4882a593Smuzhiyun #define _ASM_S390_UNWIND_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <linux/sched.h>
6*4882a593Smuzhiyun #include <linux/ftrace.h>
7*4882a593Smuzhiyun #include <asm/ptrace.h>
8*4882a593Smuzhiyun #include <asm/stacktrace.h>
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /*
11*4882a593Smuzhiyun  * To use the stack unwinder it has to be initialized with unwind_start.
12*4882a593Smuzhiyun  * There four combinations for task and regs:
13*4882a593Smuzhiyun  * 1) task==NULL, regs==NULL: the unwind starts for the task that is currently
14*4882a593Smuzhiyun  *    running, sp/ip picked up from the CPU registers
15*4882a593Smuzhiyun  * 2) task==NULL, regs!=NULL: the unwind starts from the sp/ip found in
16*4882a593Smuzhiyun  *    the struct pt_regs of an interrupt frame for the current task
17*4882a593Smuzhiyun  * 3) task!=NULL, regs==NULL: the unwind starts for an inactive task with
18*4882a593Smuzhiyun  *    the sp picked up from task->thread.ksp and the ip picked up from the
19*4882a593Smuzhiyun  *    return address stored by __switch_to
20*4882a593Smuzhiyun  * 4) task!=NULL, regs!=NULL: the sp/ip are picked up from the interrupt
21*4882a593Smuzhiyun  *    frame 'regs' of a inactive task
22*4882a593Smuzhiyun  * If 'first_frame' is not zero unwind_start skips unwind frames until it
23*4882a593Smuzhiyun  * reaches the specified stack pointer.
24*4882a593Smuzhiyun  * The end of the unwinding is indicated with unwind_done, this can be true
25*4882a593Smuzhiyun  * right after unwind_start, e.g. with first_frame!=0 that can not be found.
26*4882a593Smuzhiyun  * unwind_next_frame skips to the next frame.
27*4882a593Smuzhiyun  * Once the unwind is completed unwind_error() can be used to check if there
28*4882a593Smuzhiyun  * has been a situation where the unwinder could not correctly understand
29*4882a593Smuzhiyun  * the tasks call chain.
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct unwind_state {
33*4882a593Smuzhiyun 	struct stack_info stack_info;
34*4882a593Smuzhiyun 	unsigned long stack_mask;
35*4882a593Smuzhiyun 	struct task_struct *task;
36*4882a593Smuzhiyun 	struct pt_regs *regs;
37*4882a593Smuzhiyun 	unsigned long sp, ip;
38*4882a593Smuzhiyun 	int graph_idx;
39*4882a593Smuzhiyun 	bool reliable;
40*4882a593Smuzhiyun 	bool error;
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun void __unwind_start(struct unwind_state *state, struct task_struct *task,
44*4882a593Smuzhiyun 		    struct pt_regs *regs, unsigned long first_frame);
45*4882a593Smuzhiyun bool unwind_next_frame(struct unwind_state *state);
46*4882a593Smuzhiyun unsigned long unwind_get_return_address(struct unwind_state *state);
47*4882a593Smuzhiyun 
unwind_done(struct unwind_state * state)48*4882a593Smuzhiyun static inline bool unwind_done(struct unwind_state *state)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun 	return state->stack_info.type == STACK_TYPE_UNKNOWN;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
unwind_error(struct unwind_state * state)53*4882a593Smuzhiyun static inline bool unwind_error(struct unwind_state *state)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	return state->error;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
unwind_start(struct unwind_state * state,struct task_struct * task,struct pt_regs * regs,unsigned long first_frame)58*4882a593Smuzhiyun static inline void unwind_start(struct unwind_state *state,
59*4882a593Smuzhiyun 				struct task_struct *task,
60*4882a593Smuzhiyun 				struct pt_regs *regs,
61*4882a593Smuzhiyun 				unsigned long first_frame)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun 	task = task ?: current;
64*4882a593Smuzhiyun 	first_frame = first_frame ?: get_stack_pointer(task, regs);
65*4882a593Smuzhiyun 	__unwind_start(state, task, regs, first_frame);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
unwind_get_entry_regs(struct unwind_state * state)68*4882a593Smuzhiyun static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	return unwind_done(state) ? NULL : state->regs;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define unwind_for_each_frame(state, task, regs, first_frame)	\
74*4882a593Smuzhiyun 	for (unwind_start(state, task, regs, first_frame);	\
75*4882a593Smuzhiyun 	     !unwind_done(state);				\
76*4882a593Smuzhiyun 	     unwind_next_frame(state))
77*4882a593Smuzhiyun 
unwind_init(void)78*4882a593Smuzhiyun static inline void unwind_init(void) {}
unwind_module_init(struct module * mod,void * orc_ip,size_t orc_ip_size,void * orc,size_t orc_size)79*4882a593Smuzhiyun static inline void unwind_module_init(struct module *mod, void *orc_ip,
80*4882a593Smuzhiyun 				      size_t orc_ip_size, void *orc,
81*4882a593Smuzhiyun 				      size_t orc_size) {}
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #endif /* _ASM_S390_UNWIND_H */
84