diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index dccd225b5a..9b8024dde1 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -135,6 +135,9 @@ static void exec_ctors(FAR void *arg) int exec_module(FAR const struct binary_s *binp) { FAR struct task_tcb_s *tcb; +#ifdef CONFIG_ARCH_ADDRENV + save_addrenv_t oldenv; +#endif FAR uint32_t *stack; pid_t pid; int err; @@ -150,7 +153,7 @@ int exec_module(FAR const struct binary_s *binp) } #endif - bdbg("Executing %s\n", binp->filename); + bvdbg("Executing %s\n", binp->filename); /* Allocate a TCB for the new task. */ @@ -161,6 +164,18 @@ int exec_module(FAR const struct binary_s *binp) goto errout; } + /* Instantiate the address environment containing the destructors */ + +#ifdef CONFIG_ARCH_ADDRENV + ret = up_addrenv_select(&binp->addrenv, &oldenv); + if (ret < 0) + { + bdbg("ERROR: up_addrenv_select() failed: %d\n", ret); + err = -ret; + goto errout_with_tcb; + } +#endif + /* Allocate the stack for the new task (always from the user heap) */ stack = (FAR uint32_t*)kumm_malloc(binp->stacksize); @@ -170,6 +185,17 @@ int exec_module(FAR const struct binary_s *binp) goto errout_with_tcb; } + /* Restore the address environment */ + +#ifdef CONFIG_ARCH_ADDRENV + ret = up_addrenv_restore(&oldenv); + if (ret < 0) + { + bdbg("ERROR: up_addrenv_select() failed: %d\n", ret); + err = -ret; + goto errout_with_stack; + } +#endif /* Initialize the task */ ret = task_init((FAR struct tcb_s *)tcb, binp->filename, binp->priority, diff --git a/binfmt/binfmt_unloadmodule.c b/binfmt/binfmt_unloadmodule.c index 067e727963..67b957b201 100644 --- a/binfmt/binfmt_unloadmodule.c +++ b/binfmt/binfmt_unloadmodule.c @@ -93,13 +93,13 @@ static inline int exec_dtors(FAR struct binary_s *binp) #endif int i; - /* Instantiate the address enviroment containing the destructors */ + /* Instantiate the address environment containing the destructors */ #ifdef CONFIG_ARCH_ADDRENV - ret = up_addrenv_select(binp->addrenv, &oldenv); + ret = up_addrenv_select(&binp->addrenv, &oldenv); if (ret < 0) { - bdbg("up_addrenv_select() failed: %d\n", ret); + bdbg("ERROR: up_addrenv_select() failed: %d\n", ret); return ret; } #endif @@ -114,10 +114,10 @@ static inline int exec_dtors(FAR struct binary_s *binp) dtor++; } - /* Restore the address enviroment */ + /* Restore the address environment */ #ifdef CONFIG_ARCH_ADDRENV - return up_addrenv_restore(oldenv); + return up_addrenv_restore(&oldenv); #else return OK; #endif