Executing code on stack. Writing to IRAM. Possible?

vvb333007
Posts: 79
Joined: Wed Jul 31, 2024 5:53 am
Location: Thailand
Contact:

Executing code on stack. Writing to IRAM. Possible?

Postby vvb333007 » Fri Apr 04, 2025 8:21 am

Hello,

I am trying to find bits of information on MMU & memory usage on ESP32. In particular: how we can (can we?) execute code, which is located on stack? Or code must be located in IRAM?

Is it possible to disable write-protection for the IRAM so I can modify some code, invalidate icache and jump to that code?

Thanks!
Thanks!
Slava.

Sprite
Espressif staff
Espressif staff
Posts: 10650
Joined: Thu Nov 26, 2015 4:08 am

Re: Executing code on stack. Writing to IRAM. Possible?

Postby Sprite » Sat Apr 05, 2025 3:28 am

The (original) ESP32 can only execute code in IRAM, not in DRAM. Since the stack tends to be in DRAM you cannot execute code from there. You can allocate a chunk of IRAM using heap_malloc_caps(), put your code in there, then jump to it or call into it. I don't think the (original) ESP32 has write protection in place for IRAM, but later chips (ESP32-Sx, ESP32-Cx, ...) may have.

vvb333007
Posts: 79
Joined: Wed Jul 31, 2024 5:53 am
Location: Thailand
Contact:

Re: Executing code on stack. Writing to IRAM. Possible?

Postby vvb333007 » Mon Apr 07, 2025 3:39 pm

Thank you for the reply!
Now I see why there is a problem with C trampolines.
Thanks!
Slava.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], trendictionbot and 1 guest