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 00df758e4734f1adaf2d2486938188be82cb1974 Author: Marco Casaroli <[email protected]> AuthorDate: Sun Oct 11 10:57:03 2026 +0200 sched: Add options for the argument limits of a new task. ARG_MAX was fixed at the POSIX minimum of 4096 bytes, and the argument count of a new task was fixed at 256 in two places. Programs that build command lines, such as xargs, size them from ARG_MAX, and some programs run commands with more than 256 arguments. Add TASK_ARG_MAX, which sets _POSIX_ARG_MAX and so ARG_MAX, and TASK_MAX_ARGS, which sets the argument count limit in binfmt and in nxtask_setup_stackargs(). The defaults are the old values. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- binfmt/binfmt_copyargv.c | 14 ++------------ include/limits.h | 2 +- sched/Kconfig | 22 ++++++++++++++++++++++ sched/task/task_setup.c | 18 ++++-------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/binfmt/binfmt_copyargv.c b/binfmt/binfmt_copyargv.c index bb91847f321..d59aa62e3bf 100644 --- a/binfmt/binfmt_copyargv.c +++ b/binfmt/binfmt_copyargv.c @@ -37,16 +37,6 @@ #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* This is an artificial limit to detect error conditions where an argv[] - * list is not properly terminated. - */ - -#define MAX_EXEC_ARGS 256 - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -95,11 +85,11 @@ int binfmt_copyargv(FAR char * const **copy, FAR char * const *argv) /* This is a sanity check to prevent running away with an * unterminated argv[] list. - * MAX_EXEC_ARGS should be sufficiently large that this + * CONFIG_TASK_MAX_ARGS should be sufficiently large that this * never happens in normal usage. */ - if (nargs > MAX_EXEC_ARGS) + if (nargs > CONFIG_TASK_MAX_ARGS) { berr("ERROR: Too many arguments: %zu\n", argsize); return -E2BIG; diff --git a/include/limits.h b/include/limits.h index a2da21497b2..974adc855fa 100644 --- a/include/limits.h +++ b/include/limits.h @@ -118,7 +118,7 @@ * */ -#define _POSIX_ARG_MAX 4096 +#define _POSIX_ARG_MAX CONFIG_TASK_ARG_MAX #define _POSIX_CHILD_MAX 6 #define _POSIX_LINK_MAX 8 #define _POSIX_MAX_CANON 255 diff --git a/sched/Kconfig b/sched/Kconfig index b20c4be8584..4fb39a2ea40 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -664,6 +664,28 @@ config TASK_NAME_SIZE will be TASK_NAME_SIZE + 1. The default of 31 then results in a align-able 32-byte allocation. +config TASK_ARG_MAX + int "Maximum size of the arguments and environment of a new task" + default 4096 + range 4096 2097152 + ---help--- + _POSIX_ARG_MAX and ARG_MAX in limits.h, and sysconf(_SC_ARG_MAX): the + length in bytes of the arguments plus the environment that + programs may pass to exec() or posix_spawn(). POSIX requires at + least 4096. Programs such as xargs size their command lines from + it. The length is not checked when a task starts, but the + arguments are copied to the stack of the new task, so its stack + must be large enough for them. + +config TASK_MAX_ARGS + int "Maximum number of arguments of a new task" + default 256 + range 16 65536 + ---help--- + The maximum number of arguments that a new task can get from + exec(), posix_spawn() or task_create(). A longer list fails with + E2BIG. + config SCHED_HAVE_PARENT bool "Support parent/child task relationships" default n diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 90689819b3d..b418f313481 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -45,16 +45,6 @@ #include "group/group.h" #include "task/task.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* This is an artificial limit to detect error conditions where an argv[] - * list is not properly terminated. - */ - -#define MAX_STACK_ARGS 256 - /**************************************************************************** * Private Data ****************************************************************************/ @@ -570,12 +560,12 @@ int nxtask_setup_stackargs(FAR struct tcb_s *tcb, { /* Increment the number of args. Here is a sanity check to * prevent running away with an unterminated argv[] list. - * MAX_STACK_ARGS should be sufficiently large that this never - * happens in normal usage. + * CONFIG_TASK_MAX_ARGS should be sufficiently large that this + * never happens in normal usage. */ - DEBUGASSERT(argc <= MAX_STACK_ARGS); - if (++argc > MAX_STACK_ARGS) + DEBUGASSERT(argc <= CONFIG_TASK_MAX_ARGS); + if (++argc > CONFIG_TASK_MAX_ARGS) { ret = -E2BIG; }
