.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * arch/arm/kernel/unwind.c |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2008 ARM Limited |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License version 2 as |
---|
8 | | - * published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program; if not, write to the Free Software |
---|
17 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | | - * |
---|
19 | 6 | * |
---|
20 | 7 | * Stack unwinding support for ARM |
---|
21 | 8 | * |
---|
.. | .. |
---|
313 | 300 | return URC_OK; |
---|
314 | 301 | } |
---|
315 | 302 | |
---|
| 303 | +static unsigned long unwind_decode_uleb128(struct unwind_ctrl_block *ctrl) |
---|
| 304 | +{ |
---|
| 305 | + unsigned long bytes = 0; |
---|
| 306 | + unsigned long insn; |
---|
| 307 | + unsigned long result = 0; |
---|
| 308 | + |
---|
| 309 | + /* |
---|
| 310 | + * unwind_get_byte() will advance `ctrl` one instruction at a time, so |
---|
| 311 | + * loop until we get an instruction byte where bit 7 is not set. |
---|
| 312 | + * |
---|
| 313 | + * Note: This decodes a maximum of 4 bytes to output 28 bits data where |
---|
| 314 | + * max is 0xfffffff: that will cover a vsp increment of 1073742336, hence |
---|
| 315 | + * it is sufficient for unwinding the stack. |
---|
| 316 | + */ |
---|
| 317 | + do { |
---|
| 318 | + insn = unwind_get_byte(ctrl); |
---|
| 319 | + result |= (insn & 0x7f) << (bytes * 7); |
---|
| 320 | + bytes++; |
---|
| 321 | + } while (!!(insn & 0x80) && (bytes != sizeof(result))); |
---|
| 322 | + |
---|
| 323 | + return result; |
---|
| 324 | +} |
---|
| 325 | + |
---|
316 | 326 | /* |
---|
317 | 327 | * Execute the current unwind instruction. |
---|
318 | 328 | */ |
---|
.. | .. |
---|
366 | 376 | if (ret) |
---|
367 | 377 | goto error; |
---|
368 | 378 | } else if (insn == 0xb2) { |
---|
369 | | - unsigned long uleb128 = unwind_get_byte(ctrl); |
---|
| 379 | + unsigned long uleb128 = unwind_decode_uleb128(ctrl); |
---|
370 | 380 | |
---|
371 | 381 | ctrl->vrs[SP] += 0x204 + (uleb128 << 2); |
---|
372 | 382 | } else { |
---|
.. | .. |
---|
457 | 467 | ctrl.vrs[PC] = ctrl.vrs[LR]; |
---|
458 | 468 | |
---|
459 | 469 | /* check for infinite loop */ |
---|
460 | | - if (frame->pc == ctrl.vrs[PC]) |
---|
| 470 | + if (frame->pc == ctrl.vrs[PC] && frame->sp == ctrl.vrs[SP]) |
---|
461 | 471 | return -URC_FAILURE; |
---|
462 | 472 | |
---|
463 | 473 | frame->fp = ctrl.vrs[FP]; |
---|
.. | .. |
---|
468 | 478 | return URC_OK; |
---|
469 | 479 | } |
---|
470 | 480 | |
---|
471 | | -void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk) |
---|
| 481 | +void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk, |
---|
| 482 | + const char *loglvl) |
---|
472 | 483 | { |
---|
473 | 484 | struct stackframe frame; |
---|
474 | 485 | |
---|
.. | .. |
---|
506 | 517 | urc = unwind_frame(&frame); |
---|
507 | 518 | if (urc < 0) |
---|
508 | 519 | break; |
---|
509 | | - dump_backtrace_entry(where, frame.pc, frame.sp - 4); |
---|
| 520 | + dump_backtrace_entry(where, frame.pc, frame.sp - 4, loglvl); |
---|
510 | 521 | } |
---|
511 | 522 | } |
---|
512 | 523 | |
---|