Skip to content

Commit

Permalink
libs/modlib: Load data using up_textheap_data_address
Browse files Browse the repository at this point in the history
Some chips have different memory addressing spaces for the same
region. This is true, for instance, for ESP32-S3: the same memory
region can be accessed using the data bus or the data bus using
different address ranges. The instruction bus, however, requires
word-aligned access. That being said, it is recommended to use the
data bus while copying sections to the text heap to avoid any
illegal access using the instruction bus address which will be
later used to run the program.
  • Loading branch information
tmedicci committed Nov 4, 2024
1 parent 3c4053a commit f55ccb9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libs/libc/modlib/modlib_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@

#define _ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))

#ifdef CONFIG_ARCH_USE_TEXT_HEAP
# define buffer_data_address(p) \
(FAR uint8_t *)up_textheap_data_address((FAR void *)p)
#else
# define buffer_data_address(p) ((FAR uint8_t *)p)
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -343,7 +350,8 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
{
if (phdr->p_flags & PF_X)
{
ret = modlib_read(loadinfo, text, phdr->p_filesz,
ret = modlib_read(loadinfo, buffer_data_address(text),
phdr->p_filesz,
phdr->p_offset);
}
else
Expand Down Expand Up @@ -441,8 +449,8 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)

/* Read the section data from sh_offset to the memory region */

ret = modlib_read(loadinfo, *pptr, shdr->sh_size,
shdr->sh_offset);
ret = modlib_read(loadinfo, buffer_data_address(*pptr),
shdr->sh_size, shdr->sh_offset);
if (ret < 0)
{
berr("ERROR: Failed to read section %d: %d\n", i, ret);
Expand Down

0 comments on commit f55ccb9

Please sign in to comment.