mirror of
https://github.com/apache/nuttx.git
synced 2026-09-27 10:46:02 +08:00
Adapt dlfcn/modlib to use the instruction memory allocator
This commit is contained in:
committed by
patacongo
parent
855751b534
commit
061b796d47
@@ -7,6 +7,7 @@ config LIBC_MODLIB
|
||||
bool
|
||||
default n
|
||||
select LIBC_ARCH_ELF
|
||||
select ARCH_USE_MODULE_TEXT if ARCH_HAVE_MODULE_TEXT
|
||||
|
||||
menu "Module library configuration"
|
||||
depends on LIBC_MODLIB
|
||||
|
||||
@@ -262,6 +262,30 @@ int modlib_load(FAR struct mod_loadinfo_s *loadinfo)
|
||||
|
||||
/* Allocate memory to hold the ELF image */
|
||||
|
||||
#if defined(CONFIG_ARCH_USE_MODULE_TEXT)
|
||||
if (loadinfo->textsize > 0)
|
||||
{
|
||||
loadinfo->textalloc = (uintptr_t)
|
||||
up_module_text_alloc(loadinfo->textsize);
|
||||
if (!loadinfo->textalloc)
|
||||
{
|
||||
berr("ERROR: Failed to allocate memory for the module text\n");
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
}
|
||||
|
||||
if (loadinfo->datasize > 0)
|
||||
{
|
||||
loadinfo->datastart = (uintptr_t)lib_malloc(loadinfo->datasize);
|
||||
if (!loadinfo->datastart)
|
||||
{
|
||||
berr("ERROR: Failed to allocate memory for the module data\n");
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
}
|
||||
#else
|
||||
loadinfo->textalloc = (uintptr_t)lib_malloc(loadinfo->textsize +
|
||||
loadinfo->datasize);
|
||||
if (!loadinfo->textalloc)
|
||||
@@ -272,6 +296,7 @@ int modlib_load(FAR struct mod_loadinfo_s *loadinfo)
|
||||
}
|
||||
|
||||
loadinfo->datastart = loadinfo->textalloc + loadinfo->textsize;
|
||||
#endif
|
||||
|
||||
/* Load ELF section data into memory */
|
||||
|
||||
|
||||
@@ -73,10 +73,22 @@ int modlib_unload(struct mod_loadinfo_s *loadinfo)
|
||||
|
||||
/* Release memory holding the relocated ELF image */
|
||||
|
||||
#if defined(CONFIG_ARCH_USE_MODULE_TEXT)
|
||||
if (loadinfo->textalloc != 0)
|
||||
{
|
||||
up_module_text_free((FAR void *)loadinfo->textalloc);
|
||||
}
|
||||
|
||||
if (loadinfo->datastart != 0)
|
||||
{
|
||||
lib_free((FAR void *)loadinfo->datastart);
|
||||
}
|
||||
#else
|
||||
if (loadinfo->textalloc != 0)
|
||||
{
|
||||
lib_free((FAR void *)loadinfo->textalloc);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clear out all indications of the allocated address environment */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user