Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
Cleanup remnants from backport
  • Loading branch information
mhightower83 committed Sep 3, 2024
1 parent 2bbadca commit 49b48fb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 60 deletions.
8 changes: 5 additions & 3 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using __cxxabiv1::__guard;

// Debugging helper, last allocation which returned NULL
extern "C" void *_heap_abi_malloc(size_t size, bool unhandled, const void* const caller);
extern "C" void* _heap_abi_malloc(size_t size, bool unhandled, const void* const caller);

extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
Expand All @@ -36,15 +36,16 @@ extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
* With the option "DEBUG_ESP_OOM," always do Last OOM tracking.
* Otherwise, disable Last OOM tracking. The build relies on the weak link to
the default C++ exception handler.
This saves about 136 bytes of IROM, code in flash.
*/

// Debug replacement adaptation from ".../new_op.cc".
using std::new_handler;
using std::bad_alloc;

void * operator new (std::size_t size)
void* operator new (std::size_t size)
{
void *p;
void* p;

/* malloc (0) is unpredictable; avoid it. */
if (__builtin_expect(size == 0, false)) {
Expand All @@ -61,6 +62,7 @@ void * operator new (std::size_t size)

return p;
}

#elif !defined(__cpp_exceptions)
// When doing builds with C++ Exceptions "disabled", always save details of
// the last OOM event.
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static void postmortem_report(uint32_t sp_dump) {
ets_printf_P(PSTR("\nlast failed alloc call: 0x%08X(%d), File: %S:%d\n"),
(uint32_t)_umm_last_fail_alloc.addr,
_umm_last_fail_alloc.size,
(_umm_last_fail_alloc.file) ? _umm_last_fail_alloc.file : "??",
(_umm_last_fail_alloc.file) ? _umm_last_fail_alloc.file : PSTR("??"),
_umm_last_fail_alloc.line);
#else
ets_printf_P(PSTR("\nlast failed alloc call: %08X(%d)\n"), (uint32_t)_umm_last_fail_alloc.addr, _umm_last_fail_alloc.size);
Expand Down
99 changes: 48 additions & 51 deletions cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ extern "C" {
*
* Support debug wrappers that need to include handling poison
*/
#define UMM_MALLOC_FL(s,f,l,c) umm_poison_malloc(s)
#define UMM_CALLOC_FL(n,s,f,l,c) umm_poison_calloc(n,s)
#define UMM_MALLOC(s) umm_poison_malloc(s)
#define UMM_CALLOC(n,s) umm_poison_calloc(n,s)
#define UMM_REALLOC_FL(p,s,f,l,c) umm_poison_realloc_flc(p,s,f,l,c)
#define UMM_FREE_FL(p,f,l,c) umm_poison_free_flc(p,f,l,c)
#define ENABLE_THICK_DEBUG_WRAPPERS
Expand All @@ -161,19 +161,19 @@ extern "C" {
*
* Support debug wrappers that need to include handling poison
*/
#define UMM_MALLOC_FL(s,f,l,c) umm_poison_malloc(s)
#define UMM_CALLOC_FL(n,s,f,l,c) umm_poison_calloc(n,s)
#define UMM_MALLOC(s) umm_poison_malloc(s)
#define UMM_CALLOC(n,s) umm_poison_calloc(n,s)
#define UMM_REALLOC_FL(p,s,f,l,c) umm_poison_realloc(p,s)
#define UMM_FREE_FL(p,f,l,c) umm_poison_free(p)
#define ENABLE_THICK_DEBUG_WRAPPERS

#undef realloc
#undef free

#elif defined(DEBUG_ESP_OOM) || defined(UMM_INTEGRITY_CHECK) || defined(DEBUG_ESP_WITHINISR) || defined(HEAP_DEBUG_PROBE_PSFLC_CB)
#elif defined(DEBUG_ESP_OOM) || defined(UMM_INTEGRITY_CHECK) || defined(DEBUG_ESP_WITHINISR)
// All other debug wrappers that do not require handling poison
#define UMM_MALLOC_FL(s,f,l,c) umm_malloc(s)
#define UMM_CALLOC_FL(n,s,f,l,c) umm_calloc(n,s)
#define UMM_MALLOC(s) umm_malloc(s)
#define UMM_CALLOC(n,s) umm_calloc(n,s)
#define UMM_REALLOC_FL(p,s,f,l,c) umm_realloc(p,s)
#define UMM_FREE_FL(p,f,l,c) umm_free(p)
#define ENABLE_THICK_DEBUG_WRAPPERS
Expand Down Expand Up @@ -241,19 +241,19 @@ extern "C" {
// always track last failed caller and size requested
#if defined(DEBUG_ESP_OOM)
struct umm_last_fail_alloc {
const void *addr;
size_t size;
const char *file;
int line;
} _umm_last_fail_alloc = {NULL, 0, NULL, 0};
const void *addr = { nullptr };
size_t size = { 0 };
const char *file = { nullptr };
int line = { 0 };
} _umm_last_fail_alloc;

#else
// Note for the least used case "(defined(__cpp_exceptions) &&
// !defined(DEBUG_ESP_OOM))", we only capture details for LIBC calls.
struct umm_last_fail_alloc {
const void *addr;
size_t size;
} _umm_last_fail_alloc = {NULL, 0};
const void *addr = { nullptr };
size_t size = { 0 };
} _umm_last_fail_alloc;
#endif


Expand Down Expand Up @@ -314,7 +314,7 @@ static bool IRAM_ATTR oom_check__log_last_fail_atomic_psflc(void *ptr, size_t si
return true;
}
#define OOM_CHECK__LOG_LAST_FAIL_FL(p, s, f, l, c) oom_check__log_last_fail_atomic_psflc(p, s, f, l, c)
#define OOM_CHECK__LOG_LAST_FAIL_LITE_FL(p, s, f, l, c) ({ (void)p, (void)s, (void)f; (void)l; (void)c; true; })
#define OOM_CHECK__LOG_LAST_FAIL_LITE_FL(p, s, c) ({ (void)p; (void)s; (void)c; true; })

#elif defined(ENABLE_THICK_DEBUG_WRAPPERS)
static bool IRAM_ATTR oom_check__log_last_fail_atomic_psc(void *ptr, size_t size, const void* caller) {
Expand All @@ -329,7 +329,7 @@ static bool IRAM_ATTR oom_check__log_last_fail_atomic_psc(void *ptr, size_t size
return true;
}
#define OOM_CHECK__LOG_LAST_FAIL_FL(p, s, f, l, c) oom_check__log_last_fail_atomic_psc(p, s, c)
#define OOM_CHECK__LOG_LAST_FAIL_LITE_FL(p, s, f, l, c) ({ (void)p, (void)s, (void)f; (void)l; (void)c; true; })
#define OOM_CHECK__LOG_LAST_FAIL_LITE_FL(p, s, c) ({ (void)p; (void)s; (void)c; true; })

#else
// At this location, the macro is only used by Heap API families "new" and
Expand All @@ -344,8 +344,8 @@ static bool oom_check__log_last_fail_psc(void *ptr, size_t size, const void* cal
return true;
}
// Used to capture minumum OOM info for "new" and LIBC
#define OOM_CHECK__LOG_LAST_FAIL_LITE_FL(p, s, f, l, c) oom_check__log_last_fail_psc(p, s, c)
#define OOM_CHECK__LOG_LAST_FAIL_FL(p, s, f, l, c) ({ (void)p, (void)s, (void)f; (void)l; (void)c; true; })
#define OOM_CHECK__LOG_LAST_FAIL_LITE_FL(p, s, c) oom_check__log_last_fail_psc(p, s, c)
#define OOM_CHECK__LOG_LAST_FAIL_FL(p, s, c) ({ (void)p; (void)s; (void)c; true; })
#endif


Expand Down Expand Up @@ -398,26 +398,26 @@ static void isr_check__flash_not_safe(const void *caller) {
// * "fancy macros" that call heap_pvPortMalloc, ...
// * Fallback for uncapture malloc API calls, malloc, ...
//
void* IRAM_ATTR _heap_pvPortMalloc(size_t size, const char* file, int line, const void *caller)
void* IRAM_ATTR _heap_pvPortMalloc(size_t size, const char* file, int line, const void* caller)
{
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
POISON_CHECK__PANIC_FL(file, line, caller);
void* ret = UMM_MALLOC_FL(size, file, line, caller);
void* ret = UMM_MALLOC(size);
OOM_CHECK__LOG_LAST_FAIL_FL(ret, size, file, line, caller);
return ret;
}

void* IRAM_ATTR _heap_pvPortCalloc(size_t count, size_t size, const char* file, int line, const void *caller)
void* IRAM_ATTR _heap_pvPortCalloc(size_t count, size_t size, const char* file, int line, const void* caller)
{
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
POISON_CHECK__PANIC_FL(file, line, caller);
size_t total_size = umm_umul_sat(count, size);
void* ret = UMM_CALLOC_FL(1, total_size, file, line, caller);
void* ret = UMM_CALLOC(1, total_size);
OOM_CHECK__LOG_LAST_FAIL_FL(ret, total_size, file, line, caller);
return ret;
}

void* IRAM_ATTR _heap_pvPortRealloc(void *ptr, size_t size, const char* file, int line, const void *caller)
void* IRAM_ATTR _heap_pvPortRealloc(void* ptr, size_t size, const char* file, int line, const void* caller)
{
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
POISON_CHECK__PANIC_FL(file, line, caller);
Expand All @@ -426,7 +426,7 @@ void* IRAM_ATTR _heap_pvPortRealloc(void *ptr, size_t size, const char* file, in
return ret;
}

void IRAM_ATTR _heap_vPortFree(void *ptr, const char* file, int line, [[maybe_unused]] const void *caller)
void IRAM_ATTR _heap_vPortFree(void* ptr, const char* file, int line, [[maybe_unused]] const void* caller)
{
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
POISON_CHECK__PANIC_FL(file, line, caller);
Expand All @@ -448,12 +448,12 @@ void* IRAM_ATTR heap_pvPortCalloc(size_t count, size_t size, const char* file, i
return _heap_pvPortCalloc(count, size, file, line, __builtin_return_address(0));
}

void* IRAM_ATTR heap_pvPortRealloc(void *ptr, size_t size, const char* file, int line)
void* IRAM_ATTR heap_pvPortRealloc(void* ptr, size_t size, const char* file, int line)
{
return _heap_pvPortRealloc(ptr, size, file, line, __builtin_return_address(0));
}

void IRAM_ATTR heap_vPortFree(void *ptr, const char* file, int line)
void IRAM_ATTR heap_vPortFree(void* ptr, const char* file, int line)
{
return _heap_vPortFree(ptr, file, line, __builtin_return_address(0));
}
Expand Down Expand Up @@ -489,7 +489,7 @@ void IRAM_ATTR free(void* ptr)
#define STATIC_ALWAYS_INLINE static ALWAYS_INLINE

STATIC_ALWAYS_INLINE
void* IRAM_ATTR _heap_pvPortMalloc(size_t size, const char* file, int line, const void *caller)
void* IRAM_ATTR _heap_pvPortMalloc(size_t size, const char* file, int line, const void* caller)
{
(void)file;
(void)line;
Expand All @@ -498,7 +498,7 @@ void* IRAM_ATTR _heap_pvPortMalloc(size_t size, const char* file, int line, cons
}

STATIC_ALWAYS_INLINE
void* IRAM_ATTR _heap_pvPortCalloc(size_t count, size_t size, const char* file, int line, const void *caller)
void* IRAM_ATTR _heap_pvPortCalloc(size_t count, size_t size, const char* file, int line, const void* caller)
{
(void)file;
(void)line;
Expand All @@ -507,7 +507,7 @@ void* IRAM_ATTR _heap_pvPortCalloc(size_t count, size_t size, const char* file,
}

STATIC_ALWAYS_INLINE
void* IRAM_ATTR _heap_pvPortRealloc(void *ptr, size_t size, const char* file, int line, const void *caller)
void* IRAM_ATTR _heap_pvPortRealloc(void* ptr, size_t size, const char* file, int line, const void* caller)
{
(void)file;
(void)line;
Expand All @@ -516,7 +516,7 @@ void* IRAM_ATTR _heap_pvPortRealloc(void *ptr, size_t size, const char* file, in
}

STATIC_ALWAYS_INLINE
void IRAM_ATTR _heap_vPortFree(void *ptr, const char* file, int line, const void *caller)
void IRAM_ATTR _heap_vPortFree(void* ptr, const char* file, int line, const void* caller)
{
(void)file;
(void)line;
Expand All @@ -532,37 +532,37 @@ void IRAM_ATTR _heap_vPortFree(void *ptr, const char* file, int line, const void
void* _malloc_r(struct _reent* unused, size_t size)
{
(void) unused;
void *caller = __builtin_return_address(0);
void* caller = __builtin_return_address(0);
ISR_CHECK__LOG_NOT_SAFE(caller);
void* ret = _heap_pvPortMalloc(size, NULL, 0, caller);
OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, NULL, 0, caller);
OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, caller);
return ret;
}

void* _calloc_r(struct _reent* unused, size_t count, size_t size)
{
(void) unused;
void *caller = __builtin_return_address(0);
void* caller = __builtin_return_address(0);
ISR_CHECK__LOG_NOT_SAFE(caller);
void* ret = _heap_pvPortCalloc(count, size, NULL, 0, caller);
OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, NULL, 0, caller);
OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, caller);
return ret;
}

void* _realloc_r(struct _reent* unused, void* ptr, size_t size)
{
(void) unused;
void *caller = __builtin_return_address(0);
void* caller = __builtin_return_address(0);
ISR_CHECK__LOG_NOT_SAFE(caller);
void* ret = _heap_pvPortRealloc(ptr, size, NULL, 0, caller);
OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, NULL, 0, caller);
OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, caller);
return ret;
}

void _free_r(struct _reent* unused, void* ptr)
{
(void) unused;
void *caller = __builtin_return_address(0);
void* caller = __builtin_return_address(0);
ISR_CHECK__LOG_NOT_SAFE(caller);
_heap_vPortFree(ptr, NULL, 0, caller);
}
Expand Down Expand Up @@ -590,7 +590,7 @@ void* IRAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int li
return _heap_pvPortCalloc(count, size, file, line, __builtin_return_address(0));
}

void* IRAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
void* IRAM_ATTR pvPortRealloc(void* ptr, size_t size, const char* file, int line)
{
HeapSelectDram ephemeral;
return _heap_pvPortRealloc(ptr, size, file, line, __builtin_return_address(0));
Expand All @@ -602,7 +602,7 @@ void* IRAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
return _heap_pvPortCalloc(1, size, file, line, __builtin_return_address(0));
}

void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
void IRAM_ATTR vPortFree(void* ptr, const char* file, int line)
{
#if defined(UMM_POISON_CHECK) || defined(UMM_INTEGRITY_CHECK)
// While umm_free internally determines the correct heap, UMM_POISON_CHECK
Expand Down Expand Up @@ -639,19 +639,16 @@ void system_show_malloc(void)
// heap allocator for "new" (ABI) - To support collecting OOM info, always defined
void* _heap_abi_malloc(size_t size, bool unhandled, const void* caller)
{
[[maybe_unused]] const char *file = NULL;
[[maybe_unused]] const int line = 0;

#ifdef ENABLE_THICK_DEBUG_WRAPPERS
ISR_CHECK__LOG_NOT_SAFE(caller);
INTEGRITY_CHECK__PANIC_FL(file, line, caller);
POISON_CHECK__PANIC_FL(file, line, caller);
void* ret = UMM_MALLOC_FL(size, file, line, caller);
bool ok = OOM_CHECK__LOG_LAST_FAIL_FL(ret, size, file, line, caller);
INTEGRITY_CHECK__PANIC_FL(NULL, 0, caller);
POISON_CHECK__PANIC_FL(NULL, 0, caller);
void* ret = UMM_MALLOC(size);
bool ok = OOM_CHECK__LOG_LAST_FAIL_FL(ret, size, NULL, 0, caller);
#else
void* ret = UMM_MALLOC(size);
// minimum OOM check
bool ok = OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, file, line, caller);
bool ok = OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, caller);
#endif
if (!ok && unhandled) {
__unhandled_exception(PSTR("OOM"));
Expand Down Expand Up @@ -767,22 +764,22 @@ uint32 IRAM_ATTR user_iram_memory_is_enabled(void)
//
#include <bits/c++config.h>
#include <cstdlib>
#include "new"
#include <new>

// The sized deletes are defined in other files.
#pragma GCC diagnostic ignored "-Wsized-deallocation"

// These function replace their weak counterparts tagged with _GLIBCXX_WEAK_DEFINITION
void operator delete(void* ptr) noexcept
{
void *caller = __builtin_return_address(0);
void* caller = __builtin_return_address(0);
ISR_CHECK__LOG_NOT_SAFE(caller);
_heap_vPortFree(ptr, NULL, 0, caller);
}

void operator delete(void* ptr, std::size_t) noexcept
{
void *caller = __builtin_return_address(0);
void* caller = __builtin_return_address(0);
ISR_CHECK__LOG_NOT_SAFE(caller);
_heap_vPortFree(ptr, NULL, 0, caller);
}
Expand Down
3 changes: 1 addition & 2 deletions cores/esp8266/umm_malloc/umm_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ static size_t umm_uadd_sat(const size_t a, const size_t b);


#if defined(DEBUG_ESP_OOM) || defined(UMM_POISON_CHECK) \
|| defined(UMM_POISON_CHECK_LITE) || defined(UMM_INTEGRITY_CHECK) \
|| defined(HEAP_DEBUG_PROBE_PSFLC_CB) || defined(_HEAP_DEBUG_PROBE_PSFLC_CB)
|| defined(UMM_POISON_CHECK_LITE) || defined(UMM_INTEGRITY_CHECK)
#else
#define umm_malloc(s) malloc(s)
#define umm_calloc(n,s) calloc(n,s)
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266SdFat
Submodule ESP8266SdFat updated 155 files
2 changes: 1 addition & 1 deletion libraries/SoftwareSerial
2 changes: 1 addition & 1 deletion tools/sdk/lwip2/builder

0 comments on commit 49b48fb

Please sign in to comment.