Skip to content

Commit e309f78

Browse files
MaochenWang1nashif
authored andcommitted
libc: common: Fix init hang issue
In device init phase, it will call _mbedtls_init before malloc_prepare as mbedtls has higher priority defined in SYS_INIT.. _mbedtls_init() will call psa_crypto_init() and malloc buffer, but z_malloc_heap is not initialized, which will cause device hang. Should call malloc_prepare() before _mbedtls_init to fix this issue, so add new Kconfig to increase the priority of libc to deafult 30. Signed-off-by: Maochen Wang <[email protected]>
1 parent b5be646 commit e309f78

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

kernel/Kconfig.device

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ config KERNEL_INIT_PRIORITY_OBJECTS
4545
priority needs to be higher than minimal default initialization
4646
priority.
4747

48+
config KERNEL_INIT_PRIORITY_LIBC
49+
int "LIBC initialization priority"
50+
default 35
51+
help
52+
LIBC uses this priority for initialization. This
53+
priority needs to be higher than minimal default initialization
54+
priority.
55+
4856
config KERNEL_INIT_PRIORITY_DEFAULT
4957
int "Default init priority"
5058
default 40

lib/libc/common/source/stdlib/malloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void free(void *ptr)
260260
malloc_unlock();
261261
}
262262

263-
SYS_INIT(malloc_prepare, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
263+
SYS_INIT(malloc_prepare, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_LIBC);
264264
#else /* No malloc arena */
265265
void *malloc(size_t size)
266266
{

lib/libc/newlib/libc-hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int malloc_prepare(void)
142142
return 0;
143143
}
144144

145-
SYS_INIT(malloc_prepare, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
145+
SYS_INIT(malloc_prepare, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_LIBC);
146146

147147
/* Current offset from HEAP_BASE of unused memory */
148148
LIBC_BSS static size_t heap_sz;

0 commit comments

Comments
 (0)