Skip to content

Commit f6a72ad

Browse files
tmediccixiaoxiang781216
authored andcommitted
libs/modlib: Load data using up_textheap_data_address
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.
1 parent c371afc commit f6a72ad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

libs/libc/modlib/modlib_load.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757

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

60+
#ifdef CONFIG_ARCH_USE_TEXT_HEAP
61+
# define buffer_data_address(p) \
62+
(FAR uint8_t *)up_textheap_data_address((FAR void *)p)
63+
#else
64+
# define buffer_data_address(p) ((FAR uint8_t *)p)
65+
#endif
66+
6067
/****************************************************************************
6168
* Private Functions
6269
****************************************************************************/
@@ -343,7 +350,8 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
343350
{
344351
if (phdr->p_flags & PF_X)
345352
{
346-
ret = modlib_read(loadinfo, text, phdr->p_filesz,
353+
ret = modlib_read(loadinfo, buffer_data_address(text),
354+
phdr->p_filesz,
347355
phdr->p_offset);
348356
}
349357
else
@@ -441,8 +449,8 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
441449

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

444-
ret = modlib_read(loadinfo, *pptr, shdr->sh_size,
445-
shdr->sh_offset);
452+
ret = modlib_read(loadinfo, buffer_data_address(*pptr),
453+
shdr->sh_size, shdr->sh_offset);
446454
if (ret < 0)
447455
{
448456
berr("ERROR: Failed to read section %d: %d\n", i, ret);

0 commit comments

Comments
 (0)