From d507a862853043466bfefdf6a33847584985887f Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 3 Nov 2023 08:55:44 +0100 Subject: [PATCH] feat(freertos): Exposed Kconfig option for configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES This commit exposes the FreeRTOS List integrity check option configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES via menuconfig. --- .../test_apps/main/test_event_target.c | 2 +- .../esp_system_unity_tests/main/test_app_main.c | 2 +- .../portable/riscv/include/freertos/portmacro.h | 4 ++++ .../portable/riscv/include/freertos/portmacro.h | 4 ++++ components/freertos/Kconfig | 7 +++++++ .../config/include/freertos/FreeRTOSConfig.h | 3 +++ .../freertos/sdkconfig.ci.freertos_options | 1 + components/newlib/platform_include/sys/lock.h | 17 +++++++++++------ .../wpa_supplicant/test_apps/main/test_crypto.c | 2 +- .../wpa_supplicant/test_apps/main/test_dpp.c | 2 +- .../wpa_supplicant/test_apps/main/test_eloop.c | 2 +- .../test_apps/main/test_fast_pbkdf2.c | 2 +- .../wpa_supplicant/test_apps/main/test_sae.c | 2 +- tools/test_apps/configs/sdkconfig.debug_helpers | 1 + 14 files changed, 38 insertions(+), 13 deletions(-) diff --git a/components/esp_event/test_apps/main/test_event_target.c b/components/esp_event/test_apps/main/test_event_target.c index f949319b7f..bd9264119f 100644 --- a/components/esp_event/test_apps/main/test_event_target.c +++ b/components/esp_event/test_apps/main/test_event_target.c @@ -720,7 +720,7 @@ bool test_event_on_timer_alarm(gptimer_handle_t timer, const gptimer_alarm_event TEST_CASE("can post events from interrupt handler", "[event][intr]") { /* Lazy allocated resources in gptimer/intr_alloc */ - unity_utils_set_leak_level(150); + unity_utils_set_leak_level(160); TEST_ESP_OK(esp_event_loop_create_default()); diff --git a/components/esp_system/test_apps/esp_system_unity_tests/main/test_app_main.c b/components/esp_system/test_apps/esp_system_unity_tests/main/test_app_main.c index d894e9325e..fdaa6101fc 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/main/test_app_main.c +++ b/components/esp_system/test_apps/esp_system_unity_tests/main/test_app_main.c @@ -11,7 +11,7 @@ #include "freertos/task.h" // Some resources are lazy allocated, the threshold is left for that case -#define TEST_MEMORY_LEAK_THRESHOLD (-800) +#define TEST_MEMORY_LEAK_THRESHOLD (-900) static size_t before_free_8bit; static size_t before_free_32bit; diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h index e23af815dc..d074fa1c03 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h @@ -9,7 +9,11 @@ #include "sdkconfig.h" /* Macros used instead ofsetoff() for better performance of interrupt handler */ +#if CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES +#define PORT_OFFSET_PX_STACK 0x40 +#else #define PORT_OFFSET_PX_STACK 0x30 +#endif /* #if CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES */ #define PORT_OFFSET_PX_END_OF_STACK (PORT_OFFSET_PX_STACK + \ /* void * pxDummy6 */ 4 + \ /* BaseType_t xDummy23[ 2 ] */ 8 + \ diff --git a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h index 3691fa12fa..bdf96103b4 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h @@ -37,7 +37,11 @@ #include "freertos/FreeRTOSConfig.h" /* Macros used instead ofsetoff() for better performance of interrupt handler */ +#if CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES +#define PORT_OFFSET_PX_STACK 0x40 +#else #define PORT_OFFSET_PX_STACK 0x30 +#endif /* #if CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES */ #define PORT_OFFSET_PX_END_OF_STACK (PORT_OFFSET_PX_STACK + \ /* void * pxDummy6 */ 4 + \ /* uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ] */ CONFIG_FREERTOS_MAX_TASK_NAME_LEN + \ diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index d8ca79b487..b41daca79a 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -224,6 +224,13 @@ menu "FreeRTOS" ``vTaskList()`` and ``vTaskGetRunTimeStats()`` functions in the build (see configUSE_STATS_FORMATTING_FUNCTIONS documentation for more details). + config FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES + bool "configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES" + #TODO: Enable by default for debug builds (IDF-8517) + default n + help + Enable list integrity checker (see configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES documentation for more details). + config FREERTOS_VTASKLIST_INCLUDE_COREID # Core affinity is supported in stats for Amazon FreeRTOS SMP by default bool "Enable display of xCoreID in vTaskList" diff --git a/components/freertos/config/include/freertos/FreeRTOSConfig.h b/components/freertos/config/include/freertos/FreeRTOSConfig.h index c8e7922615..3273c71018 100644 --- a/components/freertos/config/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/config/include/freertos/FreeRTOSConfig.h @@ -247,6 +247,9 @@ #endif /* CONFIG_FREERTOS_SMP */ #endif /* def __ASSEMBLER__ */ +/* -------------- List Data Integrity Checks --------------- */ +#define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES + /* ----------------------------------------------- Amazon SMP FreeRTOS ------------------------------------------------- * - All Amazon SMP FreeRTOS specific configurations * ------------------------------------------------------------------------------------------------------------------ */ diff --git a/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options b/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options index 38ae8ab7df..89eb6d8d74 100644 --- a/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options +++ b/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options @@ -17,3 +17,4 @@ CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U64=y CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y CONFIG_FREERTOS_FPU_IN_ISR=y CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 +CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES=y diff --git a/components/newlib/platform_include/sys/lock.h b/components/newlib/platform_include/sys/lock.h index 7299c40114..a7fa41ed85 100644 --- a/components/newlib/platform_include/sys/lock.h +++ b/components/newlib/platform_include/sys/lock.h @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include_next +#include "sdkconfig.h" #ifdef _RETARGETABLE_LOCKING @@ -13,15 +14,19 @@ * The size here should be sufficient for a FreeRTOS mutex. * This is checked by a static assertion in locks.c * - * Note 1: this might need to be made dependent on whether FreeRTOS + * Note: this might need to be made dependent on whether FreeRTOS * is included in the build. - * - * Note 2: the size is made sufficient for the case when - * configUSE_TRACE_FACILITY is enabled. If it is disabled, - * this definition wastes 8 bytes. */ struct __lock { +#if (CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES && CONFIG_FREERTOS_USE_TRACE_FACILITY) + int reserved[29]; +#elif (CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES && !CONFIG_FREERTOS_USE_TRACE_FACILITY) + int reserved[27]; +#elif (!CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES && CONFIG_FREERTOS_USE_TRACE_FACILITY) int reserved[23]; +#else + int reserved[21]; +#endif /* #if (CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES && CONFIG_FREERTOS_USE_TRACE_FACILITY) */ }; /* Compatibility definitions for the legacy ESP-specific locking implementation. diff --git a/components/wpa_supplicant/test_apps/main/test_crypto.c b/components/wpa_supplicant/test_apps/main/test_crypto.c index e7b5a2159b..42fefce803 100644 --- a/components/wpa_supplicant/test_apps/main/test_crypto.c +++ b/components/wpa_supplicant/test_apps/main/test_crypto.c @@ -22,7 +22,7 @@ typedef struct crypto_bignum crypto_bignum; TEST_CASE("Test crypto lib bignum apis", "[wpa_crypto]") { - set_leak_threshold(250); + set_leak_threshold(300); { uint8_t buf[32], buf2[32]; diff --git a/components/wpa_supplicant/test_apps/main/test_dpp.c b/components/wpa_supplicant/test_apps/main/test_dpp.c index b75cbbd915..69b5176fe8 100644 --- a/components/wpa_supplicant/test_apps/main/test_dpp.c +++ b/components/wpa_supplicant/test_apps/main/test_dpp.c @@ -34,7 +34,7 @@ extern size_t dpp_nonce_override_len; TEST_CASE("Test vectors DPP responder p256", "[wpa_dpp]") { - set_leak_threshold(120); + set_leak_threshold(130); /* Global variables */ char command[1200] = {0}; const u8 *frame; diff --git a/components/wpa_supplicant/test_apps/main/test_eloop.c b/components/wpa_supplicant/test_apps/main/test_eloop.c index 9553c50bb6..ea2b115ef4 100644 --- a/components/wpa_supplicant/test_apps/main/test_eloop.c +++ b/components/wpa_supplicant/test_apps/main/test_eloop.c @@ -55,7 +55,7 @@ extern const wifi_osi_funcs_t *wifi_funcs; /* Check if eloop runs its timers correctly & in correct order */ TEST_CASE("Test eloop timers run", "[eloop]") { - set_leak_threshold(800); + set_leak_threshold(1000); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); cfg.nvs_enable = false; ESP_ERROR_CHECK(esp_wifi_init(&cfg)); diff --git a/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c b/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c index 6e94c3e403..5e74a7b76d 100644 --- a/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c +++ b/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c @@ -15,7 +15,7 @@ TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]") { - set_leak_threshold(120); + set_leak_threshold(130); uint8_t PMK[PMK_LEN]; uint8_t ssid_len; diff --git a/components/wpa_supplicant/test_apps/main/test_sae.c b/components/wpa_supplicant/test_apps/main/test_sae.c index d2cef1572e..67b6d7fe9f 100644 --- a/components/wpa_supplicant/test_apps/main/test_sae.c +++ b/components/wpa_supplicant/test_apps/main/test_sae.c @@ -48,7 +48,7 @@ void wpabuf_free2(struct wpabuf *buf) TEST_CASE("Test SAE functionality with ECC group", "[wpa3_sae]") { - set_leak_threshold(120); + set_leak_threshold(400); ESP_LOGI("SAE Test", "### Beginning SAE init and deinit ###"); { /* Test init and deinit*/ diff --git a/tools/test_apps/configs/sdkconfig.debug_helpers b/tools/test_apps/configs/sdkconfig.debug_helpers index 4bd42af97d..9bb49614b9 100644 --- a/tools/test_apps/configs/sdkconfig.debug_helpers +++ b/tools/test_apps/configs/sdkconfig.debug_helpers @@ -4,3 +4,4 @@ CONFIG_COMPILER_WARN_WRITE_STRINGS=y CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y CONFIG_COMPILER_STACK_CHECK=y +CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES=y