mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-10-10 08:03:04 -04:00
kernel: avoid divide-by-zero in thread_get_debug_info() for zero-size stacks
thread_get_debug_info() computes the current stack usage as stack_used_current * 100 / thread->stack_size with no guard against a zero stack size. On hosted targets the main thread has stack_size == 0, so opening the "View OS stacks" debug screen divides by zero and panics with a floating point exception. Guard the division and report 0% when the stack size is unknown, which matches the stack_usage() helper. Likely affects all hosted non-SDL targets, but tested/confirmed on my HiBy R1. Change-Id: I8ecc56f53f1e97e8a59ca71c0e08a66093fecbae
This commit is contained in:
parent
91774611cd
commit
8acd1c14d6
1 changed files with 4 additions and 1 deletions
|
|
@ -309,7 +309,10 @@ int thread_get_debug_info(unsigned int thread_id,
|
|||
size_t stack_used_current =
|
||||
thread->stack_size - (thread->context.sp - (uintptr_t)thread->stack);
|
||||
|
||||
infop->stack_usage_cur = stack_used_current * 100 / thread->stack_size;
|
||||
/* Hosted implementations typically have the main stack managed
|
||||
by the OS, so we create a fake entry with 0 length */
|
||||
infop->stack_usage_cur = thread->stack_size ?
|
||||
stack_used_current * 100 / thread->stack_size : 0;
|
||||
#endif
|
||||
#if NUM_CORES > 1
|
||||
infop->core = thread->core;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue