From ca49d6a85776ed6a3fdfe3da61b54fbf25c05983 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 3 Jun 2019 10:22:31 -0400 Subject: [PATCH] PTHREAD_MUTEX_DEFINE(): don't store into the _k_mutex section The _k_mutex linker section is used to gather instances of struct k_mutex into a list so that init_mutex_module() could iterate that list to perform runtime initialization tasks. In this case, we're not defining a struct k_mutex but rather a struct pthread_mutex which is a completely different structure. Not only those struct pthread_mutex would be corrupted with unexpected data, but since they're not the same size as struct k_mutex, the actual struct k_mutex instances that follow in the list would be misaligned and get corrupted too. There is nothing that requires runtime initialization in the static definition of a struct pthread_mutex so let's remove the section attribute. Signed-off-by: Nicolas Pitre --- include/posix/pthread.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/posix/pthread.h b/include/posix/pthread.h index 350c28e641b..19846b93c77 100644 --- a/include/posix/pthread.h +++ b/include/posix/pthread.h @@ -160,8 +160,7 @@ static inline int pthread_condattr_destroy(pthread_condattr_t *att) * @param name Symbol name of the mutex */ #define PTHREAD_MUTEX_DEFINE(name) \ - struct pthread_mutex name \ - __in_section(_k_mutex, static, name) = \ + struct pthread_mutex name = \ { \ .lock_count = 0, \ .wait_q = Z_WAIT_Q_INIT(&name.wait_q), \