From 0a44b419abeca91b734c9cf6ce1df62d06fc683d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 29 Mar 2023 10:21:34 -0700 Subject: [PATCH] libc/common: Allocate default malloc arena for non-minimal-libc uses When using the common malloc implementation on systems not using the minimal C library, allocate a reasonable default malloc heap according to the following rules (adopted from the Picolibc heap size defaults): * When an MMU is available, allocate 16kB. * When USERSPACE is enabled for a device with an MPU require PoT alignment, allocate 1024 bytes * Otherwise, use all available memory. Signed-off-by: Keith Packard --- lib/libc/common/Kconfig | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/libc/common/Kconfig b/lib/libc/common/Kconfig index 4d049e82107..01799428c20 100644 --- a/lib/libc/common/Kconfig +++ b/lib/libc/common/Kconfig @@ -20,11 +20,29 @@ config COMMON_LIBC_MALLOC config COMMON_LIBC_MALLOC_ARENA_SIZE int "Size of the common C library malloc arena" depends on COMMON_LIBC_MALLOC - default 0 + default 0 if MINIMAL_LIBC + default 16384 if MMU + default 1024 if USERSPACE && MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT + default -1 help Indicate the size in bytes of the memory arena used for common C library malloc() implementation. + If set to zero, then no malloc() heap will be available. + + If set to -1, then all remaining system RAM will be used for this + area. + + If user mode is enabled, and MPU hardware has requirements that + regions be sized to a power of two and aligned to their size, + then this must be defined as a power of two or a compile error + will result. + + When using the minimal C library, the default is to have no + malloc heap. Otherwise, on systems with an MMU the default is + 16kB and all other systems will default to using all remaining + ram for the malloc heap. + config COMMON_LIBC_CALLOC bool "Common C library calloc" depends on COMMON_LIBC_MALLOC