Add logic to initialize the per-process user heap when each user process is started

This commit is contained in:
Gregory Nutt
2014-09-10 15:55:36 -06:00
parent 0ee23991fd
commit 205c23b9d6
15 changed files with 326 additions and 132 deletions
+25 -15
View File
@@ -48,6 +48,7 @@
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mm.h>
#include <nuttx/binfmt/binfmt.h>
#include "sched/sched.h"
@@ -164,9 +165,9 @@ int exec_module(FAR const struct binary_s *binp)
goto errout;
}
/* Instantiate the address environment containing the destructors */
#ifdef CONFIG_ARCH_ADDRENV
/* Instantiate the address environment containing the user heap */
ret = up_addrenv_select(&binp->addrenv, &oldenv);
if (ret < 0)
{
@@ -174,9 +175,18 @@ int exec_module(FAR const struct binary_s *binp)
err = -ret;
goto errout_with_tcb;
}
/* Initialize the user heap */
umm_initialize((FAR void *)CONFIG_ARCH_HEAP_VBASE,
up_addrenv_heapsize(&binp->addrenv));
#endif
/* Allocate the stack for the new task (always from the user heap) */
/* Allocate the stack for the new task.
*
* REVISIT: This allocation is currently always from the user heap. That
* will need to change if/when we want to support dynamic stack allocation.
*/
stack = (FAR uint32_t*)kumm_malloc(binp->stacksize);
if (!stack)
@@ -185,18 +195,6 @@ int exec_module(FAR const struct binary_s *binp)
goto errout_with_addrenv;
}
/* 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,
@@ -262,6 +260,18 @@ int exec_module(FAR const struct binary_s *binp)
goto errout_with_stack;
}
#ifdef CONFIG_ARCH_ADDRENV
/* Restore the address environment of the caller */
ret = up_addrenv_restore(&oldenv);
if (ret < 0)
{
bdbg("ERROR: up_addrenv_select() failed: %d\n", ret);
err = -ret;
goto errout_with_stack;
}
#endif
return (int)pid;
errout_with_stack: