mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
binfmt: Introduce a separate text memory for ELF
Summary: - This commit introduces a separate text memory for ELF - The logic is similar to modlib Impact: - None Testing: - Tested with spresense:elf - NOTE: needs separate commits Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
committed by
Xiang Xiao
parent
bebdbc5c87
commit
4d492104a7
@@ -117,13 +117,30 @@ int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t textsize,
|
|||||||
#else
|
#else
|
||||||
/* Allocate memory to hold the ELF image */
|
/* Allocate memory to hold the ELF image */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ARCH_USE_MODULE_TEXT)
|
||||||
|
loadinfo->textalloc = (uintptr_t)
|
||||||
|
up_module_text_memalign(loadinfo->textalign,
|
||||||
|
textsize);
|
||||||
|
#else
|
||||||
loadinfo->textalloc = (uintptr_t)kumm_malloc(textsize + datasize);
|
loadinfo->textalloc = (uintptr_t)kumm_malloc(textsize + datasize);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!loadinfo->textalloc)
|
if (!loadinfo->textalloc)
|
||||||
{
|
{
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_ARCH_USE_MODULE_TEXT)
|
||||||
|
loadinfo->dataalloc = (uintptr_t)kumm_malloc(datasize);
|
||||||
|
|
||||||
|
if (0 != datasize && !loadinfo->dataalloc)
|
||||||
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
#else
|
||||||
loadinfo->dataalloc = loadinfo->textalloc + textsize;
|
loadinfo->dataalloc = loadinfo->textalloc + textsize;
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -159,12 +176,26 @@ void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
|
|||||||
berr("ERROR: up_addrenv_destroy failed: %d\n", ret);
|
berr("ERROR: up_addrenv_destroy failed: %d\n", ret);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#if defined(CONFIG_ARCH_USE_MODULE_TEXT)
|
||||||
|
if (loadinfo->textalloc != 0)
|
||||||
|
{
|
||||||
|
up_module_text_free((FAR void *)loadinfo->textalloc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loadinfo->dataalloc != 0)
|
||||||
|
{
|
||||||
|
kumm_free((FAR void *)loadinfo->dataalloc);
|
||||||
|
}
|
||||||
|
#else
|
||||||
/* If there is an allocation for the ELF image, free it */
|
/* If there is an allocation for the ELF image, free it */
|
||||||
|
|
||||||
if (loadinfo->textalloc != 0)
|
if (loadinfo->textalloc != 0)
|
||||||
{
|
{
|
||||||
kumm_free((FAR void *)loadinfo->textalloc);
|
kumm_free((FAR void *)loadinfo->textalloc);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Clear out all indications of the allocated address environment */
|
/* Clear out all indications of the allocated address environment */
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ struct elf_loadinfo_s
|
|||||||
uintptr_t textalloc; /* .text memory allocated when ELF file was loaded */
|
uintptr_t textalloc; /* .text memory allocated when ELF file was loaded */
|
||||||
uintptr_t dataalloc; /* .bss/.data memory allocated when ELF file was loaded */
|
uintptr_t dataalloc; /* .bss/.data memory allocated when ELF file was loaded */
|
||||||
size_t textsize; /* Size of the ELF .text memory allocation */
|
size_t textsize; /* Size of the ELF .text memory allocation */
|
||||||
|
#ifdef CONFIG_ARCH_USE_MODULE_TEXT
|
||||||
|
size_t textalign; /* Necessary alignment of .text */
|
||||||
|
#endif
|
||||||
size_t datasize; /* Size of the ELF .bss/.data memory allocation */
|
size_t datasize; /* Size of the ELF .bss/.data memory allocation */
|
||||||
off_t filelen; /* Length of the entire ELF file */
|
off_t filelen; /* Length of the entire ELF file */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user