[En-Nut-Discussion] ARM Alignment for Threads

Harald Kipp harald.kipp at egnite.de
Thu Oct 10 11:30:58 CEST 2013

Hi Bob,

On 09.10.2013 16:40, Bob Wirka wrote:

> So, even if you set NUTMEM_ALIGNMENT to 8, you still can get a stack pointer on a 4 byte boundary.

Thanks for reporting this. Indeed, I consider this broken for all heap
alignments, which needs to be larger than the natural alignment of integers.

> My ugly hack was to set NUTMEM_ALIGNMENT to 8, and then to add 4 bytes of padding in HEAPNODE between 'size' and 'next'. The result is that threads get a stack that's aligned to 8 bytes, and va_arg() seems to work.

Consumes more RAM, but should serve well as a temporary work-around. I'd
suggest to make this the default for Cortex until someone presents a
better solution. Uwe, Ole, what do you think?

> A more elegant solution should be found, but I'm under the gun right now...

The Nut/OS heap management is intentionally simple. Not very responsive,
but it has been proven to be very reliable. For example, I never
experienced any fragmentation problems so far.

I'm very skeptical about any "new features". Except those features,
which improve debugging capabilities, because heap corruption is the
major cause of crashing applications.

If we think about more elegant solutions, we should check, whether it
makes still sense to allocate the thread stack from heap. For example,
the application may provide a pointer to the stack when creating the
thread. Furthermore, I recently did some research on shared stacks.

The long and short of it: IMHO there is more potential in reconsidering
the stack creation than in enhancing the heap management.



More information about the En-Nut-Discussion mailing list