1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

tests: Fix thread return with local message queue

When a message queue is configured from the stack, that main function
must never return -- otherwise, during sched_task_exit (which the
thread's function "returns" to), message senders might still send
messages into already freed stack space (which would be reused by
sched_task_exit).

Co-authored-by: Marian Buschsieweke <maribu@users.noreply.github.com>
This commit is contained in:
chrysn 2022-01-11 16:54:56 +01:00
parent c49f156e6e
commit 87847b1de4
3 changed files with 15 additions and 10 deletions

View File

@ -109,12 +109,13 @@ void print_register(char reg, int num_bytes)
char rx_handler_stack[THREAD_STACKSIZE_MAIN];
static msg_t _msg_q[1];
/* RX handler that waits for a message from the ISR */
void *nrf24l01p_rx_handler(void *arg)
{
(void)arg;
msg_t msg_q[1];
msg_init_queue(msg_q, 1);
msg_init_queue(_msg_q, 1);
unsigned int pid = thread_getpid();
char rx_buf[NRF24L01P_MAX_DATA_LENGTH];

View File

@ -129,10 +129,11 @@ static void test1(void)
puts("first: end");
}
static msg_t _sema_thread_queue[SEMAPHORE_MSG_QUEUE_SIZE];
static void *priority_sema_thread(void *name)
{
msg_t msg_queue[SEMAPHORE_MSG_QUEUE_SIZE];
msg_init_queue(msg_queue, SEMAPHORE_MSG_QUEUE_SIZE);
msg_init_queue(_sema_thread_queue, SEMAPHORE_MSG_QUEUE_SIZE);
sem_wait(&s1);
printf("Thread '%s' woke up.\n", (const char *) name);
return NULL;
@ -176,11 +177,12 @@ void test2(void)
}
}
static msg_t _one_two_queue[SEMAPHORE_MSG_QUEUE_SIZE];
static void *test3_one_two_thread(void *arg)
{
msg_t msg_queue[SEMAPHORE_MSG_QUEUE_SIZE];
(void)arg;
msg_init_queue(msg_queue, SEMAPHORE_MSG_QUEUE_SIZE);
msg_init_queue(_one_two_queue, SEMAPHORE_MSG_QUEUE_SIZE);
sem_wait(&s1);
puts("Thread 1 woke up after waiting for s1.");
sem_wait(&s2);
@ -188,11 +190,12 @@ static void *test3_one_two_thread(void *arg)
return NULL;
}
static msg_t _two_one_queue[SEMAPHORE_MSG_QUEUE_SIZE];
static void *test3_two_one_thread(void *arg)
{
msg_t msg_queue[SEMAPHORE_MSG_QUEUE_SIZE];
(void)arg;
msg_init_queue(msg_queue, SEMAPHORE_MSG_QUEUE_SIZE);
msg_init_queue(_two_one_queue, SEMAPHORE_MSG_QUEUE_SIZE);
sem_wait(&s2);
puts("Thread 2 woke up after waiting for s2.");
sem_wait(&s1);

View File

@ -52,13 +52,14 @@ void *sender_thread(void *arg)
return NULL;
}
static msg_t _msg_q[1];
int main(void)
{
msg_t msg;
p_recv = thread_getpid();
msg_t msg_q[1];
msg_init_queue(msg_q, 1);
msg_init_queue(_msg_q, 1);
p_send = thread_create(t1_stack, sizeof(t1_stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,