From 60b7d076c27f4e3450d9beb7131adf787411f529 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Sep 2014 12:40:09 -0600 Subject: Fix an ordering problem in integration of kernel stack logic --- nuttx/binfmt/binfmt_execmodule.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'nuttx/binfmt') diff --git a/nuttx/binfmt/binfmt_execmodule.c b/nuttx/binfmt/binfmt_execmodule.c index 3756fbaf6..dae892571 100644 --- a/nuttx/binfmt/binfmt_execmodule.c +++ b/nuttx/binfmt/binfmt_execmodule.c @@ -165,8 +165,7 @@ int exec_module(FAR const struct binary_s *binp) goto errout; } -#ifdef CONFIG_ARCH_ADDRENV -#ifdef CONFIG_BUILD_KERNEL +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) /* Instantiate the address environment containing the user heap */ ret = up_addrenv_select(&binp->addrenv, &oldenv); @@ -183,19 +182,6 @@ int exec_module(FAR const struct binary_s *binp) up_addrenv_heapsize(&binp->addrenv)); #endif -#ifdef CONFIG_ARCH_KERNEL_STACK - /* Allocate the kernel stack */ - - ret = up_addrenv_kstackalloc(&tcb->cmn); - if (ret < 0) - { - bdbg("ERROR: up_addrenv_select() failed: %d\n", ret); - err = -ret; - goto errout_with_addrenv; - } -#endif -#endif - /* Allocate the stack for the new task. * * REVISIT: This allocation is currently always from the user heap. That @@ -223,6 +209,18 @@ int exec_module(FAR const struct binary_s *binp) /* Note that tcb->flags are not modified. 0=normal task */ /* tcb->flags |= TCB_FLAG_TTYPE_TASK; */ +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) + /* Allocate the kernel stack */ + + ret = up_addrenv_kstackalloc(&tcb->cmn); + if (ret < 0) + { + bdbg("ERROR: up_addrenv_select() failed: %d\n", ret); + err = -ret; + goto errout_with_addrenv; + } +#endif + #ifdef CONFIG_PIC /* Add the D-Space address as the PIC base address. By convention, this * must be the first allocated address space. -- cgit v1.2.3