Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This method of stack checking leverages the profiler hook mechanism supported by the compiler. Once enabled using CONFIG_ARMV7M_STACKCHECK, one register is set aside (R10 is the default) and the value of the base of stack is saved there (rBS). Then every function call will have a preamble and a postamble code added to it. The preamble ({{

...

__cyg_profile_func_enter

...

}}) checks the current stack pointer, minus a margin of 64 bytes (with an additional 136 bytes for the FP registers) against the value in the reserved register rBS. If the computed value lies below the value in rBS a hard fault is generated. The postamble code ({{

...

__cyg_profile_func_exit

...

}})  just returns to the caller.

...

This is done for a given architecture in {{nuttxin nuttx/arch/arm/src/

...

<arch>

...

/Make.defs}}:

Code Block
    ifeq ($(CONFIG_ARMV7M_STACKCHECK),y)
    CMN_CSRCS += up_stackcheck.c
    endif

The compiler flags are added in the nuttx/arch/arm/src/armv7-m/Toolchain.defs
TBD

Code Block
    # enable precise stack overflow tracking
    ifeq ($(CONFIG_ARMV7M_STACKCHECK),y)
    INSTRUMENTATIONDEFINES   = -finstrument-functions -ffixed-r10
    endif

...