d3ffeb40a7
In order to turn longjmp context-switch safe, it's necessary to disable interrupts before modifying windowbase and windowstart. Otherwise, after a context switch, windowstart and windowbase would be different, leading to a wrongly set windowstart bit due to longjmp writing it based on the windowbase before the context switch. This corrupts the registers at the next window overflow reaching that wrongly set bit. *Background:* This PR is related to an issue first observed on ESP-IDF https://github.com/espressif/esp-idf/issues/5229 and it was, then, checked on NuttX using a test application. *The test application:* To check if the problem affects ESP32, ESP32-S2 and ESP32-S3 on NuttX, it was created an application based on: https://en.cppreference.com/w/c/program/longjmp The application creates 16 tasks (`#define NUMBER_OF_TASKS 16`) that implements the following daemon: ``` static int setjmp_longjmp_daemon(int argc, char *argv[]) { for (int i = 0; i < NUMBER_OF_TASKS * 2; i++) { jmp_buf env; volatile int count = 0; if (setjmp(env) != UINT16_MAX) { foo(&env, ++count); } } sem_post(&g_sem); return EXIT_SUCCESS; } ``` The main function also initializes a semaphore to avoid application exiting before tasks return successfully: ``` sem_init(&g_sem, 0, -NUMBER_OF_TASKS); ``` Finally, the round-robin interval was lowered to 1ms to raise the chances of the longjmp being interrupted by a context switch (`CONFIG_RR_INTERVAL=1). This setup was able to reproduce the problem prior to this patch being applied.
60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
#
|
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
|
#
|
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
|
# modifications.
|
|
#
|
|
# CONFIG_ARCH_LEDS is not set
|
|
# CONFIG_NSH_ARGCAT is not set
|
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
|
# CONFIG_NSH_CMDPARMS is not set
|
|
CONFIG_ARCH="xtensa"
|
|
CONFIG_ARCH_BOARD="esp32-devkitc"
|
|
CONFIG_ARCH_BOARD_COMMON=y
|
|
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
|
|
CONFIG_ARCH_CHIP="esp32"
|
|
CONFIG_ARCH_CHIP_ESP32=y
|
|
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
|
CONFIG_ARCH_INTERRUPTSTACK=2048
|
|
CONFIG_ARCH_SETJMP_H=y
|
|
CONFIG_ARCH_STACKDUMP=y
|
|
CONFIG_ARCH_XTENSA=y
|
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
|
CONFIG_BUILTIN=y
|
|
CONFIG_DEBUG_FULLOPT=y
|
|
CONFIG_DEBUG_SYMBOLS=y
|
|
CONFIG_ESP32_UART0=y
|
|
CONFIG_EXAMPLES_HELLO=y
|
|
CONFIG_FS_PROCFS=y
|
|
CONFIG_HAVE_CXX=y
|
|
CONFIG_HAVE_CXXINITIALIZE=y
|
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
|
CONFIG_INIT_STACKSIZE=3072
|
|
CONFIG_INTELHEX_BINARY=y
|
|
CONFIG_MM_REGIONS=4
|
|
CONFIG_NSH_ARCHINIT=y
|
|
CONFIG_NSH_BUILTIN_APPS=y
|
|
CONFIG_NSH_FILEIOSIZE=512
|
|
CONFIG_NSH_LINELEN=64
|
|
CONFIG_NSH_READLINE=y
|
|
CONFIG_PREALLOC_TIMERS=4
|
|
CONFIG_RAM_SIZE=114688
|
|
CONFIG_RAM_START=0x20000000
|
|
CONFIG_READLINE_CMD_HISTORY=y
|
|
CONFIG_RR_INTERVAL=200
|
|
CONFIG_SMP=y
|
|
CONFIG_SMP_NCPUS=2
|
|
CONFIG_SPI=y
|
|
CONFIG_STACK_COLORATION=y
|
|
CONFIG_START_DAY=6
|
|
CONFIG_START_MONTH=12
|
|
CONFIG_START_YEAR=2011
|
|
CONFIG_SYSTEM_NSH=y
|
|
CONFIG_SYSTEM_SYSTEM=y
|
|
CONFIG_SYSTEM_TASKSET=y
|
|
CONFIG_TESTING_OSTEST=y
|
|
CONFIG_TESTING_SMP=y
|
|
CONFIG_UART0_SERIAL_CONSOLE=y
|