diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index c8cd9f7b753..d08419937e4 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -240,17 +240,6 @@ int exec_module(FAR struct binary_s *binp, umm_initialize(vheap, up_addrenv_heapsize(addrenv)); #endif -#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK) - /* Allocate the kernel stack */ - - ret = up_addrenv_kstackalloc(tcb); - if (ret < 0) - { - berr("ERROR: up_addrenv_kstackalloc() failed: %d\n", ret); - goto errout_with_addrenv; - } -#endif - /* Note that tcb->flags are not modified. 0=normal task */ /* tcb->flags |= TCB_FLAG_TTYPE_TASK; */ diff --git a/sched/task/task_init.c b/sched/task/task_init.c index 087eed81d3f..e26678704a3 100644 --- a/sched/task/task_init.c +++ b/sched/task/task_init.c @@ -168,6 +168,19 @@ int nxtask_init(FAR struct tcb_s *tcb, const char *name, int priority, goto errout_with_group; } +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK) + /* Allocate the kernel stack */ + + if (ttype != TCB_FLAG_TTYPE_KERNEL) + { + ret = up_addrenv_kstackalloc(tcb); + if (ret < 0) + { + goto errout_with_group; + } + } +#endif + /* Initialize the task control block */ ret = nxtask_setup_scheduler(tcb, priority, nxtask_start,