Skip to content

Commit

Permalink
Resolved issue where OOM selected w/ Debug port: "Disabled" caused hang.
Browse files Browse the repository at this point in the history
With OOM selected w/ Debug port: "Disabled" you can now use
Serial.setDebugOutput(true); to enable OOM message displaying.
This is the behavior previously available with os_printf.

commit rev 1
  • Loading branch information
mhightower83 committed Sep 8, 2019
1 parent 2a1923e commit f68a64f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
61 changes: 31 additions & 30 deletions cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,53 @@
#include "umm_malloc/umm_malloc.h"
#include <c_types.h>
#include <sys/reent.h>

#include <user_interface.h>

extern "C" {

#if defined( UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE)
#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)
#undef realloc
#undef free

#define POISON_CHECK__PANIC_FL(file, line) \
do { \
if ( ! POISON_CHECK() ) \
__panic_func(file, line, ""); \
} while(0)
#endif
#elif defined(DEBUG_ESP_OOM)
#define __umm_malloc(s) umm_malloc(s)
#define __umm_calloc(n,s) umm_calloc(n,s)
#define __umm_realloc_fl(p,s,f,l) umm_realloc(p,s)
#define __umm_free_fl(p,f,l) umm_free(p)

#undef realloc
#undef free

#else // ! UMM_POISON_CHECK
#else // ! UMM_POISON_CHECK && ! DEBUG_ESP_OOM
#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)
#endif

#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

#if defined(UMM_POISON_CHECK)
#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)

#else // No full heap poison checking.
#define POISON_CHECK__ABORT() do {} while(0)
#define POISON_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)
#endif

// Debugging helper, last allocation which returned NULL
void *umm_last_fail_alloc_addr = NULL;
Expand Down Expand Up @@ -109,14 +116,6 @@ void* _calloc_r(struct _reent* unused, size_t count, size_t size)
return ret;
}


#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
Expand All @@ -128,6 +127,8 @@ static const char oom_fmt_2[] PROGMEM STORE_ATTR = ":%d\n";

void ICACHE_RAM_ATTR print_loc(size_t size, const char* file, int line)
{
(void)size;
(void)line;
if (system_get_os_print()) {
DBGLOG_FUNCTION_P(oom_fmt_1, (int)size);
DBGLOG_FUNCTION_P(file);
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/umm_malloc/isr_safe_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include <string.h>
#include <pgmspace.h>
#include <core_esp8266_features.h>

#include "umm_malloc_cfg.h"
extern "C" {

#if defined(DEBUG_ESP_PORT) || defined(DEBUG_ESP_OOM) || defined(UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE)
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/umm_malloc/umm_malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ void *umm_realloc( void *ptr, size_t size ) {
} else if ((blockSize + nextBlockSize) >= blocks) { // 3
DBGLOG_DEBUG( "realloc using next block - %d\n", blocks );
umm_assimilate_up( c );
STATS__FREE_BLOCKS_UPDATE(-nextBlockSize);
STATS__FREE_BLOCKS_UPDATE( - nextBlockSize );
blockSize += nextBlockSize;
} else { // 4
DBGLOG_DEBUG( "realloc a completely new block %d\n", blocks );
Expand Down
1 change: 0 additions & 1 deletion cores/esp8266/umm_malloc/umm_malloc_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ int _isr_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)
#define DBGLOG_FUNCTION(fmt, ...) printf(PSTR(fmt), ##__VA_ARGS__)
#define DBGLOG_FUNCTION_P(fmt, ...) printf_P(fmt, ##__VA_ARGS__)
#endif

//C What about printing from umm_info - does it need to be ISR safe

/////////////////////////////////////////////////
Expand Down

0 comments on commit f68a64f

Please sign in to comment.