This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit ca28baf2129ad97bb4c2a2111590ce975f9398ea Author: Marco Casaroli <[email protected]> AuthorDate: Tue Oct 20 20:45:01 2026 +0200 include/limits.h: Define _POSIX_THREAD_KEYS_MAX as the POSIX constant. _POSIX_THREAD_KEYS_MAX is the smallest PTHREAD_KEYS_MAX that POSIX allows, and it is always 128. <limits.h> defined it from CONFIG_TLS_NELEM (0 by default), so a program could not see that the configured number of keys is below the POSIX minimum. Define it as 128. PTHREAD_KEYS_MAX still follows CONFIG_TLS_NELEM; the Kconfig help now says that POSIX requires at least 128 keys and what each key costs. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/limits.h | 12 ++++-------- libs/libc/tls/Kconfig | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/limits.h b/include/limits.h index fd0922d5a1f..25189e98a2b 100644 --- a/include/limits.h +++ b/include/limits.h @@ -89,13 +89,7 @@ #define _POSIX_SYMLINK_MAX 255 #define _POSIX_SYMLOOP_MAX 8 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 -#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM >= 128 -# define _POSIX_THREAD_KEYS_MAX 128 -#elif defined(CONFIG_TLS_NELEM) -# define _POSIX_THREAD_KEYS_MAX CONFIG_TLS_NELEM -#else -# define _POSIX_THREAD_KEYS_MAX 0 -#endif +#define _POSIX_THREAD_KEYS_MAX 128 #define _POSIX_THREAD_THREADS_MAX 64 #define _POSIX_TIMER_MAX 32 #define _POSIX_TTY_NAME_MAX 9 @@ -274,7 +268,9 @@ #define SEM_NSEMS_MAX INT_MAX #define SEM_VALUE_MAX INT_MAX -/* Required for POSIX pthread management */ +/* Required for POSIX pthread management. POSIX requires at least + * _POSIX_THREAD_KEYS_MAX keys: set CONFIG_TLS_NELEM to 128 or more. + */ #ifndef PTHREAD_KEYS_MAX # define PTHREAD_KEYS_MAX CONFIG_TLS_NELEM diff --git a/libs/libc/tls/Kconfig b/libs/libc/tls/Kconfig index 7e5ce6a3cda..f91222dc2d9 100644 --- a/libs/libc/tls/Kconfig +++ b/libs/libc/tls/Kconfig @@ -56,6 +56,11 @@ config TLS_NELEM NOTE that the special value of CONFIG_TLS_NELEM disables these TLS interfaces. + This is also PTHREAD_KEYS_MAX, the number of pthread_key_create() + keys. POSIX requires at least 128 (_POSIX_THREAD_KEYS_MAX). Each + element costs one pointer in every thread and one destructor + pointer in every task group. + config TLS_TASK_NELEM int "Number of Task Local Storage elements" depends on !BUILD_KERNEL
