39
39
* associated with the most recently encountered replacement lr
40
40
* value.
41
41
*/
42
- struct stackframe {
42
+ struct unwind_state {
43
43
unsigned long fp ;
44
44
unsigned long pc ;
45
45
DECLARE_BITMAP (stacks_done , __NR_STACK_TYPES );
@@ -50,13 +50,13 @@ struct stackframe {
50
50
#endif
51
51
};
52
52
53
- static notrace void unwind_init (struct stackframe * frame , unsigned long fp ,
53
+ static notrace void unwind_init (struct unwind_state * state , unsigned long fp ,
54
54
unsigned long pc )
55
55
{
56
- frame -> fp = fp ;
57
- frame -> pc = pc ;
56
+ state -> fp = fp ;
57
+ state -> pc = pc ;
58
58
#ifdef CONFIG_KRETPROBES
59
- frame -> kr_cur = NULL ;
59
+ state -> kr_cur = NULL ;
60
60
#endif
61
61
62
62
/*
@@ -68,9 +68,9 @@ static notrace void unwind_init(struct stackframe *frame, unsigned long fp,
68
68
* prev_fp value won't be used, but we set it to 0 such that it is
69
69
* definitely not an accessible stack address.
70
70
*/
71
- bitmap_zero (frame -> stacks_done , __NR_STACK_TYPES );
72
- frame -> prev_fp = 0 ;
73
- frame -> prev_type = STACK_TYPE_UNKNOWN ;
71
+ bitmap_zero (state -> stacks_done , __NR_STACK_TYPES );
72
+ state -> prev_fp = 0 ;
73
+ state -> prev_type = STACK_TYPE_UNKNOWN ;
74
74
}
75
75
NOKPROBE_SYMBOL (unwind_init );
76
76
@@ -82,9 +82,9 @@ NOKPROBE_SYMBOL(unwind_init);
82
82
* and the location (but not the fp value) of B.
83
83
*/
84
84
static int notrace unwind_next (struct task_struct * tsk ,
85
- struct stackframe * frame )
85
+ struct unwind_state * state )
86
86
{
87
- unsigned long fp = frame -> fp ;
87
+ unsigned long fp = state -> fp ;
88
88
struct stack_info info ;
89
89
90
90
/* Final frame; nothing to unwind */
@@ -97,7 +97,7 @@ static int notrace unwind_next(struct task_struct *tsk,
97
97
if (!on_accessible_stack (tsk , fp , 16 , & info ))
98
98
return - EINVAL ;
99
99
100
- if (test_bit (info .type , frame -> stacks_done ))
100
+ if (test_bit (info .type , state -> stacks_done ))
101
101
return - EINVAL ;
102
102
103
103
/*
@@ -113,60 +113,60 @@ static int notrace unwind_next(struct task_struct *tsk,
113
113
* stack to another, it's never valid to unwind back to that first
114
114
* stack.
115
115
*/
116
- if (info .type == frame -> prev_type ) {
117
- if (fp <= frame -> prev_fp )
116
+ if (info .type == state -> prev_type ) {
117
+ if (fp <= state -> prev_fp )
118
118
return - EINVAL ;
119
119
} else {
120
- set_bit (frame -> prev_type , frame -> stacks_done );
120
+ set_bit (state -> prev_type , state -> stacks_done );
121
121
}
122
122
123
123
/*
124
124
* Record this frame record's values and location. The prev_fp and
125
125
* prev_type are only meaningful to the next unwind_next() invocation.
126
126
*/
127
- frame -> fp = READ_ONCE_NOCHECK (* (unsigned long * )(fp ));
128
- frame -> pc = READ_ONCE_NOCHECK (* (unsigned long * )(fp + 8 ));
129
- frame -> prev_fp = fp ;
130
- frame -> prev_type = info .type ;
127
+ state -> fp = READ_ONCE_NOCHECK (* (unsigned long * )(fp ));
128
+ state -> pc = READ_ONCE_NOCHECK (* (unsigned long * )(fp + 8 ));
129
+ state -> prev_fp = fp ;
130
+ state -> prev_type = info .type ;
131
131
132
- frame -> pc = ptrauth_strip_insn_pac (frame -> pc );
132
+ state -> pc = ptrauth_strip_insn_pac (state -> pc );
133
133
134
134
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
135
135
if (tsk -> ret_stack &&
136
- (frame -> pc == (unsigned long )return_to_handler )) {
136
+ (state -> pc == (unsigned long )return_to_handler )) {
137
137
unsigned long orig_pc ;
138
138
/*
139
139
* This is a case where function graph tracer has
140
140
* modified a return address (LR) in a stack frame
141
141
* to hook a function return.
142
142
* So replace it to an original value.
143
143
*/
144
- orig_pc = ftrace_graph_ret_addr (tsk , NULL , frame -> pc ,
145
- (void * )frame -> fp );
146
- if (WARN_ON_ONCE (frame -> pc == orig_pc ))
144
+ orig_pc = ftrace_graph_ret_addr (tsk , NULL , state -> pc ,
145
+ (void * )state -> fp );
146
+ if (WARN_ON_ONCE (state -> pc == orig_pc ))
147
147
return - EINVAL ;
148
- frame -> pc = orig_pc ;
148
+ state -> pc = orig_pc ;
149
149
}
150
150
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
151
151
#ifdef CONFIG_KRETPROBES
152
- if (is_kretprobe_trampoline (frame -> pc ))
153
- frame -> pc = kretprobe_find_ret_addr (tsk , (void * )frame -> fp , & frame -> kr_cur );
152
+ if (is_kretprobe_trampoline (state -> pc ))
153
+ state -> pc = kretprobe_find_ret_addr (tsk , (void * )state -> fp , & state -> kr_cur );
154
154
#endif
155
155
156
156
return 0 ;
157
157
}
158
158
NOKPROBE_SYMBOL (unwind_next );
159
159
160
160
static void notrace unwind (struct task_struct * tsk ,
161
- struct stackframe * frame ,
161
+ struct unwind_state * state ,
162
162
bool (* fn )(void * , unsigned long ), void * data )
163
163
{
164
164
while (1 ) {
165
165
int ret ;
166
166
167
- if (!fn (data , frame -> pc ))
167
+ if (!fn (data , state -> pc ))
168
168
break ;
169
- ret = unwind_next (tsk , frame );
169
+ ret = unwind_next (tsk , state );
170
170
if (ret < 0 )
171
171
break ;
172
172
}
@@ -210,17 +210,17 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry,
210
210
void * cookie , struct task_struct * task ,
211
211
struct pt_regs * regs )
212
212
{
213
- struct stackframe frame ;
213
+ struct unwind_state state ;
214
214
215
215
if (regs )
216
- unwind_init (& frame , regs -> regs [29 ], regs -> pc );
216
+ unwind_init (& state , regs -> regs [29 ], regs -> pc );
217
217
else if (task == current )
218
- unwind_init (& frame ,
218
+ unwind_init (& state ,
219
219
(unsigned long )__builtin_frame_address (1 ),
220
220
(unsigned long )__builtin_return_address (0 ));
221
221
else
222
- unwind_init (& frame , thread_saved_fp (task ),
222
+ unwind_init (& state , thread_saved_fp (task ),
223
223
thread_saved_pc (task ));
224
224
225
- unwind (task , & frame , consume_entry , cookie );
225
+ unwind (task , & state , consume_entry , cookie );
226
226
}
0 commit comments