This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 4b0676e583923dc9ee5d5f68df192ff632951481 Author: Marco Casaroli <[email protected]> AuthorDate: Mon Oct 12 17:05:25 2026 +0200 arch: Return -ENOMEM when up_create_stack() cannot allocate the stack. up_create_stack() returned ERROR (-1) on every architecture when it could not allocate the stack. nxtask_init() and nxtask_setup_fork() pass the value on as a negated errno, so exec(), task_create() and fork() failed with EPERM ("Operation not permitted"). pthread_create() already returns ENOMEM in this case. Return -ENOMEM from up_create_stack() on all architectures, and describe the return value in include/nuttx/arch.h. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- arch/arm/src/common/arm_createstack.c | 3 ++- arch/arm64/src/common/arm64_createstack.c | 3 ++- arch/avr/src/avr/avr_createstack.c | 3 ++- arch/avr/src/avr32/avr_createstack.c | 3 ++- arch/ceva/src/common/ceva_createstack.c | 3 ++- arch/hc/src/common/hc_createstack.c | 3 ++- arch/mips/src/common/mips_createstack.c | 3 ++- arch/misoc/src/lm32/lm32_createstack.c | 3 ++- arch/misoc/src/minerva/minerva_createstack.c | 3 ++- arch/or1k/src/common/or1k_createstack.c | 3 ++- arch/renesas/src/common/renesas_createstack.c | 3 ++- arch/risc-v/src/common/riscv_createstack.c | 3 ++- arch/sim/src/sim/sim_createstack.c | 3 ++- arch/sparc/src/common/sparc_createstack.c | 3 ++- arch/tricore/src/common/tricore_createstack.c | 3 ++- arch/x86/src/i486/i486_createstack.c | 3 ++- arch/x86_64/src/intel64/intel64_createstack.c | 3 ++- arch/xtensa/src/common/xtensa_createstack.c | 3 ++- arch/z16/src/common/z16_createstack.c | 3 ++- arch/z80/src/common/z80_createstack.c | 3 ++- include/nuttx/arch.h | 3 +++ 21 files changed, 43 insertions(+), 20 deletions(-) diff --git a/arch/arm/src/common/arm_createstack.c b/arch/arm/src/common/arm_createstack.c index b94e8005ab8..33a336c19fc 100644 --- a/arch/arm/src/common/arm_createstack.c +++ b/arch/arm/src/common/arm_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <string.h> #include <sched.h> #include <assert.h> @@ -198,5 +199,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/arm64/src/common/arm64_createstack.c b/arch/arm64/src/common/arm64_createstack.c index 617e116f38a..9a4f7426179 100644 --- a/arch/arm64/src/common/arm64_createstack.c +++ b/arch/arm64/src/common/arm64_createstack.c @@ -27,6 +27,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <nuttx/debug.h> @@ -204,5 +205,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/avr/src/avr/avr_createstack.c b/arch/avr/src/avr/avr_createstack.c index 6cb98380210..a6d3d0c0399 100644 --- a/arch/avr/src/avr/avr_createstack.c +++ b/arch/avr/src/avr/avr_createstack.c @@ -29,6 +29,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <sched.h> @@ -189,5 +190,5 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/avr/src/avr32/avr_createstack.c b/arch/avr/src/avr32/avr_createstack.c index 73971673464..da6cbab668c 100644 --- a/arch/avr/src/avr32/avr_createstack.c +++ b/arch/avr/src/avr32/avr_createstack.c @@ -29,6 +29,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <stdlib.h> #include <sched.h> #include <assert.h> @@ -210,5 +211,5 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/ceva/src/common/ceva_createstack.c b/arch/ceva/src/common/ceva_createstack.c index 19272a8d36e..58211f99fa3 100644 --- a/arch/ceva/src/common/ceva_createstack.c +++ b/arch/ceva/src/common/ceva_createstack.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> +#include <errno.h> #include <string.h> #include <sched.h> #include <assert.h> @@ -218,7 +219,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } /**************************************************************************** diff --git a/arch/hc/src/common/hc_createstack.c b/arch/hc/src/common/hc_createstack.c index d23eeef7b09..06f6dcdd748 100644 --- a/arch/hc/src/common/hc_createstack.c +++ b/arch/hc/src/common/hc_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -209,5 +210,5 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/mips/src/common/mips_createstack.c b/arch/mips/src/common/mips_createstack.c index 20132780700..8adbfe90078 100644 --- a/arch/mips/src/common/mips_createstack.c +++ b/arch/mips/src/common/mips_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -208,5 +209,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/misoc/src/lm32/lm32_createstack.c b/arch/misoc/src/lm32/lm32_createstack.c index 7d26525b615..3af8c22d72b 100644 --- a/arch/misoc/src/lm32/lm32_createstack.c +++ b/arch/misoc/src/lm32/lm32_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -201,5 +202,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/misoc/src/minerva/minerva_createstack.c b/arch/misoc/src/minerva/minerva_createstack.c index c1d35d7f258..8f863a7557a 100644 --- a/arch/misoc/src/minerva/minerva_createstack.c +++ b/arch/misoc/src/minerva/minerva_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -202,5 +203,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/or1k/src/common/or1k_createstack.c b/arch/or1k/src/common/or1k_createstack.c index 3958f68a553..03bae1e59e3 100644 --- a/arch/or1k/src/common/or1k_createstack.c +++ b/arch/or1k/src/common/or1k_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <string.h> #include <sched.h> #include <assert.h> @@ -191,7 +192,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } /**************************************************************************** diff --git a/arch/renesas/src/common/renesas_createstack.c b/arch/renesas/src/common/renesas_createstack.c index 9afc006f65c..9f3d37a857a 100644 --- a/arch/renesas/src/common/renesas_createstack.c +++ b/arch/renesas/src/common/renesas_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -210,5 +211,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/risc-v/src/common/riscv_createstack.c b/arch/risc-v/src/common/riscv_createstack.c index 9d8c8487089..5b3b4d56091 100644 --- a/arch/risc-v/src/common/riscv_createstack.c +++ b/arch/risc-v/src/common/riscv_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -201,7 +202,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } /**************************************************************************** diff --git a/arch/sim/src/sim/sim_createstack.c b/arch/sim/src/sim/sim_createstack.c index 98058abd9f2..e9cca5b91e3 100644 --- a/arch/sim/src/sim/sim_createstack.c +++ b/arch/sim/src/sim/sim_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <string.h> #include <assert.h> @@ -152,7 +153,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } /**************************************************************************** diff --git a/arch/sparc/src/common/sparc_createstack.c b/arch/sparc/src/common/sparc_createstack.c index fd69fb77bbc..01ad5a9283b 100644 --- a/arch/sparc/src/common/sparc_createstack.c +++ b/arch/sparc/src/common/sparc_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <nuttx/debug.h> @@ -176,5 +177,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/tricore/src/common/tricore_createstack.c b/arch/tricore/src/common/tricore_createstack.c index ad7a6a93a70..50796090426 100644 --- a/arch/tricore/src/common/tricore_createstack.c +++ b/arch/tricore/src/common/tricore_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -200,7 +201,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } /**************************************************************************** diff --git a/arch/x86/src/i486/i486_createstack.c b/arch/x86/src/i486/i486_createstack.c index ac71128c86e..41824b96590 100644 --- a/arch/x86/src/i486/i486_createstack.c +++ b/arch/x86/src/i486/i486_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <stdlib.h> #include <sched.h> #include <assert.h> @@ -209,5 +210,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/x86_64/src/intel64/intel64_createstack.c b/arch/x86_64/src/intel64/intel64_createstack.c index edfb47aa0e6..3b2dde5c186 100644 --- a/arch/x86_64/src/intel64/intel64_createstack.c +++ b/arch/x86_64/src/intel64/intel64_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <stdlib.h> #include <sched.h> #include <assert.h> @@ -212,5 +213,5 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c index 983172f4317..c0fc9670bb7 100644 --- a/arch/xtensa/src/common/xtensa_createstack.c +++ b/arch/xtensa/src/common/xtensa_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -207,7 +208,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } /**************************************************************************** diff --git a/arch/z16/src/common/z16_createstack.c b/arch/z16/src/common/z16_createstack.c index 074c993c3b1..75a86492806 100644 --- a/arch/z16/src/common/z16_createstack.c +++ b/arch/z16/src/common/z16_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -204,5 +205,5 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/arch/z80/src/common/z80_createstack.c b/arch/z80/src/common/z80_createstack.c index 4e73ae5f42b..1faadb4eaca 100644 --- a/arch/z80/src/common/z80_createstack.c +++ b/arch/z80/src/common/z80_createstack.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <stdint.h> +#include <errno.h> #include <sched.h> #include <assert.h> #include <nuttx/debug.h> @@ -208,5 +209,5 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return OK; } - return ERROR; + return -ENOMEM; } diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 2836a57cd46..5480a0a3a25 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -388,6 +388,9 @@ void up_initial_state(FAR struct tcb_s *tcb); * Stacks for user tasks and threads must come from memory that is * accessible to user code. * + * Returned Value: + * Zero (OK) on success; -ENOMEM if the stack cannot be allocated. + * ****************************************************************************/ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype);
