arm: cortex_m: Kconfig symbols for null pointer detection feature

Introduce the required Kconfig symbol framework for the
Cortex-M-specific null pointer dereferencing detection
feature. There are two implementations (based on DWT and
MPU) so we introduce the corresponding choice symbols,
including a choice symbol to signify that the feature
is to be disabled.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2021-01-19 13:53:19 +01:00 committed by Carles Cufí
parent c320bb0522
commit b3cd5065eb

View file

@ -305,6 +305,95 @@ config TEST_EXTRA_STACKSIZE
endmenu
# Implement the null pointer detection using either the Data Watchpoint and
# Trace Unit and the Debug Monitor Exception, or the Memory Protection Unit.
choice CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION
bool "Enable and use null-pointer exception"
help
There are 2 implementations available, one based
on DWT and the other based on MPU. Use this choice
symbol to select one of the options. By default the
feature is disabled. In the test suite the feature
is enabled and the DWT-based solution is preferred.
config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION_NONE
bool "Do not enable null pointer exception detection"
help
Null pointer exception detection feature is not
enabled.
config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION_DWT
bool "Use DWT for null pointer exception detection"
depends on CPU_CORTEX_M_HAS_DWT
depends on !TRUSTED_EXECUTION_NONSECURE
select CORTEX_M_DWT
select CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION
help
Null pointer dereference detection implemented
using the DWT unit functionality.
Notes:
- Not enabled for Non-Secure FW images, where
null-pointer dereferencing is likely caught as
a SecureFault.
- Requires DWT functionality in the Cortex-M SoC
implementation (1 comparator for ARMv7-M, 2 comparators
for ARMv8-M).
config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION_MPU
bool "Use MPU for null pointer exception detection"
depends on !TRUSTED_EXECUTION_NONSECURE
depends on ARM_MPU
select CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION
help
Null pointer dereference detection implemented
using MPU functionality.
Notes:
- Mutually exclusive to the DWT-based solution
- Not enabled for Non-Secure FW images, where
null-pointer dereferencing is likely caught as
a SecureFault.
- Requires MPU functionality to be present and
enabled. The implementation consumes 1 MPU region.
- In ARMv8-M, explicit null-pointer dereference
detection with MPU requires, additionally, that
the area: [0x0,
CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE)
is not unmapped (covered by an MPU region already).
If it is unmapped null-pointer dereferencing may
still be idirectly detected (e.g. via a precise
Bus access fault), but this is not guaranteed. A
build-time message warns the user of this scenario.
endchoice
config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION
bool
help
Enable and use the null pointer exception option.
This is a debug feature in Cortex-M, allowing for
detecting null pointer dereferencing (raising a
CPU fault). Supporting the feature results in an
increased code footprint, determined by option
CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE.
Note: this hidden option is selected by the choice
symbols corresponding to the DWT-based or to the
MPU-based solution.
if CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION
config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE
hex "Size of paged unmapped to implement null pointer detection"
default 0x400
help
Size of the page reserved for detecting null pointer
dereferencing. Must be a power of two. A large value
offers enhanced detection performance to the cost of
wasting a large flash area that code may not use.
endif # CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION
rsource "mpu/Kconfig"
rsource "tz/Kconfig"