1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/objtool.h>
3 #include <linux/module.h>
4 #include <linux/sort.h>
5 #include <asm/ptrace.h>
6 #include <asm/stacktrace.h>
7 #include <asm/unwind.h>
8 #include <asm/orc_types.h>
9 #include <asm/orc_lookup.h>
10
11 #define orc_warn(fmt, ...) \
12 printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
13
14 #define orc_warn_current(args...) \
15 ({ \
16 if (state->task == current) \
17 orc_warn(args); \
18 })
19
20 extern int __start_orc_unwind_ip[];
21 extern int __stop_orc_unwind_ip[];
22 extern struct orc_entry __start_orc_unwind[];
23 extern struct orc_entry __stop_orc_unwind[];
24
25 static bool orc_init __ro_after_init;
26 static unsigned int lookup_num_blocks __ro_after_init;
27
orc_ip(const int * ip)28 static inline unsigned long orc_ip(const int *ip)
29 {
30 return (unsigned long)ip + *ip;
31 }
32
__orc_find(int * ip_table,struct orc_entry * u_table,unsigned int num_entries,unsigned long ip)33 static struct orc_entry *__orc_find(int *ip_table, struct orc_entry *u_table,
34 unsigned int num_entries, unsigned long ip)
35 {
36 int *first = ip_table;
37 int *last = ip_table + num_entries - 1;
38 int *mid = first, *found = first;
39
40 if (!num_entries)
41 return NULL;
42
43 /*
44 * Do a binary range search to find the rightmost duplicate of a given
45 * starting address. Some entries are section terminators which are
46 * "weak" entries for ensuring there are no gaps. They should be
47 * ignored when they conflict with a real entry.
48 */
49 while (first <= last) {
50 mid = first + ((last - first) / 2);
51
52 if (orc_ip(mid) <= ip) {
53 found = mid;
54 first = mid + 1;
55 } else
56 last = mid - 1;
57 }
58
59 return u_table + (found - ip_table);
60 }
61
62 #ifdef CONFIG_MODULES
orc_module_find(unsigned long ip)63 static struct orc_entry *orc_module_find(unsigned long ip)
64 {
65 struct module *mod;
66
67 mod = __module_address(ip);
68 if (!mod || !mod->arch.orc_unwind || !mod->arch.orc_unwind_ip)
69 return NULL;
70 return __orc_find(mod->arch.orc_unwind_ip, mod->arch.orc_unwind,
71 mod->arch.num_orcs, ip);
72 }
73 #else
orc_module_find(unsigned long ip)74 static struct orc_entry *orc_module_find(unsigned long ip)
75 {
76 return NULL;
77 }
78 #endif
79
80 #ifdef CONFIG_DYNAMIC_FTRACE
81 static struct orc_entry *orc_find(unsigned long ip);
82
83 /*
84 * Ftrace dynamic trampolines do not have orc entries of their own.
85 * But they are copies of the ftrace entries that are static and
86 * defined in ftrace_*.S, which do have orc entries.
87 *
88 * If the unwinder comes across a ftrace trampoline, then find the
89 * ftrace function that was used to create it, and use that ftrace
90 * function's orc entry, as the placement of the return code in
91 * the stack will be identical.
92 */
orc_ftrace_find(unsigned long ip)93 static struct orc_entry *orc_ftrace_find(unsigned long ip)
94 {
95 struct ftrace_ops *ops;
96 unsigned long tramp_addr, offset;
97
98 ops = ftrace_ops_trampoline(ip);
99 if (!ops)
100 return NULL;
101
102 /* Set tramp_addr to the start of the code copied by the trampoline */
103 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
104 tramp_addr = (unsigned long)ftrace_regs_caller;
105 else
106 tramp_addr = (unsigned long)ftrace_caller;
107
108 /* Now place tramp_addr to the location within the trampoline ip is at */
109 offset = ip - ops->trampoline;
110 tramp_addr += offset;
111
112 /* Prevent unlikely recursion */
113 if (ip == tramp_addr)
114 return NULL;
115
116 return orc_find(tramp_addr);
117 }
118 #else
orc_ftrace_find(unsigned long ip)119 static struct orc_entry *orc_ftrace_find(unsigned long ip)
120 {
121 return NULL;
122 }
123 #endif
124
125 /*
126 * If we crash with IP==0, the last successfully executed instruction
127 * was probably an indirect function call with a NULL function pointer,
128 * and we don't have unwind information for NULL.
129 * This hardcoded ORC entry for IP==0 allows us to unwind from a NULL function
130 * pointer into its parent and then continue normally from there.
131 */
132 static struct orc_entry null_orc_entry = {
133 .sp_offset = sizeof(long),
134 .sp_reg = ORC_REG_SP,
135 .bp_reg = ORC_REG_UNDEFINED,
136 .type = UNWIND_HINT_TYPE_CALL
137 };
138
139 /* Fake frame pointer entry -- used as a fallback for generated code */
140 static struct orc_entry orc_fp_entry = {
141 .type = UNWIND_HINT_TYPE_CALL,
142 .sp_reg = ORC_REG_BP,
143 .sp_offset = 16,
144 .bp_reg = ORC_REG_PREV_SP,
145 .bp_offset = -16,
146 .end = 0,
147 };
148
orc_find(unsigned long ip)149 static struct orc_entry *orc_find(unsigned long ip)
150 {
151 static struct orc_entry *orc;
152
153 if (ip == 0)
154 return &null_orc_entry;
155
156 /* For non-init vmlinux addresses, use the fast lookup table: */
157 if (ip >= LOOKUP_START_IP && ip < LOOKUP_STOP_IP) {
158 unsigned int idx, start, stop;
159
160 idx = (ip - LOOKUP_START_IP) / LOOKUP_BLOCK_SIZE;
161
162 if (unlikely((idx >= lookup_num_blocks-1))) {
163 orc_warn("WARNING: bad lookup idx: idx=%u num=%u ip=%pB\n",
164 idx, lookup_num_blocks, (void *)ip);
165 return NULL;
166 }
167
168 start = orc_lookup[idx];
169 stop = orc_lookup[idx + 1] + 1;
170
171 if (unlikely((__start_orc_unwind + start >= __stop_orc_unwind) ||
172 (__start_orc_unwind + stop > __stop_orc_unwind))) {
173 orc_warn("WARNING: bad lookup value: idx=%u num=%u start=%u stop=%u ip=%pB\n",
174 idx, lookup_num_blocks, start, stop, (void *)ip);
175 return NULL;
176 }
177
178 return __orc_find(__start_orc_unwind_ip + start,
179 __start_orc_unwind + start, stop - start, ip);
180 }
181
182 /* vmlinux .init slow lookup: */
183 if (init_kernel_text(ip))
184 return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
185 __stop_orc_unwind_ip - __start_orc_unwind_ip, ip);
186
187 /* Module lookup: */
188 orc = orc_module_find(ip);
189 if (orc)
190 return orc;
191
192 return orc_ftrace_find(ip);
193 }
194
195 #ifdef CONFIG_MODULES
196
197 static DEFINE_MUTEX(sort_mutex);
198 static int *cur_orc_ip_table = __start_orc_unwind_ip;
199 static struct orc_entry *cur_orc_table = __start_orc_unwind;
200
orc_sort_swap(void * _a,void * _b,int size)201 static void orc_sort_swap(void *_a, void *_b, int size)
202 {
203 struct orc_entry *orc_a, *orc_b;
204 struct orc_entry orc_tmp;
205 int *a = _a, *b = _b, tmp;
206 int delta = _b - _a;
207
208 /* Swap the .orc_unwind_ip entries: */
209 tmp = *a;
210 *a = *b + delta;
211 *b = tmp - delta;
212
213 /* Swap the corresponding .orc_unwind entries: */
214 orc_a = cur_orc_table + (a - cur_orc_ip_table);
215 orc_b = cur_orc_table + (b - cur_orc_ip_table);
216 orc_tmp = *orc_a;
217 *orc_a = *orc_b;
218 *orc_b = orc_tmp;
219 }
220
orc_sort_cmp(const void * _a,const void * _b)221 static int orc_sort_cmp(const void *_a, const void *_b)
222 {
223 struct orc_entry *orc_a;
224 const int *a = _a, *b = _b;
225 unsigned long a_val = orc_ip(a);
226 unsigned long b_val = orc_ip(b);
227
228 if (a_val > b_val)
229 return 1;
230 if (a_val < b_val)
231 return -1;
232
233 /*
234 * The "weak" section terminator entries need to always be on the left
235 * to ensure the lookup code skips them in favor of real entries.
236 * These terminator entries exist to handle any gaps created by
237 * whitelisted .o files which didn't get objtool generation.
238 */
239 orc_a = cur_orc_table + (a - cur_orc_ip_table);
240 return orc_a->sp_reg == ORC_REG_UNDEFINED && !orc_a->end ? -1 : 1;
241 }
242
unwind_module_init(struct module * mod,void * _orc_ip,size_t orc_ip_size,void * _orc,size_t orc_size)243 void unwind_module_init(struct module *mod, void *_orc_ip, size_t orc_ip_size,
244 void *_orc, size_t orc_size)
245 {
246 int *orc_ip = _orc_ip;
247 struct orc_entry *orc = _orc;
248 unsigned int num_entries = orc_ip_size / sizeof(int);
249
250 WARN_ON_ONCE(orc_ip_size % sizeof(int) != 0 ||
251 orc_size % sizeof(*orc) != 0 ||
252 num_entries != orc_size / sizeof(*orc));
253
254 /*
255 * The 'cur_orc_*' globals allow the orc_sort_swap() callback to
256 * associate an .orc_unwind_ip table entry with its corresponding
257 * .orc_unwind entry so they can both be swapped.
258 */
259 mutex_lock(&sort_mutex);
260 cur_orc_ip_table = orc_ip;
261 cur_orc_table = orc;
262 sort(orc_ip, num_entries, sizeof(int), orc_sort_cmp, orc_sort_swap);
263 mutex_unlock(&sort_mutex);
264
265 mod->arch.orc_unwind_ip = orc_ip;
266 mod->arch.orc_unwind = orc;
267 mod->arch.num_orcs = num_entries;
268 }
269 #endif
270
unwind_init(void)271 void __init unwind_init(void)
272 {
273 size_t orc_ip_size = (void *)__stop_orc_unwind_ip - (void *)__start_orc_unwind_ip;
274 size_t orc_size = (void *)__stop_orc_unwind - (void *)__start_orc_unwind;
275 size_t num_entries = orc_ip_size / sizeof(int);
276 struct orc_entry *orc;
277 int i;
278
279 if (!num_entries || orc_ip_size % sizeof(int) != 0 ||
280 orc_size % sizeof(struct orc_entry) != 0 ||
281 num_entries != orc_size / sizeof(struct orc_entry)) {
282 orc_warn("WARNING: Bad or missing .orc_unwind table. Disabling unwinder.\n");
283 return;
284 }
285
286 /*
287 * Note, the orc_unwind and orc_unwind_ip tables were already
288 * sorted at build time via the 'sorttable' tool.
289 * It's ready for binary search straight away, no need to sort it.
290 */
291
292 /* Initialize the fast lookup table: */
293 lookup_num_blocks = orc_lookup_end - orc_lookup;
294 for (i = 0; i < lookup_num_blocks-1; i++) {
295 orc = __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
296 num_entries,
297 LOOKUP_START_IP + (LOOKUP_BLOCK_SIZE * i));
298 if (!orc) {
299 orc_warn("WARNING: Corrupt .orc_unwind table. Disabling unwinder.\n");
300 return;
301 }
302
303 orc_lookup[i] = orc - __start_orc_unwind;
304 }
305
306 /* Initialize the ending block: */
307 orc = __orc_find(__start_orc_unwind_ip, __start_orc_unwind, num_entries,
308 LOOKUP_STOP_IP);
309 if (!orc) {
310 orc_warn("WARNING: Corrupt .orc_unwind table. Disabling unwinder.\n");
311 return;
312 }
313 orc_lookup[lookup_num_blocks-1] = orc - __start_orc_unwind;
314
315 orc_init = true;
316 }
317
unwind_get_return_address(struct unwind_state * state)318 unsigned long unwind_get_return_address(struct unwind_state *state)
319 {
320 if (unwind_done(state))
321 return 0;
322
323 return __kernel_text_address(state->ip) ? state->ip : 0;
324 }
325 EXPORT_SYMBOL_GPL(unwind_get_return_address);
326
unwind_get_return_address_ptr(struct unwind_state * state)327 unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
328 {
329 if (unwind_done(state))
330 return NULL;
331
332 if (state->regs)
333 return &state->regs->ip;
334
335 if (state->sp)
336 return (unsigned long *)state->sp - 1;
337
338 return NULL;
339 }
340
stack_access_ok(struct unwind_state * state,unsigned long _addr,size_t len)341 static bool stack_access_ok(struct unwind_state *state, unsigned long _addr,
342 size_t len)
343 {
344 struct stack_info *info = &state->stack_info;
345 void *addr = (void *)_addr;
346
347 if (!on_stack(info, addr, len) &&
348 (get_stack_info(addr, state->task, info, &state->stack_mask)))
349 return false;
350
351 return true;
352 }
353
deref_stack_reg(struct unwind_state * state,unsigned long addr,unsigned long * val)354 static bool deref_stack_reg(struct unwind_state *state, unsigned long addr,
355 unsigned long *val)
356 {
357 if (!stack_access_ok(state, addr, sizeof(long)))
358 return false;
359
360 *val = READ_ONCE_NOCHECK(*(unsigned long *)addr);
361 return true;
362 }
363
deref_stack_regs(struct unwind_state * state,unsigned long addr,unsigned long * ip,unsigned long * sp)364 static bool deref_stack_regs(struct unwind_state *state, unsigned long addr,
365 unsigned long *ip, unsigned long *sp)
366 {
367 struct pt_regs *regs = (struct pt_regs *)addr;
368
369 /* x86-32 support will be more complicated due to the ®s->sp hack */
370 BUILD_BUG_ON(IS_ENABLED(CONFIG_X86_32));
371
372 if (!stack_access_ok(state, addr, sizeof(struct pt_regs)))
373 return false;
374
375 *ip = READ_ONCE_NOCHECK(regs->ip);
376 *sp = READ_ONCE_NOCHECK(regs->sp);
377 return true;
378 }
379
deref_stack_iret_regs(struct unwind_state * state,unsigned long addr,unsigned long * ip,unsigned long * sp)380 static bool deref_stack_iret_regs(struct unwind_state *state, unsigned long addr,
381 unsigned long *ip, unsigned long *sp)
382 {
383 struct pt_regs *regs = (void *)addr - IRET_FRAME_OFFSET;
384
385 if (!stack_access_ok(state, addr, IRET_FRAME_SIZE))
386 return false;
387
388 *ip = READ_ONCE_NOCHECK(regs->ip);
389 *sp = READ_ONCE_NOCHECK(regs->sp);
390 return true;
391 }
392
393 /*
394 * If state->regs is non-NULL, and points to a full pt_regs, just get the reg
395 * value from state->regs.
396 *
397 * Otherwise, if state->regs just points to IRET regs, and the previous frame
398 * had full regs, it's safe to get the value from the previous regs. This can
399 * happen when early/late IRQ entry code gets interrupted by an NMI.
400 */
get_reg(struct unwind_state * state,unsigned int reg_off,unsigned long * val)401 static bool get_reg(struct unwind_state *state, unsigned int reg_off,
402 unsigned long *val)
403 {
404 unsigned int reg = reg_off/8;
405
406 if (!state->regs)
407 return false;
408
409 if (state->full_regs) {
410 *val = READ_ONCE_NOCHECK(((unsigned long *)state->regs)[reg]);
411 return true;
412 }
413
414 if (state->prev_regs) {
415 *val = READ_ONCE_NOCHECK(((unsigned long *)state->prev_regs)[reg]);
416 return true;
417 }
418
419 return false;
420 }
421
unwind_next_frame(struct unwind_state * state)422 bool unwind_next_frame(struct unwind_state *state)
423 {
424 unsigned long ip_p, sp, tmp, orig_ip = state->ip, prev_sp = state->sp;
425 enum stack_type prev_type = state->stack_info.type;
426 struct orc_entry *orc;
427 bool indirect = false;
428
429 if (unwind_done(state))
430 return false;
431
432 /* Don't let modules unload while we're reading their ORC data. */
433 preempt_disable();
434
435 /* End-of-stack check for user tasks: */
436 if (state->regs && user_mode(state->regs))
437 goto the_end;
438
439 /*
440 * Find the orc_entry associated with the text address.
441 *
442 * For a call frame (as opposed to a signal frame), state->ip points to
443 * the instruction after the call. That instruction's stack layout
444 * could be different from the call instruction's layout, for example
445 * if the call was to a noreturn function. So get the ORC data for the
446 * call instruction itself.
447 */
448 orc = orc_find(state->signal ? state->ip : state->ip - 1);
449 if (!orc) {
450 /*
451 * As a fallback, try to assume this code uses a frame pointer.
452 * This is useful for generated code, like BPF, which ORC
453 * doesn't know about. This is just a guess, so the rest of
454 * the unwind is no longer considered reliable.
455 */
456 orc = &orc_fp_entry;
457 state->error = true;
458 }
459
460 /* End-of-stack check for kernel threads: */
461 if (orc->sp_reg == ORC_REG_UNDEFINED) {
462 if (!orc->end)
463 goto err;
464
465 goto the_end;
466 }
467
468 /* Find the previous frame's stack: */
469 switch (orc->sp_reg) {
470 case ORC_REG_SP:
471 sp = state->sp + orc->sp_offset;
472 break;
473
474 case ORC_REG_BP:
475 sp = state->bp + orc->sp_offset;
476 break;
477
478 case ORC_REG_SP_INDIRECT:
479 sp = state->sp + orc->sp_offset;
480 indirect = true;
481 break;
482
483 case ORC_REG_BP_INDIRECT:
484 sp = state->bp + orc->sp_offset;
485 indirect = true;
486 break;
487
488 case ORC_REG_R10:
489 if (!get_reg(state, offsetof(struct pt_regs, r10), &sp)) {
490 orc_warn_current("missing R10 value at %pB\n",
491 (void *)state->ip);
492 goto err;
493 }
494 break;
495
496 case ORC_REG_R13:
497 if (!get_reg(state, offsetof(struct pt_regs, r13), &sp)) {
498 orc_warn_current("missing R13 value at %pB\n",
499 (void *)state->ip);
500 goto err;
501 }
502 break;
503
504 case ORC_REG_DI:
505 if (!get_reg(state, offsetof(struct pt_regs, di), &sp)) {
506 orc_warn_current("missing RDI value at %pB\n",
507 (void *)state->ip);
508 goto err;
509 }
510 break;
511
512 case ORC_REG_DX:
513 if (!get_reg(state, offsetof(struct pt_regs, dx), &sp)) {
514 orc_warn_current("missing DX value at %pB\n",
515 (void *)state->ip);
516 goto err;
517 }
518 break;
519
520 default:
521 orc_warn("unknown SP base reg %d at %pB\n",
522 orc->sp_reg, (void *)state->ip);
523 goto err;
524 }
525
526 if (indirect) {
527 if (!deref_stack_reg(state, sp, &sp))
528 goto err;
529 }
530
531 /* Find IP, SP and possibly regs: */
532 switch (orc->type) {
533 case UNWIND_HINT_TYPE_CALL:
534 ip_p = sp - sizeof(long);
535
536 if (!deref_stack_reg(state, ip_p, &state->ip))
537 goto err;
538
539 state->ip = ftrace_graph_ret_addr(state->task, &state->graph_idx,
540 state->ip, (void *)ip_p);
541
542 state->sp = sp;
543 state->regs = NULL;
544 state->prev_regs = NULL;
545 state->signal = false;
546 break;
547
548 case UNWIND_HINT_TYPE_REGS:
549 if (!deref_stack_regs(state, sp, &state->ip, &state->sp)) {
550 orc_warn_current("can't access registers at %pB\n",
551 (void *)orig_ip);
552 goto err;
553 }
554
555 state->regs = (struct pt_regs *)sp;
556 state->prev_regs = NULL;
557 state->full_regs = true;
558 state->signal = true;
559 break;
560
561 case UNWIND_HINT_TYPE_REGS_PARTIAL:
562 if (!deref_stack_iret_regs(state, sp, &state->ip, &state->sp)) {
563 orc_warn_current("can't access iret registers at %pB\n",
564 (void *)orig_ip);
565 goto err;
566 }
567
568 if (state->full_regs)
569 state->prev_regs = state->regs;
570 state->regs = (void *)sp - IRET_FRAME_OFFSET;
571 state->full_regs = false;
572 state->signal = true;
573 break;
574
575 default:
576 orc_warn("unknown .orc_unwind entry type %d at %pB\n",
577 orc->type, (void *)orig_ip);
578 goto err;
579 }
580
581 /* Find BP: */
582 switch (orc->bp_reg) {
583 case ORC_REG_UNDEFINED:
584 if (get_reg(state, offsetof(struct pt_regs, bp), &tmp))
585 state->bp = tmp;
586 break;
587
588 case ORC_REG_PREV_SP:
589 if (!deref_stack_reg(state, sp + orc->bp_offset, &state->bp))
590 goto err;
591 break;
592
593 case ORC_REG_BP:
594 if (!deref_stack_reg(state, state->bp + orc->bp_offset, &state->bp))
595 goto err;
596 break;
597
598 default:
599 orc_warn("unknown BP base reg %d for ip %pB\n",
600 orc->bp_reg, (void *)orig_ip);
601 goto err;
602 }
603
604 /* Prevent a recursive loop due to bad ORC data: */
605 if (state->stack_info.type == prev_type &&
606 on_stack(&state->stack_info, (void *)state->sp, sizeof(long)) &&
607 state->sp <= prev_sp) {
608 orc_warn_current("stack going in the wrong direction? at %pB\n",
609 (void *)orig_ip);
610 goto err;
611 }
612
613 preempt_enable();
614 return true;
615
616 err:
617 state->error = true;
618
619 the_end:
620 preempt_enable();
621 state->stack_info.type = STACK_TYPE_UNKNOWN;
622 return false;
623 }
624 EXPORT_SYMBOL_GPL(unwind_next_frame);
625
__unwind_start(struct unwind_state * state,struct task_struct * task,struct pt_regs * regs,unsigned long * first_frame)626 void __unwind_start(struct unwind_state *state, struct task_struct *task,
627 struct pt_regs *regs, unsigned long *first_frame)
628 {
629 memset(state, 0, sizeof(*state));
630 state->task = task;
631
632 if (!orc_init)
633 goto err;
634
635 /*
636 * Refuse to unwind the stack of a task while it's executing on another
637 * CPU. This check is racy, but that's ok: the unwinder has other
638 * checks to prevent it from going off the rails.
639 */
640 if (task_on_another_cpu(task))
641 goto err;
642
643 if (regs) {
644 if (user_mode(regs))
645 goto the_end;
646
647 state->ip = regs->ip;
648 state->sp = regs->sp;
649 state->bp = regs->bp;
650 state->regs = regs;
651 state->full_regs = true;
652 state->signal = true;
653
654 } else if (task == current) {
655 asm volatile("lea (%%rip), %0\n\t"
656 "mov %%rsp, %1\n\t"
657 "mov %%rbp, %2\n\t"
658 : "=r" (state->ip), "=r" (state->sp),
659 "=r" (state->bp));
660
661 } else {
662 struct inactive_task_frame *frame = (void *)task->thread.sp;
663
664 state->sp = task->thread.sp + sizeof(*frame);
665 state->bp = READ_ONCE_NOCHECK(frame->bp);
666 state->ip = READ_ONCE_NOCHECK(frame->ret_addr);
667 state->signal = (void *)state->ip == ret_from_fork;
668 }
669
670 if (get_stack_info((unsigned long *)state->sp, state->task,
671 &state->stack_info, &state->stack_mask)) {
672 /*
673 * We weren't on a valid stack. It's possible that
674 * we overflowed a valid stack into a guard page.
675 * See if the next page up is valid so that we can
676 * generate some kind of backtrace if this happens.
677 */
678 void *next_page = (void *)PAGE_ALIGN((unsigned long)state->sp);
679 state->error = true;
680 if (get_stack_info(next_page, state->task, &state->stack_info,
681 &state->stack_mask))
682 return;
683 }
684
685 /*
686 * The caller can provide the address of the first frame directly
687 * (first_frame) or indirectly (regs->sp) to indicate which stack frame
688 * to start unwinding at. Skip ahead until we reach it.
689 */
690
691 /* When starting from regs, skip the regs frame: */
692 if (regs) {
693 unwind_next_frame(state);
694 return;
695 }
696
697 /* Otherwise, skip ahead to the user-specified starting frame: */
698 while (!unwind_done(state) &&
699 (!on_stack(&state->stack_info, first_frame, sizeof(long)) ||
700 state->sp <= (unsigned long)first_frame))
701 unwind_next_frame(state);
702
703 return;
704
705 err:
706 state->error = true;
707 the_end:
708 state->stack_info.type = STACK_TYPE_UNKNOWN;
709 }
710 EXPORT_SYMBOL_GPL(__unwind_start);
711