This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a7f9f95af75994658fb2c979badaa6757eebbe1b Author: Marco Casaroli <[email protected]> AuthorDate: Tue Nov 17 12:23:59 2026 +0100 mm: Default the heap alignment to 16 on 64-bit architectures. malloc(), calloc() and realloc() must return memory that is aligned for every type (C11 7.22.3), that is to alignof(max_align_t). On arm64, x86_64 and 64-bit RISC-V, alignof(max_align_t) is 16 (long double), but CONFIG_MM_DEFAULT_ALIGNMENT is 8, so half of the heap blocks are 8 modulo 16. On x86_64 an aligned SSE access to such a block (movaps, movdqa) gives a general protection fault. GCC also assumes the alignment of 16: at -O2 it folds (uintptr_t)malloc(n) & 15 to 0. Make the default 16 when ARCH_64BIT is set. The default of the other architectures and the value of configurations that set it do not change. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- mm/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index fd2feac0be1..4b65b93e1d4 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -77,12 +77,15 @@ config MM_KERNEL_HEAPSIZE config MM_DEFAULT_ALIGNMENT int "Memory default alignment in bytes" + default 16 if ARCH_64BIT default 8 range 0 64 ---help--- The memory default alignment in bytes, if this value is 0, the real memory default alignment is equal to sizoef(uintptr), if this value is not 0, this value must be 2^n and at least sizeof(uintptr). + The default is 16 on 64-bit architectures: malloc() must return + memory aligned for every type, and alignof(max_align_t) is 16 there. config MM_NODE_GUARDSIZE int "Memory node guard size"
