casaroli opened a new pull request, #20956: URL: https://github.com/apache/nuttx/pull/20956
## Summary With `CONFIG_TLS_ALIGNED` (the default of protected and kernel builds), a stack cannot be larger than its alignment, `2^CONFIG_TLS_LOG2_MAXSTACK` bytes. A larger request reached `up_create_stack()` or `up_use_stack()`. With assertions, a program stopped the system on `DEBUGASSERT(stack_size <= TLS_MAXSTACK)`; without assertions, the thread got a smaller stack than it asked for. POSIX lets `pthread_attr_setstacksize()` and `pthread_attr_setstack()` fail with `EINVAL` for a size above the system limit. - `pthread_attr_setstacksize()` and `pthread_attr_setstack()` return `EINVAL` for a size above the limit. - `pthread_create()` and `nxtask_init()` (`task_create()`, `posix_spawn()`, `exec()`) check the size too, so attributes that are set directly also fail with `EINVAL`. - Documentation: the errors of `pthread_attr_setstacksize()` and the `TLS_LOG2_MAXSTACK` help. ## Impact Only builds with `CONFIG_TLS_ALIGNED`. A request for a stack above the limit fails with `EINVAL` instead of a kernel assertion or a smaller stack. No in-tree configuration asks for a larger stack, except `CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE` of three rv-virt kernel configurations (`knsh_paging`, `knsh64_paging`, `knsh_romfs`), which only `task_spawn()` uses; a kernel build starts programs with `exec()`, which does not use it. No ABI change. ## Testing Test program `tlsstack.c` on `qemu-armv8a:knsh` (QEMU with HVF) with `CONFIG_TLS_LOG2_MAXSTACK=16` (64 KiB): `pthread_attr_setstacksize()` and `pthread_attr_setstack()` with 128 KiB, `pthread_create()` with 32 KiB, `posix_spawn()` with a 128 KiB stack, and `pthread_create()` with an attribute set directly to 128 KiB. - master: `pthread_attr_setstacksize()` and `pthread_attr_setstack()` with 128 KiB return 0, not `EINVAL`. `posix_spawn()` with a 128 KiB stack stops the kernel: an assertion at `arm64_createstack.c:105`, then at `mm_free.c:58`, then a data abort in the kernel (panic). - This PR: all five cases pass. ostest exits with status 0 on `qemu-armv8a:knsh` and `qemu-armv8a:nsh`. Build, each OK: `qemu-armv8a:nsh` (flat, arm64), `qemu-armv8a:knsh` (kernel, arm64), `lm3s6965-ek:qemu-protected` (protected, armv7-m), `qemu-armv7a:knsh` (kernel, armv7-a), `rv-virt:nsh64` (flat, rv64), `rv-virt:knsh64` (kernel, rv64). No new warnings. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
