CONFIG_HW_STACK_PROTECTION implementation on nrf52840

What is the implementation of CONFIG_HW_STACK_PROTECTION on the nrf52840, using Zephyr (ncs 1.9.2)?

How does it differ from using  CONFIG_STACK_SENTINEL?

  • Hello,

    Letting you know I have been assigned to this case.

    I will be answering this on the next week.

    Kind Regards,

    Abhijith

  • Hello,

    There is no hw based stack checking in Cortex M4 based IC, so you should do it through MPU instead. In ARM v8-M platforms, CONFIG_HW_STACK_PROTECTION is enabled by default for stack checking, instead of MPU. Hence we need to change the default to MPU, for which we can manually enable another config, i.e. the CONFIG_MPU_STACK_GUARD.

    Kind Regards,

    Abhijith

  • So the CONFIG_MPU_STACK_GUARD configured should trigger an ASSERT immediately when a stack overflow occurs?

    how does it exactly use the MPU in order to do this?
    is there additional memory utilization in order to use this feature?

    I did not exactly understand what did you mean by: "In ARM v8-M platforms, CONFIG_HW_STACK_PROTECTION is enabled by default for stack checking, instead of MPU. Hence we need to change the default to MPU,". I see that in ncs for nrf52840 CONFIG_HW_STACK_PROTECTION is set to y and CONFIG_MPU_STACK_GUARD is not set.

  • Hello,

    Sorry for the delayed response and my last response was bit confusing as I included ArmV8 in that. In simple words CONFIG_HW_STACK_PROTECTION is a Hardware based platform feature to check the stack overflow. And CONFIG_HW_STACK_PROTECTION is enabled automatically if CONFIG_USERSPACE=n (disabled),AFAIK cortex M4 based IC lacks of hardware based stack overflow checking. But CONFIG_STACK_SENTINEL feature will enable stack overflow protection for those systems which lack hardware support.

    Kind Regards,

    Abhijith

  • Hi, and thanks for the answer but I still need some clarification.

    CONFIG_STACK_SENTINEL uses a software implementation and it can also be used, this is clear.

    But CONFIG_HW_STACK_PROTECTION is based on hardware implementation which is not supported in arm cortex m4, but it still raises an assertion when I test a case for stack overflow. It is also enabled for the nrf52840dk in:

    zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig

    So what is the implementation of CONFIG_HW_STACK_PROTECTION for the nrf52840?

Related