[PATCH 00/13] More robust idle thread creation and TLS handling

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Sep 30 09:21:23 UTC 2022


This patch set started with an 8 byte overwrite of the interrupt stack while
porting an application from RTEMS 5 to 6.

The overwrite was due to a mismatch of the size returned by
_TLS_Get_allocation_size() and the actual usage of the area.  To fix this issue
it was necessary to add a new CPU port option:
CPU_THREAD_LOCAL_STORAGE_VARIANT.  I checked also the glibc implementations.
It seems that on some architectures (for example powerpc) the TCB is used for a
couple of more things.  For RTEMS, we don't really need the DTV and TCB.  It
could be useful for debuggers, however, then we probably need also some glibc
compatibility.

Add a new fatal error to catch a failing idle thread initialization:
INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED.  This can only happen if a thread
create extension fails for an idle thread.

Add a new CONFIGURE_IDLE_TASK_MINIMUM_STACK_SIZE application configuration
option to ensure that the idle task stacks have at least the configured minimum
size.  To check the default value for this option, the stack checker was
improved by adding the rtems_stack_checker_iterate() directive which can be
used to query the current information of all stacks in the system.

Sebastian Huber (13):
  sptls0*: Enable stack checker
  sptls01: Disable file system and Newlib reentrancy
  sptls02: Fix alignment check
  score: Require power of two CPU_STACK_MINIMUM_SIZE
  config: Changeable size for IDLE stack allocator
  config: Add rtems_malloc_task_stack_for_idle()
  sptls02: Increase alignment of a TLS object
  score: Add CPU_THREAD_LOCAL_STORAGE_VARIANT
  score: Simplify casts
  score: INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED
  stackchk: Avoid internal header file
  stackchk: Add rtems_stack_checker_iterate()
  config: Add CONFIGURE_IDLE_TASK_MINIMUM_STACK_SIZE

 bsps/powerpc/shared/cpu.c                     |   2 +-
 cpukit/doxygen/appl-config.h                  | 121 +++++++++-
 cpukit/include/rtems/confdefs/percpu.h        |  10 +
 cpukit/include/rtems/rtems/config.h           |  29 ++-
 cpukit/include/rtems/score/interr.h           |   3 +
 cpukit/include/rtems/score/stack.h            |  17 +-
 cpukit/include/rtems/score/threadidledata.h   |   8 +
 cpukit/include/rtems/score/tls.h              | 210 +++++++-----------
 cpukit/include/rtems/stackchk.h               |  89 +++++++-
 cpukit/libmisc/stackchk/check.c               | 158 +++++++------
 cpukit/sapi/src/interrtext.c                  |   5 +-
 cpukit/sapi/src/malloctaskstackforidle.c      |  59 +++++
 cpukit/score/cpu/aarch64/cpu.c                |   2 +-
 .../cpu/aarch64/include/rtems/score/cpu.h     |   2 +-
 .../cpu/aarch64/include/rtems/score/cpuimpl.h |   3 +
 cpukit/score/cpu/arm/__aeabi_read_tp.c        |   6 +-
 cpukit/score/cpu/arm/__tls_get_addr.c         |   6 +-
 .../score/cpu/arm/armv7m-context-initialize.c |   2 +-
 cpukit/score/cpu/arm/cpu.c                    |  17 +-
 .../score/cpu/arm/include/rtems/score/cpu.h   |  10 +-
 .../cpu/arm/include/rtems/score/cpuimpl.h     |   2 +
 .../cpu/bfin/include/rtems/score/cpuimpl.h    |   2 +
 cpukit/score/cpu/i386/cpu.c                   |   2 +-
 .../cpu/i386/include/rtems/score/cpuimpl.h    |   2 +
 .../cpu/lm32/include/rtems/score/cpuimpl.h    |   2 +
 cpukit/score/cpu/m68k/__m68k_read_tp.c        |   4 +-
 cpukit/score/cpu/m68k/cpu.c                   |   5 +-
 .../score/cpu/m68k/include/rtems/score/cpu.h  |   1 +
 .../cpu/m68k/include/rtems/score/cpuimpl.h    |   2 +
 cpukit/score/cpu/microblaze/__tls_get_addr.c  |  10 +-
 cpukit/score/cpu/microblaze/cpu.c             |   2 +-
 .../cpu/microblaze/include/rtems/score/cpu.h  |   1 +
 .../microblaze/include/rtems/score/cpuimpl.h  |   3 +
 .../cpu/mips/include/rtems/score/cpuimpl.h    |   2 +
 .../score/cpu/moxie/include/rtems/score/cpu.h |   2 +-
 .../cpu/moxie/include/rtems/score/cpuimpl.h   |   2 +
 .../cpu/nios2/include/rtems/score/cpuimpl.h   |   2 +
 .../cpu/nios2/nios2-context-initialize.c      |   5 +-
 .../cpu/no_cpu/include/rtems/score/cpu.h      |   3 +-
 .../cpu/no_cpu/include/rtems/score/cpuimpl.h  |  18 ++
 .../cpu/or1k/include/rtems/score/cpuimpl.h    |   2 +
 .../cpu/powerpc/include/rtems/score/cpuimpl.h |   2 +
 .../cpu/riscv/include/rtems/score/cpuimpl.h   |   2 +
 .../cpu/riscv/riscv-context-initialize.c      |   2 +-
 .../cpu/sh/include/rtems/score/cpuimpl.h      |   2 +
 cpukit/score/cpu/sparc/cpu.c                  |   2 +-
 .../cpu/sparc/include/rtems/score/cpuimpl.h   |   2 +
 cpukit/score/cpu/sparc64/cpu.c                |   2 +-
 .../cpu/sparc64/include/rtems/score/cpuimpl.h |   2 +
 .../cpu/v850/include/rtems/score/cpuimpl.h    |   2 +
 .../cpu/x86_64/include/rtems/score/cpuimpl.h  |   2 +
 cpukit/score/src/percpuasm.c                  |   7 +-
 cpukit/score/src/stackallocatorforidle.c      |  19 +-
 cpukit/score/src/threadcreateidle.c           |  40 +++-
 cpukit/score/src/threadinitialize.c           |   6 +-
 cpukit/score/src/tlsallocsize.c               |  44 ++--
 spec/build/cpukit/librtemscpu.yml             |   1 +
 spec/build/testsuites/sptests/grp.yml         |   2 +
 spec/build/testsuites/sptests/spfatal36.yml   |  19 ++
 .../fatal-idle-thread-create-failed.yml       |  20 ++
 .../fatal-idle-thread-stack-too-small.yml     |  20 ++
 spec/build/testsuites/validation/grp.yml      |   4 +
 testsuites/libtests/stackchk01/init.c         |  30 ++-
 testsuites/libtests/stackchk01/stackchk01.doc |  12 +-
 testsuites/samples/minimum/init.c             |   3 +
 testsuites/sptests/spfatal36/init.c           |  52 +++++
 testsuites/sptests/spfatal36/spfatal36.doc    |  11 +
 testsuites/sptests/spinternalerror02/init.c   |   2 +-
 testsuites/sptests/spstkalloc03/init.c        |   4 +-
 testsuites/sptests/spstkalloc04/init.c        |   4 +-
 testsuites/sptests/sptls01/init.c             |  39 +++-
 testsuites/sptests/sptls02/init.cc            |  20 +-
 testsuites/sptests/sptls03/init.c             |   4 +
 testsuites/sptests/sptls04/init.c             |   2 +
 testsuites/validation/tc-acfg-default.c       |  51 +++--
 .../tr-fatal-idle-thread-create-failed.c      | 158 +++++++++++++
 .../tr-fatal-idle-thread-create-failed.h      |  84 +++++++
 .../tr-fatal-idle-thread-stack-too-small.c    | 169 ++++++++++++++
 .../tr-fatal-idle-thread-stack-too-small.h    |  84 +++++++
 testsuites/validation/ts-config.h             |   2 +-
 testsuites/validation/ts-default.h            |   4 +-
 .../ts-fatal-idle-thread-create-failed.c      |  90 ++++++++
 .../ts-fatal-idle-thread-stack-too-small.c    |  99 +++++++++
 testsuites/validation/ts-fatal-sysinit.h      |   7 +
 84 files changed, 1625 insertions(+), 341 deletions(-)
 create mode 100644 cpukit/sapi/src/malloctaskstackforidle.c
 create mode 100644 spec/build/testsuites/sptests/spfatal36.yml
 create mode 100644 spec/build/testsuites/validation/fatal-idle-thread-create-failed.yml
 create mode 100644 spec/build/testsuites/validation/fatal-idle-thread-stack-too-small.yml
 create mode 100644 testsuites/sptests/spfatal36/init.c
 create mode 100644 testsuites/sptests/spfatal36/spfatal36.doc
 create mode 100644 testsuites/validation/tr-fatal-idle-thread-create-failed.c
 create mode 100644 testsuites/validation/tr-fatal-idle-thread-create-failed.h
 create mode 100644 testsuites/validation/tr-fatal-idle-thread-stack-too-small.c
 create mode 100644 testsuites/validation/tr-fatal-idle-thread-stack-too-small.h
 create mode 100644 testsuites/validation/ts-fatal-idle-thread-create-failed.c
 create mode 100644 testsuites/validation/ts-fatal-idle-thread-stack-too-small.c

-- 
2.35.3



More information about the devel mailing list