Keil Logo

Legacy function __user_initial_stackheap()

4.61 Legacy function __user_initial_stackheap()

If you have legacy source code you might see __user_initial_stackheap(), from rt_misc.h. This is an old function that is only supported for backwards compatibility with legacy source code.

The modern equivalent is __user_setup_stackheap().


extern __value_in_regs struct __initial_stackheap __user_initial_stackheap(unsigned R0, unsigned SP, unsigned R2, unsigned SL);


__user_initial_stackheap() returns the:
  • Heap base in r0.
  • Stack base in r1, that is, the highest address in the stack region.
  • Heap limit in r2.
If this function is reimplemented, it must:
  • Use no more than 88 bytes of stack.
  • Not corrupt registers other than r12 (ip).
  • Maintain eight-byte alignment of the heap.
The value of sp (r13) at the time __main() is called is passed as an argument in r1. The default implementation of __user_initial_stackheap(), using the semihosting SYS_HEAPINFO, is given by the library in module sys_stackheap.o.
To create a version of __user_initial_stackheap() that inherits sp from the execution environment and does not have a heap, set r0 and r2 to the value of r1 and return.
There is no limit to the size of the stack. However, if the heap region grows into the stack, malloc() attempts to detect the overlapping memory and fails the new memory allocation request.
The definition of __initial_stackheap in rt_misc.h is:
struct __initial_stackheap {
    unsigned heap_base; /* low-address end of initial heap */
    unsigned stack_base; /* high-address end of initial stack */
    unsigned heap_limit; /* high-address end of initial heap */
    unsigned stack_limit; /* unused */


The value of stack_base is 0x1 greater than the highest address used by the stack because a full-descending stack is used.
Non-ConfidentialPDF file icon PDF versionARM DUI0378H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.