summaryrefslogtreecommitdiff
path: root/apps/plugins/announce_status.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-07-20 21:12:34 +0100
committerWilliam Wilgus <me.theuser@yahoo.com>2021-07-21 11:26:14 +0000
commit48c29e3b3b3c0570c9f5c09579162ff4c317ba35 (patch)
treece550b50cef2a285a5071b71c7923a9afd757724 /apps/plugins/announce_status.c
parentb91ad60d6390f20ac7b86e5ae71398cf341d944b (diff)
downloadrockbox-48c29e3b3b3c0570c9f5c09579162ff4c317ba35.tar.gz
rockbox-48c29e3b3b3c0570c9f5c09579162ff4c317ba35.zip
Fix announce_status usage of plugin buffer
Since this is a TSR plugin, it is not safe to use the plugin buffer. Convert to using static buffers instead. Change-Id: Ic5b297468a99d77d56f5b75e52dafabeb80d2f78
Diffstat (limited to 'apps/plugins/announce_status.c')
-rw-r--r--apps/plugins/announce_status.c61
1 files changed, 19 insertions, 42 deletions
diff --git a/apps/plugins/announce_status.c b/apps/plugins/announce_status.c
index db7b890a51..84a44556ef 100644
--- a/apps/plugins/announce_status.c
+++ b/apps/plugins/announce_status.c
@@ -44,6 +44,8 @@
44#define CFG_FILE "/VoiceTSR.cfg" 44#define CFG_FILE "/VoiceTSR.cfg"
45#define CFG_VER 1 45#define CFG_VER 1
46 46
47#define THREAD_STACK_SIZE 4*DEFAULT_STACK_SIZE
48
47#if CONFIG_RTC 49#if CONFIG_RTC
48 #define K_TIME "DT D1;\n\n" 50 #define K_TIME "DT D1;\n\n"
49 #define K_DATE "DD D2;\n\n" 51 #define K_DATE "DD D2;\n\n"
@@ -59,7 +61,15 @@
59#define K_BATTERY "BP BM B1;\n" 61#define K_BATTERY "BP BM B1;\n"
60#define K_SLEEP "RS R2 R3;\n" 62#define K_SLEEP "RS R2 R3;\n"
61#define K_RUNTIME "RT R1;" 63#define K_RUNTIME "RT R1;"
62#define KEYBD_LAYOUT (K_TIME K_DATE K_TRACK_TA K_TRACK K_TRACK1 K_PLAYLIST K_BATTERY K_SLEEP K_RUNTIME) 64
65static const char keybd_layout[] =
66 K_TIME K_DATE K_TRACK_TA K_TRACK K_TRACK1 K_PLAYLIST K_BATTERY K_SLEEP K_RUNTIME;
67
68/* - each character in keybd_layout will consume one element
69 * - \n does not create a key, but it also consumes one element
70 * - the final null terminator is equivalent to \n
71 * - since sizeof includes the null terminator we don't need +1 for that. */
72static unsigned short kbd_buf[sizeof(keybd_layout)];
63 73
64/****************** prototypes ******************/ 74/****************** prototypes ******************/
65void print_scroll(char* string); /* implements a scrolling screen */ 75void print_scroll(char* string); /* implements a scrolling screen */
@@ -88,11 +98,7 @@ static struct
88 bool exiting; /* signal to the thread that we want to exit */ 98 bool exiting; /* signal to the thread that we want to exit */
89 unsigned int id; /* worker thread id */ 99 unsigned int id; /* worker thread id */
90 struct event_queue queue; /* thread event queue */ 100 struct event_queue queue; /* thread event queue */
91 long *stack; 101 long stack[THREAD_STACK_SIZE / sizeof(long)];
92 ssize_t stacksize;
93 void *buf;
94 size_t buf_size;
95
96} gThread; 102} gThread;
97 103
98static struct 104static struct
@@ -241,8 +247,7 @@ static int announce_menu_cb(int action,
241 struct gui_synclist *this_list) 247 struct gui_synclist *this_list)
242{ 248{
243 (void)this_item; 249 (void)this_item;
244 unsigned short *kbd_p = gThread.buf; 250 unsigned short* kbd_p;
245 size_t kbd_bufsz = gThread.buf_size;
246 251
247 int selection = rb->gui_synclist_get_sel_pos(this_list); 252 int selection = rb->gui_synclist_get_sel_pos(this_list);
248 253
@@ -293,7 +298,8 @@ static int announce_menu_cb(int action,
293 rb->splash(HZ / 2, ID2P(LANG_RESET_DONE_CLEAR)); 298 rb->splash(HZ / 2, ID2P(LANG_RESET_DONE_CLEAR));
294 break; 299 break;
295 case 9: /* inspect it */ 300 case 9: /* inspect it */
296 if (!kbd_create_layout(KEYBD_LAYOUT, kbd_p, kbd_bufsz)) 301 kbd_p = kbd_buf;
302 if (!kbd_create_layout(keybd_layout, kbd_p, sizeof(kbd_buf)))
297 kbd_p = NULL; 303 kbd_p = NULL;
298 304
299 rb->kbd_input(gAnnounce.wps_fmt, MAX_ANNOUNCE_WPS, kbd_p); 305 rb->kbd_input(gAnnounce.wps_fmt, MAX_ANNOUNCE_WPS, kbd_p);
@@ -439,45 +445,16 @@ void thread(void)
439 } 445 }
440} 446}
441 447
442void plugin_buffer_init(void)
443{
444 if (gThread.buf == 0)
445 {
446 rb->memset(&gThread, 0, sizeof(gThread));
447 gThread.buf = rb->plugin_get_buffer(&gThread.buf_size);
448 ALIGN_BUFFER(gThread.buf, gThread.buf_size, sizeof(long));
449 }
450}
451
452void thread_create(void) 448void thread_create(void)
453{ 449{
454 /* init the worker thread */
455 gThread.stacksize = gThread.buf_size;
456 gThread.buf_size -= gThread.stacksize;
457
458 gThread.stack = (long *) gThread.buf;
459
460 ALIGN_BUFFER(gThread.stack, gThread.stacksize, sizeof(long));
461
462 if (gThread.stacksize < DEFAULT_STACK_SIZE)
463 {
464 rb->splash(HZ*2, "Out of memory");
465 gThread.exiting = true;
466 rb->remove_event(PLAYBACK_EVENT_TRACK_CHANGE, playback_event_callback);
467 gThread.id = UINT_MAX;
468 return;
469 }
470
471 /* put the thread's queue in the bcast list */ 450 /* put the thread's queue in the bcast list */
472 rb->queue_init(&gThread.queue, true); 451 rb->queue_init(&gThread.queue, true);
473 452 gThread.id = rb->create_thread(thread, gThread.stack, sizeof(gThread.stack),
474 gThread.id = rb->create_thread(thread, gThread.stack, gThread.stacksize,
475 0, "vTSR" 453 0, "vTSR"
476 IF_PRIO(, PRIORITY_BACKGROUND) 454 IF_PRIO(, PRIORITY_BACKGROUND)
477 IF_COP(, CPU)); 455 IF_COP(, CPU));
478 rb->queue_post(&gThread.queue, EV_STARTUP, 0); 456 rb->queue_post(&gThread.queue, EV_STARTUP, 0);
479 rb->yield(); 457 rb->yield();
480
481} 458}
482 459
483void thread_quit(void) 460void thread_quit(void)
@@ -515,6 +492,8 @@ int plugin_main(const void* parameter)
515 bool settings = false; 492 bool settings = false;
516 int i = 0; 493 int i = 0;
517 494
495 rb->memset(&gThread, 0, sizeof(gThread));
496
518 gAnnounce.index = 0; 497 gAnnounce.index = 0;
519 gAnnounce.timeout = 0; 498 gAnnounce.timeout = 0;
520 499
@@ -555,8 +534,6 @@ int plugin_main(const void* parameter)
555 } 534 }
556 } 535 }
557 536
558 plugin_buffer_init(); /* need buffer for custom keyboard layout */
559
560 if (settings) 537 if (settings)
561 { 538 {
562 rb->splash(100, ID2P(LANG_SETTINGS)); 539 rb->splash(100, ID2P(LANG_SETTINGS));
@@ -673,7 +650,7 @@ static unsigned char* voice_info_group(unsigned char* current_token, bool testin
673 /* 650 /*
674 Sleep timer and runtime 651 Sleep timer and runtime
675 */ 652 */
676 int sleep_remaining = sleep_remaining = rb->get_sleep_timer(); 653 int sleep_remaining = rb->get_sleep_timer();
677 int runtime; 654 int runtime;
678 655
679 current_token++; 656 current_token++;