Skip to content

arch/xtensa/esp32s3: Fix ROM strdup heap issue in USER_HEAP mode#18563

Open
461911662 wants to merge 1 commit intoapache:masterfrom
461911662:master
Open

arch/xtensa/esp32s3: Fix ROM strdup heap issue in USER_HEAP mode#18563
461911662 wants to merge 1 commit intoapache:masterfrom
461911662:master

Conversation

@461911662
Copy link

In ESP32-S3 flat build with USER_HEAP mode, ROM strdup internally calls malloc which may be mapped to a different heap than lib_free, causing cross-heap allocation issues and system crashes.

This commit adds a new Kconfig option ESP32S3_DONT_USE_ROM_LIBC to allow using NuttX libc instead of ROM newlib functions. When USER_HEAP mode is selected, this option is automatically enabled.

Fixes: 60ca804 ("esp32s3: Fix bug related to the PSRAM-allocated task stack")

Reviewed-by: Tiago Medicci Serrano tiago.medicci@espressif.com
Reviewed-by: Almir Okato almir.okato@espressif.com
Reviewed-by: Eren Terzioglu eren.terzioglu@espressif.com

Note: Please adhere to Contributing Guidelines.

Summary

Update this section with information on why change is necessary,
what it exactly does and how, if new feature shows up, provide
references (dependencies, similar problems and solutions), etc.

Impact

Update this section, where applicable, on how change affects users,
build process, hardware, documentation, security, compatibility, etc.

Testing

This section should provide a detailed description of what you did
to verify your changes work and do not break existing code.

Please provide information about your host machine, the board(s) you
tested your changes on, and how you tested. Logs should be included.

For example, when changing something in the core OS functions, you
may want to run the OSTest application to verify that there are no
regressions. Changes to ADC code may warrant running the adc
example. Adding a new uORB driver may require that you run
uorb_listener to verify correct operation.

Pure documentation changes can just be tested with make html
(see docs) and verification of the correct format in your
browser.

PRs without testing information will not be accepted. We will
request test logs.

In ESP32-S3 flat build with USER_HEAP mode, ROM strdup internally calls
malloc which may be mapped to a different heap than lib_free, causing
cross-heap allocation issues and system crashes.

This commit adds a new Kconfig option ESP32S3_DONT_USE_ROM_LIBC to
allow using NuttX libc instead of ROM newlib functions. When USER_HEAP
mode is selected, this option is automatically enabled.

Fixes: 60ca804 ("esp32s3: Fix bug related to the PSRAM-allocated task stack")

Signed-off-by: 461911662 <461911662@qq.com>
Reviewed-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
Reviewed-by: Almir Okato <almir.okato@espressif.com>
Reviewed-by: Eren Terzioglu <eren.terzioglu@espressif.com>
@github-actions github-actions bot added Arch: xtensa Issues related to the Xtensa architecture Size: S The size of the change in this PR is small labels Mar 19, 2026
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @461911662 :-)

@461911662
Copy link
Author

461911662 commented Mar 19, 2026 via email

Copy link
Contributor

@linguini1 linguini1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please fill out the PR template?

@cederom
Copy link
Contributor

cederom commented Mar 20, 2026

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

This is an automated holiday reply email from QQ Mail. Hello, I am currently on vacation and unable to reply to your email personally. I will reply to you as soon as possible after my vacation ends.

@eren-terzioglu
Copy link
Contributor

Hi,

We were planning to use Nuttx implementation of strdup and strndup functions but disabling all the other functions might causes some issues. We need to check, please do not merge it.

Thanks for your work.

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to mark waiting for @eren-terzioglu verification and confirmation :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: xtensa Issues related to the Xtensa architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants