From b3b36f69a6444baac1cad1a67590e5fd7af70cf4 Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Wed, 26 May 2021 16:26:36 +0200 Subject: [PATCH] arm: cortex-m: shrink hidden option for null-pointer detection Shrink the name of the hidden cortex-m option for the null-pointer dereference detection feature. Signed-off-by: Ioannis Glaropoulos --- arch/arm/core/aarch32/cortex_m/Kconfig | 16 ++++++++-------- arch/arm/core/aarch32/cortex_m/debug.c | 8 ++++---- .../core/aarch32/cortex_m/vector_table_pad.ld | 6 +++--- arch/arm/core/aarch32/mpu/arm_mpu.c | 10 +++++----- tests/arch/arm/arm_interrupt/src/arm_interrupt.c | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/arch/arm/core/aarch32/cortex_m/Kconfig b/arch/arm/core/aarch32/cortex_m/Kconfig index 9cb3580080f..8a501a89f03 100644 --- a/arch/arm/core/aarch32/cortex_m/Kconfig +++ b/arch/arm/core/aarch32/cortex_m/Kconfig @@ -352,7 +352,7 @@ config NULL_POINTER_EXCEPTION_DETECTION_DWT depends on CPU_CORTEX_M_HAS_DWT depends on !TRUSTED_EXECUTION_NONSECURE select CORTEX_M_DWT - select CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION + select CORTEX_M_NULL_POINTER_EXCEPTION help Null pointer dereference detection implemented using the DWT unit functionality. @@ -369,7 +369,7 @@ config 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 + select CORTEX_M_NULL_POINTER_EXCEPTION help Null pointer dereference detection implemented using MPU functionality. @@ -383,7 +383,7 @@ config NULL_POINTER_EXCEPTION_DETECTION_MPU - In ARMv8-M, explicit null-pointer dereference detection with MPU requires, additionally, that the area: [0x0, - CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE) + CORTEX_M_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 @@ -392,7 +392,7 @@ config NULL_POINTER_EXCEPTION_DETECTION_MPU endchoice -config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION +config CORTEX_M_NULL_POINTER_EXCEPTION bool help Enable and use the null pointer exception option. @@ -400,15 +400,15 @@ config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION 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. + CORTEX_M_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 +if CORTEX_M_NULL_POINTER_EXCEPTION -config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE +config CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE hex "Size of paged unmapped to implement null pointer detection" default 0x400 help @@ -417,7 +417,7 @@ config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE 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 +endif # CORTEX_M_NULL_POINTER_EXCEPTION rsource "tz/Kconfig" diff --git a/arch/arm/core/aarch32/cortex_m/debug.c b/arch/arm/core/aarch32/cortex_m/debug.c index 245d834d666..69218fc5951 100644 --- a/arch/arm/core/aarch32/cortex_m/debug.c +++ b/arch/arm/core/aarch32/cortex_m/debug.c @@ -53,8 +53,8 @@ bool z_arm_debug_monitor_event_error_check(void) /* The area (0x0 - ) monitored by DWT needs to be a power of 2, * so we add a build assert that catches it. */ -BUILD_ASSERT(!(CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE & - (CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1)), +BUILD_ASSERT(!(CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE & + (CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1)), "the size of the partition must be power of 2"); static int z_arm_debug_enable_null_pointer_detection(const struct device *arg) @@ -79,7 +79,7 @@ static int z_arm_debug_enable_null_pointer_detection(const struct device *arg) /* Use comparators 0, 1, R/W access check */ DWT->COMP0 = 0; - DWT->COMP1 = CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1; + DWT->COMP1 = CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1; DWT->FUNCTION0 = ((0x4 << DWT_FUNCTION_MATCH_Pos) & DWT_FUNCTION_MATCH_Msk) @@ -112,7 +112,7 @@ static int z_arm_debug_enable_null_pointer_detection(const struct device *arg) /* Set mask according to the desired size */ DWT->MASK0 = 32 - __builtin_clzl( - CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1); + CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1); #endif return 0; diff --git a/arch/arm/core/aarch32/cortex_m/vector_table_pad.ld b/arch/arm/core/aarch32/cortex_m/vector_table_pad.ld index f82bda08a08..2e31d7b7656 100644 --- a/arch/arm/core/aarch32/cortex_m/vector_table_pad.ld +++ b/arch/arm/core/aarch32/cortex_m/vector_table_pad.ld @@ -16,6 +16,6 @@ * first stage vector table. */ -#if defined(CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION) -. = MAX(ABSOLUTE(.), CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE); -#endif /* CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION */ +#if defined(CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION) +. = MAX(ABSOLUTE(.), CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE); +#endif /* CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION */ diff --git a/arch/arm/core/aarch32/mpu/arm_mpu.c b/arch/arm/core/aarch32/mpu/arm_mpu.c index 4418552ab74..f8c9d589a29 100644 --- a/arch/arm/core/aarch32/mpu/arm_mpu.c +++ b/arch/arm/core/aarch32/mpu/arm_mpu.c @@ -355,12 +355,12 @@ int z_arm_mpu_init(void) */ #if defined(CONFIG_NULL_POINTER_EXCEPTION_DETECTION_MPU) #if (defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)) && \ - (CONFIG_FLASH_BASE_ADDRESS > CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE) + (CONFIG_FLASH_BASE_ADDRESS > CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE) #pragma message "Null-Pointer exception detection cannot be configured on un-mapped flash areas" #else const struct z_arm_mpu_partition unmap_region = { .start = 0x0, - .size = CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE, + .size = CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE, #if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) /* Overlapping region (with any permissions) * will result in fault generation @@ -377,16 +377,16 @@ int z_arm_mpu_init(void) * (size and alignment). */ _ARCH_MEM_PARTITION_ALIGN_CHECK(0x0, - CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE); + CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE); #if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) /* ARMv8-M requires that the area: - * 0x0 - CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE + * 0x0 - CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE * is not unmapped (belongs to a valid MPU region already). */ if ((arm_cmse_mpu_region_get(0x0) == -EINVAL) || (arm_cmse_mpu_region_get( - CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1) + CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION_PAGE_SIZE - 1) == -EINVAL)) { __ASSERT(0, "Null pointer detection page unmapped\n"); diff --git a/tests/arch/arm/arm_interrupt/src/arm_interrupt.c b/tests/arch/arm/arm_interrupt/src/arm_interrupt.c index 9516338c09a..12b62ff4ea0 100644 --- a/tests/arch/arm/arm_interrupt/src/arm_interrupt.c +++ b/tests/arch/arm/arm_interrupt/src/arm_interrupt.c @@ -481,7 +481,7 @@ void test_arm_user_interrupt(void) } #endif /* CONFIG_USERSPACE */ -#if defined(CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION) +#if defined(CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION) #pragma GCC push_options #pragma GCC optimize("O0") /* Avoid compiler optimizing null pointer de-referencing. */ @@ -511,7 +511,7 @@ void test_arm_null_pointer_exception(void) TC_PRINT("Skipped\n"); } -#endif /* CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION */ +#endif /* CONFIG_CORTEX_M_NULL_POINTER_EXCEPTION */ /** * @}