Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core with upstream umm_malloc #6438

Merged
merged 40 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
88a32c8
WIP: Initial overlay of upstream version of umm_malloc over
mhightower83 Aug 20, 2019
b508642
WIP: upstream version of umm_malloc customized for Arduino ESP8266 Core
mhightower83 Aug 20, 2019
d7363e0
Resoved Travis CI - issue
mhightower83 Aug 23, 2019
57b65ab
Corrected #ifdef's for UMM_STATS/UMM_STATS_FULL
mhightower83 Aug 27, 2019
da47a79
Merge branch 'master' into WIP-upstream-umm_malloc
d-a-v Aug 29, 2019
71b10fd
Corrected UMM_REALLOC_DEFRAG option to be more like the original umm_…
mhightower83 Sep 3, 2019
4612235
Merge branch 'WIP-upstream-umm_malloc' of github.com:mhightower83/Ard…
mhightower83 Sep 3, 2019
79fe67f
Updated UMM_POISON_CHECK_LITE - Expanded the poison check on the current
mhightower83 Sep 5, 2019
5ded134
Updated printing in heap.cpp to behave the way os_printf did.
mhightower83 Sep 8, 2019
2a1923e
Merged latest, 2019-09-07, from upstream umm_malloc
mhightower83 Sep 8, 2019
f68a64f
Resolved issue where OOM selected w/ Debug port: "Disabled" caused hang.
mhightower83 Sep 8, 2019
9fcf27b
Fixed realloc OOM bug introduced due to confusing code, added comment…
mhightower83 Sep 9, 2019
ad03e16
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Sep 11, 2019
f438e02
Updated to track PRs for various print definitions. Cleaned up comments
mhightower83 Sep 27, 2019
919b122
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Sep 28, 2019
35c6868
Added missing "#ifdef __cplusplus"
mhightower83 Sep 28, 2019
47563cd
Reorganize local enhancements
mhightower83 Sep 29, 2019
2a1b722
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Sep 30, 2019
5560f6b
Print notice message for the need of -DUMM_INFO_PRINT
mhightower83 Sep 30, 2019
c4a46bc
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Sep 30, 2019
0b89ce7
This updates the heap management library, umm_malloc, to the current …
mhightower83 Sep 30, 2019
7e859c5
This updates the heap management library, umm_malloc, to the current …
mhightower83 Sep 30, 2019
2d26ccb
Updated upstream TODO
mhightower83 Oct 1, 2019
eed4b99
Merge branch 'WIP-upstream-umm_malloc' of github.com:mhightower83/Ard…
mhightower83 Oct 1, 2019
966812a
Changes on printing to comply with new understanding of SPI bus avail…
mhightower83 Oct 1, 2019
3669bf5
Removed no longer needed files.
mhightower83 Oct 1, 2019
be66ae7
OOM build option now saves file and line number for post mortem repor…
mhightower83 Oct 2, 2019
917e723
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Oct 2, 2019
503def2
Merge branch 'WIP-upstream-umm_malloc' of github.com:mhightower83/Ard…
mhightower83 Oct 2, 2019
3b80577
Missed change.
mhightower83 Oct 5, 2019
2507ced
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Oct 10, 2019
46b61fb
Consolated upstream integration comments into Notes.h. This helps
mhightower83 Oct 10, 2019
e9401c7
Comment updates.
mhightower83 Oct 10, 2019
648c028
Notes update.
mhightower83 Oct 10, 2019
3475ba2
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Oct 17, 2019
435b8a6
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Oct 23, 2019
eb5a7ca
Changes to heap.cpp -
mhightower83 Oct 24, 2019
3c77efe
Corrected Full Poison Check's placement and documented the
mhightower83 Oct 24, 2019
9da7eb8
Merge branch 'master' into WIP-upstream-umm_malloc
mhightower83 Oct 28, 2019
0eaa613
Fixed typos
mhightower83 Oct 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 150 additions & 93 deletions cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,116 @@
#include <c_types.h>
#include <sys/reent.h>


extern "C" {

#if defined( UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE)
#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) umm_poison_realloc_fl(p,s,f,l)
#define __umm_free_fl(p,f,l) umm_poison_free_fl(p,f,l)

#ifdef UMM_POISON_CHECK_LITE
#define POISON_CHECK__ABORT() do {} while(0)
#define POISON_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)

#else // Full heap poison check at every malloc libary call.
#define POISON_CHECK__ABORT() \
do { \
if ( ! POISON_CHECK() ) \
abort(); \
} while(0)

#define POISON_CHECK__PANIC_FL(file, line) \
do { \
if ( ! POISON_CHECK() ) \
__panic_func(file, line, ""); \
} while(0)
#endif

#undef realloc
#undef free

#else // ! UMM_POISON_CHECK
#define __umm_malloc(s) malloc(s)
#define __umm_calloc(n,s) calloc(n,s)
#define __umm_realloc_fl(p,s,f,l) realloc(p,s)
#define __umm_free_fl(p,f,l) free(p)

#define POISON_CHECK__ABORT() do {} while(0)
#define POISON_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)
#endif // UMM_POISON_CHECK

// Debugging helper, last allocation which returned NULL
void *umm_last_fail_alloc_addr = NULL;
int umm_last_fail_alloc_size = 0;


#ifdef UMM_INTEGRITY_CHECK
#define INTEGRITY_CHECK__ABORT() \
do { \
if ( ! INTEGRITY_CHECK() ) \
abort(); \
} while(0)

#define INTEGRITY_CHECK__PANIC_FL(file, line) \
do { \
if ( ! INTEGRITY_CHECK() ) \
__panic_func(file, line, ""); \
} while(0)

#else // ! UMM_INTEGRITY_CHECK
#define INTEGRITY_CHECK__ABORT() do {} while(0)
#define INTEGRITY_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)

#endif // UMM_INTEGRITY_CHECK

#define PTR_CHECK__LOG_LAST_FAIL(p, s, a) \
if(0 != (s) && 0 == p)\
{\
umm_last_fail_alloc_addr = a;\
umm_last_fail_alloc_size = s;\
}

void* _malloc_r(struct _reent* unused, size_t size)
{
(void) unused;
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0))
return ret;
}

void _free_r(struct _reent* unused, void* ptr)
{
(void) unused;
return free(ptr);
free(ptr);
}

void* _realloc_r(struct _reent* unused, void* ptr, size_t size)
{
(void) unused;
void *ret = realloc(ptr, size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0))
return ret;
}

void* _calloc_r(struct _reent* unused, size_t count, size_t size)
{
(void) unused;
void *ret = calloc(count, size);
if (0 != (count * size) && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = count * size;
}
PTR_CHECK__LOG_LAST_FAIL(ret, count * size, __builtin_return_address(0))
return ret;
}

void ICACHE_RAM_ATTR vPortFree(void *ptr, const char* file, int line)
{
(void) file;
(void) line;
free(ptr);
}

#ifdef DEBUG_ESP_OOM

void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
{
return malloc_loc(size, file, line);
}

void* ICACHE_RAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
{
return calloc_loc(count, size, file, line);
}

void* ICACHE_RAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
{
return realloc_loc(ptr, size, file, line);
}

void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
{
return calloc_loc(1, size, file, line);
}
#define PTR_CHECK__LOG_LAST_FAIL(p, s, a) \
if(0 != (s) && 0 == p)\
{\
umm_last_fail_alloc_addr = a;\
umm_last_fail_alloc_size = s;\
}

#ifdef DEBUG_ESP_OOM
#undef malloc
#undef calloc
#undef realloc
Expand All @@ -90,96 +126,117 @@ static const char oom_fmt[] PROGMEM STORE_ATTR = ":oom(%d)@?\n";
static const char oom_fmt_1[] PROGMEM STORE_ATTR = ":oom(%d)@";
static const char oom_fmt_2[] PROGMEM STORE_ATTR = ":%d\n";

void* malloc (size_t s)
void ICACHE_RAM_ATTR print_loc(size_t size, const char* file, int line)
{
void* ret = umm_malloc(s);
if (!ret)
os_printf(oom_fmt, (int)s);
return ret;
if (system_get_os_print()) {
DBGLOG_FUNCTION_P(oom_fmt_1, (int)size);
mhightower83 marked this conversation as resolved.
Show resolved Hide resolved
DBGLOG_FUNCTION_P(file);
DBGLOG_FUNCTION_P(oom_fmt_2, line);
}
}

void* calloc (size_t n, size_t s)
{
void* ret = umm_calloc(n, s);
if (!ret)
os_printf(oom_fmt, (int)s);
return ret;
}
#define OOM_CHECK__PRINT_OOM(p, f, s) if (!p && system_get_os_print()) DBGLOG_FUNCTION_P(f, s)
#define OOM_CHECK__PRINT_LOC(p, s, f, l) if (!p) print_loc(s, f, l)

void* realloc (void* p, size_t s)
{
void* ret = umm_realloc(p, s);
if (!ret)
os_printf(oom_fmt, (int)s);
return ret;
}
#else // ! DEBUG_ESP_OOM

#if 1
//C Skip OOM check of pvPort... . It cost 64 more bytes of IRAM to turn on.
//C Was not previously enabled.
#undef PTR_CHECK__LOG_LAST_FAIL
#define PTR_CHECK__LOG_LAST_FAIL(p, s, a)
#endif

void print_loc (size_t s, const char* file, int line)
#define OOM_CHECK__PRINT_OOM(p, f, s)
#define OOM_CHECK__PRINT_LOC(p, s, f, l)
#endif

#if defined(DEBUG_ESP_OOM) || defined(UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE) || defined(UMM_INTEGRITY_CHECK)

void* ICACHE_RAM_ATTR malloc(size_t size)
{
os_printf(oom_fmt_1, (int)s);
os_printf(file);
os_printf(oom_fmt_2, line);
INTEGRITY_CHECK__ABORT();
POISON_CHECK__ABORT();
void* ret = __umm_malloc(size);
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0));
OOM_CHECK__PRINT_OOM(ret, oom_fmt, (int)size);
return ret;
}

void* malloc_loc (size_t s, const char* file, int line)
void* ICACHE_RAM_ATTR calloc(size_t count, size_t size)
{
void* ret = umm_malloc(s);
if (!ret)
print_loc(s, file, line);
INTEGRITY_CHECK__ABORT();
POISON_CHECK__ABORT();
void* ret = __umm_calloc(count, size);
PTR_CHECK__LOG_LAST_FAIL(ret, count * size, __builtin_return_address(0));
OOM_CHECK__PRINT_OOM(ret, oom_fmt, (int)size);
return ret;
}

void* calloc_loc (size_t n, size_t s, const char* file, int line)
void* ICACHE_RAM_ATTR realloc(void* ptr, size_t size)
{
void* ret = umm_calloc(n, s);
if (!ret)
print_loc(s, file, line);
INTEGRITY_CHECK__ABORT();
void* ret = __umm_realloc_fl(ptr, size, NULL, 0);
POISON_CHECK__ABORT();
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0));
OOM_CHECK__PRINT_OOM(ret, oom_fmt, (int)size);
return ret;
}

void* realloc_loc (void* p, size_t s, const char* file, int line)
void ICACHE_RAM_ATTR free(void* p)
{
void* ret = umm_realloc(p, s);
if (!ret)
print_loc(s, file, line);
return ret;
INTEGRITY_CHECK__ABORT();
__umm_free_fl(p, NULL, 0);
POISON_CHECK__ABORT();
}
#endif

#else

void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
{
(void) file;
(void) line;
return malloc(size);
INTEGRITY_CHECK__PANIC_FL(file, line);
POISON_CHECK__PANIC_FL(file, line);
void* ret = __umm_malloc(size);
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0));
OOM_CHECK__PRINT_LOC(ret, size, file, line);
return ret;
}

void* ICACHE_RAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
{
(void) file;
(void) line;
return calloc(count, size);
INTEGRITY_CHECK__PANIC_FL(file, line);
POISON_CHECK__PANIC_FL(file, line);
void* ret = __umm_calloc(count, size);
PTR_CHECK__LOG_LAST_FAIL(ret, count * size, __builtin_return_address(0));
OOM_CHECK__PRINT_LOC(ret, size, file, line);
return ret;
}

void* ICACHE_RAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
{
(void) file;
(void) line;
return realloc(ptr, size);
INTEGRITY_CHECK__PANIC_FL(file, line);
void* ret = __umm_realloc_fl(ptr, size, file, line);
POISON_CHECK__PANIC_FL(file, line);
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0));
OOM_CHECK__PRINT_LOC(ret, size, file, line);
return ret;
}

void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
{
(void) file;
(void) line;
return calloc(1, size);
INTEGRITY_CHECK__PANIC_FL(file, line);
POISON_CHECK__PANIC_FL(file, line);
void* ret = __umm_calloc(1, size);
PTR_CHECK__LOG_LAST_FAIL(ret, size, __builtin_return_address(0));
OOM_CHECK__PRINT_LOC(ret, size, file, line);
return ret;
}

#endif // !defined(DEBUG_ESP_OOM)

size_t xPortGetFreeHeapSize(void)
void ICACHE_RAM_ATTR vPortFree(void *ptr, const char* file, int line)
{
return umm_free_heap_size();
INTEGRITY_CHECK__PANIC_FL(file, line);
POISON_CHECK__PANIC_FL(file, line);
__umm_free_fl(ptr, file, line);
}

size_t ICACHE_RAM_ATTR xPortWantedSizeAlign(size_t size)
Expand Down
Loading