mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
sched/addrenv: Remove up_addrenv_restore
The function is not relevant any longer, remove it. Also remove save_addrenv_t, the parameter taken by up_addrenv_restore. Implement addrenv_select() / addrenv_restore() to handle the temporary instantiation of address environments, e.g. when a process is being created.
This commit is contained in:
+11
-10
@@ -31,6 +31,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/addrenv.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/sched.h>
|
||||
@@ -110,13 +111,13 @@ static void exec_ctors(FAR void *arg)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec_module(FAR const struct binary_s *binp,
|
||||
int exec_module(FAR struct binary_s *binp,
|
||||
FAR const char *filename, FAR char * const *argv,
|
||||
FAR char * const *envp)
|
||||
{
|
||||
FAR struct task_tcb_s *tcb;
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
save_addrenv_t oldenv;
|
||||
FAR struct arch_addrenv_s *addrenv = &binp->addrenv.addrenv;
|
||||
FAR void *vheap;
|
||||
#endif
|
||||
FAR void *stackaddr = NULL;
|
||||
@@ -164,14 +165,14 @@ int exec_module(FAR const struct binary_s *binp,
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
/* Instantiate the address environment containing the user heap */
|
||||
|
||||
ret = up_addrenv_select(&binp->addrenv, &oldenv);
|
||||
ret = addrenv_select(&binp->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select() failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_select() failed: %d\n", ret);
|
||||
goto errout_with_envp;
|
||||
}
|
||||
|
||||
ret = up_addrenv_vheap(&binp->addrenv, &vheap);
|
||||
ret = up_addrenv_vheap(addrenv, &vheap);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_vheap() failed: %d\n", ret);
|
||||
@@ -179,8 +180,8 @@ int exec_module(FAR const struct binary_s *binp,
|
||||
}
|
||||
|
||||
binfo("Initialize the user heap (heapsize=%zu)\n",
|
||||
up_addrenv_heapsize(&binp->addrenv));
|
||||
umm_initialize(vheap, up_addrenv_heapsize(&binp->addrenv));
|
||||
up_addrenv_heapsize(addrenv));
|
||||
umm_initialize(vheap, up_addrenv_heapsize(addrenv));
|
||||
#endif
|
||||
|
||||
/* Note that tcb->flags are not modified. 0=normal task */
|
||||
@@ -272,10 +273,10 @@ int exec_module(FAR const struct binary_s *binp,
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
/* Restore the address environment of the caller */
|
||||
|
||||
ret = up_addrenv_restore(&oldenv);
|
||||
ret = addrenv_restore();
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_restore() failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_restore() failed: %d\n", ret);
|
||||
goto errout_with_tcbinit;
|
||||
}
|
||||
#endif
|
||||
@@ -291,7 +292,7 @@ errout_with_tcbinit:
|
||||
|
||||
errout_with_addrenv:
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
up_addrenv_restore(&oldenv);
|
||||
addrenv_restore();
|
||||
errout_with_envp:
|
||||
#endif
|
||||
binfmt_freeenv(envp);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/addrenv.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
@@ -61,7 +62,6 @@ static inline int exec_dtors(FAR struct binary_s *binp)
|
||||
{
|
||||
binfmt_dtor_t *dtor = binp->dtors;
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
save_addrenv_t oldenv;
|
||||
int ret;
|
||||
#endif
|
||||
int i;
|
||||
@@ -69,10 +69,10 @@ static inline int exec_dtors(FAR struct binary_s *binp)
|
||||
/* Instantiate the address environment containing the destructors */
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
ret = up_addrenv_select(&binp->addrenv, &oldenv);
|
||||
ret = addrenv_select(&binp->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select() failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -90,7 +90,7 @@ static inline int exec_dtors(FAR struct binary_s *binp)
|
||||
/* Restore the address environment */
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
return up_addrenv_restore(&oldenv);
|
||||
return addrenv_restore();
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
+6
-1
@@ -271,7 +271,12 @@ static int elf_loadbinary(FAR struct binary_s *binp,
|
||||
* needed when the module is executed.
|
||||
*/
|
||||
|
||||
up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv);
|
||||
up_addrenv_clone(&loadinfo.addrenv.addrenv, &binp->addrenv.addrenv);
|
||||
|
||||
/* Take a reference to the address environment, so it won't get freed */
|
||||
|
||||
addrenv_take(&binp->addrenv);
|
||||
|
||||
#else
|
||||
binp->alloc[0] = (FAR void *)loadinfo.textalloc;
|
||||
binp->alloc[1] = (FAR void *)loadinfo.dataalloc;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/addrenv.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
@@ -83,33 +84,38 @@ int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t textsize,
|
||||
size_t datasize, size_t heapsize)
|
||||
{
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
FAR struct arch_addrenv_s *addrenv = &loadinfo->addrenv.addrenv;
|
||||
FAR void *vtext;
|
||||
FAR void *vdata;
|
||||
int ret;
|
||||
|
||||
/* Create an address environment for the new ELF task */
|
||||
|
||||
ret = up_addrenv_create(textsize, datasize, heapsize, &loadinfo->addrenv);
|
||||
ret = up_addrenv_create(textsize, datasize, heapsize, addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_create failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Take a reference to the address environment, so it won't get freed */
|
||||
|
||||
addrenv_take(&loadinfo->addrenv);
|
||||
|
||||
/* Get the virtual address associated with the start of the address
|
||||
* environment. This is the base address that we will need to use to
|
||||
* access the ELF image (but only if the address environment has been
|
||||
* selected.
|
||||
*/
|
||||
|
||||
ret = up_addrenv_vtext(&loadinfo->addrenv, &vtext);
|
||||
ret = up_addrenv_vtext(addrenv, &vtext);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_vtext failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = up_addrenv_vdata(&loadinfo->addrenv, textsize, &vdata);
|
||||
ret = up_addrenv_vdata(addrenv, textsize, &vdata);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_vdata failed: %d\n", ret);
|
||||
@@ -171,16 +177,16 @@ int elf_addrenv_select(FAR struct elf_loadinfo_s *loadinfo)
|
||||
|
||||
/* Instantiate the new address environment */
|
||||
|
||||
ret = up_addrenv_select(&loadinfo->addrenv, &loadinfo->oldenv);
|
||||
ret = addrenv_select(&loadinfo->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_select failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Allow write access to .text */
|
||||
|
||||
ret = up_addrenv_mprot(&loadinfo->addrenv, loadinfo->textalloc,
|
||||
ret = up_addrenv_mprot(&loadinfo->addrenv.addrenv, loadinfo->textalloc,
|
||||
loadinfo->textsize, ELF_TEXT_WRE);
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -213,7 +219,7 @@ int elf_addrenv_restore(FAR struct elf_loadinfo_s *loadinfo)
|
||||
|
||||
/* Remove write access to .text */
|
||||
|
||||
ret = up_addrenv_mprot(&loadinfo->addrenv, loadinfo->textalloc,
|
||||
ret = up_addrenv_mprot(&loadinfo->addrenv.addrenv, loadinfo->textalloc,
|
||||
loadinfo->textsize, ELF_TEXT_WRD);
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -223,10 +229,10 @@ int elf_addrenv_restore(FAR struct elf_loadinfo_s *loadinfo)
|
||||
|
||||
/* Restore the old address environment */
|
||||
|
||||
ret = up_addrenv_restore(&loadinfo->oldenv);
|
||||
ret = addrenv_restore();
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_restore failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_restore failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -259,7 +265,7 @@ void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
|
||||
|
||||
/* Free the address environment */
|
||||
|
||||
ret = up_addrenv_destroy(&loadinfo->addrenv);
|
||||
ret = up_addrenv_destroy(&loadinfo->addrenv.addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_destroy failed: %d\n", ret);
|
||||
|
||||
@@ -643,7 +643,7 @@ int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
|
||||
*/
|
||||
|
||||
#if 0 /* REVISIT... has some problems */
|
||||
up_addrenv_coherent(&loadinfo->addrenv);
|
||||
up_addrenv_coherent(&loadinfo->addrenv.addrenv);
|
||||
#else
|
||||
up_coherent_dcache(loadinfo->textalloc, loadinfo->textsize);
|
||||
up_coherent_dcache(loadinfo->dataalloc, loadinfo->datasize);
|
||||
|
||||
@@ -76,26 +76,7 @@ int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
# define nxflat_addrenv_select(l) up_addrenv_select(&(l)->addrenv, &(l)->oldenv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_restore
|
||||
*
|
||||
* Description:
|
||||
* Restore the address environment before nxflat_addrenv_select() was
|
||||
* called..
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
# define nxflat_addrenv_restore(l) up_addrenv_restore(&(l)->oldenv)
|
||||
# define nxflat_addrenv_select(l) addrenv_select(&(l)->addrenv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/addrenv.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
@@ -70,8 +71,8 @@ int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
{
|
||||
FAR struct dspace_s *dspace;
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
FAR struct arch_addrenv_s *addrenv = &loadinfo->addrenv.addrenv;
|
||||
FAR void *vdata;
|
||||
save_addrenv_t oldenv;
|
||||
size_t heapsize;
|
||||
int ret;
|
||||
#endif
|
||||
@@ -101,20 +102,24 @@ int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
|
||||
/* Create a D-Space address environment for the new NXFLAT task */
|
||||
|
||||
ret = up_addrenv_create(0, envsize, heapsize, &loadinfo->addrenv);
|
||||
ret = up_addrenv_create(0, envsize, heapsize, addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_create failed: %d\n", ret);
|
||||
goto errout_with_dspace;
|
||||
}
|
||||
|
||||
/* Take a reference to the address environment, so it won't get freed */
|
||||
|
||||
addrenv_take(&loadinfo->addrenv);
|
||||
|
||||
/* Get the virtual address associated with the start of the address
|
||||
* environment. This is the base address that we will need to use to
|
||||
* access the D-Space region (but only if the address environment has been
|
||||
* selected.
|
||||
*/
|
||||
|
||||
ret = up_addrenv_vdata(&loadinfo->addrenv, 0, &vdata);
|
||||
ret = up_addrenv_vdata(addrenv, 0, &vdata);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_vdata failed: %d\n", ret);
|
||||
@@ -125,19 +130,19 @@ int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
* selected the D-Space address environment to do this.
|
||||
*/
|
||||
|
||||
ret = up_addrenv_select(loadinfo->addrenv, &oldenv);
|
||||
ret = addrenv_select(&loadinfo->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_select failed: %d\n", ret);
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
memset(vdata, 0, envsize);
|
||||
|
||||
ret = up_addrenv_restore(oldenv);
|
||||
ret = addrenv_restore();
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_restore failed: %d\n", ret);
|
||||
berr("ERROR: addrenv_restore failed: %d\n", ret);
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -202,7 +202,7 @@ static int nxflat_loadbinary(FAR struct binary_s *binp,
|
||||
* needed when the module is executed.
|
||||
*/
|
||||
|
||||
up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv);
|
||||
up_addrenv_clone(&loadinfo.addrenv.addrenv, &binp->addrenv.addrenv);
|
||||
#endif
|
||||
|
||||
nxflat_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt,
|
||||
|
||||
Reference in New Issue
Block a user