libc/common: Place malloc data structures in libc partition

Leave the malloc partition so that it only contains the heap itself; this
lets the initialization code adjust the address range when configuring the
arena at startup.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2023-10-04 09:31:04 -07:00 committed by Johan Hedberg
commit e7126b5d84
2 changed files with 6 additions and 5 deletions

View file

@ -13,6 +13,7 @@ config COMMON_LIBC_TIME
config COMMON_LIBC_MALLOC
bool "Common C library malloc implementation"
select NEED_LIBC_MEM_PARTITION if COMMON_LIBC_MALLOC_ARENA_SIZE != 0
help
Common implementation of malloc family that uses the kernel heap
API.

View file

@ -33,10 +33,8 @@ LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
# if Z_MALLOC_PARTITION_EXISTS
K_APPMEM_PARTITION_DEFINE(z_malloc_partition);
# define POOL_SECTION Z_GENERIC_SECTION(K_APP_DMEM_SECTION(z_malloc_partition))
# define MALLOC_SECTION Z_GENERIC_SECTION(K_APP_DMEM_SECTION(z_malloc_partition))
# else
# define POOL_SECTION __noinit
# define MALLOC_SECTION
# endif /* CONFIG_USERSPACE */
# if defined(CONFIG_MMU) && CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE < 0
@ -77,6 +75,8 @@ K_APPMEM_PARTITION_DEFINE(z_malloc_partition);
# if CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE > 0
# define HEAP_STATIC
/* Static allocation of heap in BSS */
# define HEAP_SIZE ROUND_UP(CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE, HEAP_ALIGN)
@ -114,10 +114,10 @@ extern char _heap_sentry[];
# endif /* else ALLOCATE_HEAP_AT_STARTUP */
POOL_SECTION static struct sys_heap z_malloc_heap;
Z_LIBC_DATA static struct sys_heap z_malloc_heap;
#ifdef CONFIG_MULTITHREADING
MALLOC_SECTION SYS_MUTEX_DEFINE(z_malloc_heap_mutex);
Z_LIBC_DATA SYS_MUTEX_DEFINE(z_malloc_heap_mutex);
static inline void
malloc_lock(void) {
@ -225,7 +225,7 @@ static int malloc_prepare(void)
heap_size = HEAP_SIZE;
#endif
#if Z_MALLOC_PARTITION_EXISTS
#if Z_MALLOC_PARTITION_EXISTS && !defined(HEAP_STATIC)
z_malloc_partition.start = POINTER_TO_UINT(heap_base);
z_malloc_partition.size = heap_size;
z_malloc_partition.attr = K_MEM_PARTITION_P_RW_U_RW;