Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4a0b66b

Browse files
authoredDec 16, 2022
Heap addendum to handle changes in NON-OS SDK 3.0.x (#8746)
## WPA2 Enterprise connections References - merged PRs: * #8529 * #8566 - these occurred with connect/disconnect with WPA-Enterprise * #8736 (comment) The NON-OS SDK 3.0.x has breaking changes to the [`pvPortMalloc`](https://github.com/espressif/ESP8266_NONOS_SDK/blob/bf890b22e57a41d5cda00f9c8191f3f7035a87b4/include/mem.h#L42) function. They added a new `bool` argument for selecting a heap. ```cpp void *pvPortMalloc (size_t sz, const char *, unsigned, bool); ``` To avoid breaking the build, I added a new thin wrapper function `sdk3_pvPortMalloc` to `heap.cpp`. Edited new SDK LIBs to call `pvPortMalloc`'s replacement `sdk3_pvPortMalloc`. They also added `pvPortZallocIram` and `pvPortCallocIram`, which are not a problem to support. Support added to `heap.cpp`. Issues with WPA2 Enterprise in new SDKs: * v3.0.0 and v3.0.1 - have the same memory leak and duplicate free bugs from before * v3.0.2 through v3.0.5 - have the same memory leak; however, _no_ duplicate free crash. * memory leak can be seen by cycling through setup, connect, disconnect, and clear setup - repeatedly. Updated `wpa2_eap_patch.cpp` and binary patch scripts to handle v3.0.0 through v3.0.5. Patched SDKs v3.0.0 through v3.0.5 ## Duplicate Non-32-bit exception handler Issue: At v3.0.0 and above `libmain.a` supplies a built-in exception handler (`load_non_32_wide_handler`) for non-32-bit access. Our non-32-bit access handler (`non32xfer_exception_handler`) overrides it. Solution: Add "weak" attribute to symbol `load_non_32_wide_handler`. Adjust the build to default to the SDK's built-in non-32-bit handler. If there is a need to use our non-32-bit handler, make the selection from the Arduino IDE Tools menu `Non-32-Bit Access: "Byte/Word access to IRAM/PROGMEM (very slow)"`. With SDKs v3.0.0 and above a "non-32-bit exception handler" is always present.
1 parent d3c8d27 commit 4a0b66b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+317
-66
lines changed
 

‎cores/esp8266/core_esp8266_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ extern "C" void user_init(void) {
496496
install_vm_exception_handler();
497497
#endif
498498

499-
#if defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)
499+
#if defined(NON32XFER_HANDLER) || (defined(MMU_IRAM_HEAP) && (NONOSDK < (0x30000 - 1)))
500500
install_non32xfer_exception_handler();
501501
#endif
502502

‎cores/esp8266/core_esp8266_non32xfer.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626
* Code taken directly from @pvvx's public domain code in
2727
* https://github.com/pvvx/esp8266web/blob/master/app/sdklib/system/app_main.c
2828
*
29+
* In Espressif versions NONOSDK v3.0.0+ a similar feature was added
30+
* load_non_32_wide_handler. Theirs is always loaded. Add weak attribute to
31+
* theirs so we can choose by adding an alias to ours.
2932
*
3033
*/
3134

3235
#include <Arduino.h>
36+
#include <user_interface.h>
3337
#define VERIFY_C_ASM_EXCEPTION_FRAME_STRUCTURE
3438
#include <esp8266_undocumented.h>
3539
#include <core_esp8266_non32xfer.h>
@@ -58,10 +62,13 @@ extern "C" {
5862

5963
#define EXCCAUSE_LOAD_STORE_ERROR 3 /* Non 32-bit read/write error */
6064

65+
#if (defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)) && (NONOSDK < (0x30000 - 1))
6166
static fn_c_exception_handler_t old_c_handler = NULL;
67+
#endif
6268

69+
#if defined(NON32XFER_HANDLER) || (defined(MMU_IRAM_HEAP) && (NONOSDK < (0x30000 - 1)))
6370
static
64-
IRAM_ATTR void non32xfer_exception_handler(struct __exception_frame *ef, int cause)
71+
IRAM_ATTR void non32xfer_exception_handler(struct __exception_frame *ef, [[maybe_unused]] int cause)
6572
{
6673
do {
6774
uint32_t insn, excvaddr;
@@ -138,6 +145,7 @@ IRAM_ATTR void non32xfer_exception_handler(struct __exception_frame *ef, int cau
138145
} while(false);
139146

140147
/* Fail request, die */
148+
#if (NONOSDK < (0x30000 - 1))
141149
/*
142150
The old handler points to the SDK. Be alert for HWDT when Calling with
143151
INTLEVEL != 0. I cannot create it any more. I thought I saw this as a
@@ -148,16 +156,23 @@ IRAM_ATTR void non32xfer_exception_handler(struct __exception_frame *ef, int cau
148156
old_c_handler(ef, cause);
149157
return;
150158
}
151-
159+
#endif
152160
/*
153161
Calling _xtos_unhandled_exception(ef, cause) in the Boot ROM, gets us a
154162
hardware wdt.
155163
156164
Use panic instead as a fall back. It will produce a stack trace.
157165
*/
166+
#if defined(DEBUG_ESP_PORT) || defined(DEBUG_ESP_MMU)
158167
panic();
168+
#else
169+
// For non-debug builds, save on resources
170+
abort();
171+
#endif
159172
}
173+
#endif // #if defined(NON32XFER_HANDLER) || (defined(MMU_IRAM_HEAP) && (NONOSDK < (0x30000 - 1)))
160174

175+
#if (defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)) && (NONOSDK < (0x30000 - 1))
161176
/*
162177
To operate reliably, this module requires the new
163178
`_xtos_set_exception_handler` from `exc-sethandler.cpp` and
@@ -174,5 +189,17 @@ void install_non32xfer_exception_handler(void) {
174189
non32xfer_exception_handler);
175190
}
176191
}
192+
#else
193+
// For v3.0.x SDKs, no need for install - call_user_start will do the job.
194+
// Need this for build dependencies
195+
void install_non32xfer_exception_handler(void) __attribute__((weak));
196+
void install_non32xfer_exception_handler(void) {}
197+
#endif
198+
199+
#if defined(NON32XFER_HANDLER)
200+
// For SDKs 3.0.x, we made load_non_32_wide_handler in
201+
// libmain.c:user_exceptions.o a weak symbol allowing this override to work.
202+
extern void load_non_32_wide_handler(struct __exception_frame *ef, int cause) __attribute__((alias("non32xfer_exception_handler")));
203+
#endif
177204

178205
};

0 commit comments

Comments
 (0)
Please sign in to comment.