[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rockbox-cvs
Subject:    Fix battery_bench bug by using a static buffer for stack
From:       rockbox-gerrit-noreply--- via rockbox-cvs <rockbox-cvs () cool ! haxx ! se>
Date:       2021-07-22 13:50:28
Message-ID: 202107221350.16MDoSIE3666735 () stuffed ! shaftnet ! org
[Download RAW message or body]

commit 00129ac87205bfdf52a03e1053923ccf498501d4
Author: Aidan MacDonald <amachronic@protonmail.com>
Date:   Tue Jul 20 19:23:20 2021 +0100

    Fix battery_bench bug by using a static buffer for stack
    
    Since battery_bench is a TSR (terminate & stay resident) plugin it
    cannot allocate the plugin buffer -- various parts of the Rockbox
    core make use of it as temporary storage space. The buffer was used
    for stack space so this generated false 'Stkov' panics when one of
    those in-core users overwrote the buffer.
    
    The default stack size of 1kb is a bit small, so use 4x the default
    size to be on the safe side.
    
    This also fixes a minor issue where trying to view OS stack usage
    while battery_bench was running would cause audio dropouts, due to
    scanning the possibly huge stack with IRQs disabled.
    
    Change-Id: I2e6b76f9946db9090c1af61f7aa0a0dac0698c20

diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index 6c477cbd09..53931d1930 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -30,7 +30,7 @@
 #define EV_EXIT 1337
 
 /* seems to work with 1300, but who knows... */
-#define MIN_THREAD_STACK_SIZE DEFAULT_STACK_SIZE + 0x200
+#define THREAD_STACK_SIZE 4*DEFAULT_STACK_SIZE
 
 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
       (CONFIG_KEYPAD == IRIVER_H300_PAD)
@@ -279,8 +279,7 @@ static struct batt_info
 static struct
 {
     unsigned int id; /* worker thread id */
-    long   *stack;
-    ssize_t stacksize;
+    long stack[THREAD_STACK_SIZE / sizeof(long)];
 } gThread;
 
 static struct event_queue thread_q SHAREDBSS_ATTR;
@@ -607,25 +606,9 @@ enum plugin_status plugin_start(const void* parameter)
     }
 
     rb->memset(&gThread, 0, sizeof(gThread));
-    void   *buf;
-    size_t  buf_size;
-    buf = rb->plugin_get_buffer(&buf_size);
-    ALIGN_BUFFER(buf, buf_size, sizeof(long));
-    rb->memset(buf, 0, buf_size);
-
-    gThread.stacksize = buf_size;
-    gThread.stack = (long *) buf;
-
-    if (gThread.stacksize < MIN_THREAD_STACK_SIZE)
-    {
-        rb->splash(HZ*2, "Out of memory");
-        gThread.id = UINT_MAX;
-        return PLUGIN_ERROR;
-    }
-
     rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */
-    gThread.id = rb->create_thread(thread, gThread.stack,
-                                   gThread.stacksize, 0, "Battery Benchmark"
+    gThread.id = rb->create_thread(thread, gThread.stack, sizeof(gThread.stack),
+                                   0, "Battery Benchmark"
                                    IF_PRIO(, PRIORITY_BACKGROUND)
                                    IF_COP(, CPU));
 
_______________________________________________
rockbox-cvs mailing list
rockbox-cvs@cool.haxx.se
https://cool.haxx.se/cgi-bin/mailman/listinfo/rockbox-cvs

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic