Skip to content

Commit f68a64f

Browse files
committed
Resolved issue where OOM selected w/ Debug port: "Disabled" caused hang.
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
1 parent 2a1923e commit f68a64f

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

cores/esp8266/heap.cpp

+31-30
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,53 @@
77
#include "umm_malloc/umm_malloc.h"
88
#include <c_types.h>
99
#include <sys/reent.h>
10-
10+
#include <user_interface.h>
1111

1212
extern "C" {
1313

14-
#if defined( UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE)
14+
#if defined(UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE)
1515
#define __umm_malloc(s) umm_poison_malloc(s)
1616
#define __umm_calloc(n,s) umm_poison_calloc(n,s)
1717
#define __umm_realloc_fl(p,s,f,l) umm_poison_realloc_fl(p,s,f,l)
1818
#define __umm_free_fl(p,f,l) umm_poison_free_fl(p,f,l)
1919

20-
#ifdef UMM_POISON_CHECK_LITE
21-
#define POISON_CHECK__ABORT() do {} while(0)
22-
#define POISON_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)
23-
24-
#else // Full heap poison check at every malloc libary call.
25-
#define POISON_CHECK__ABORT() \
26-
do { \
27-
if ( ! POISON_CHECK() ) \
28-
abort(); \
29-
} while(0)
20+
#undef realloc
21+
#undef free
3022

31-
#define POISON_CHECK__PANIC_FL(file, line) \
32-
do { \
33-
if ( ! POISON_CHECK() ) \
34-
__panic_func(file, line, ""); \
35-
} while(0)
36-
#endif
23+
#elif defined(DEBUG_ESP_OOM)
24+
#define __umm_malloc(s) umm_malloc(s)
25+
#define __umm_calloc(n,s) umm_calloc(n,s)
26+
#define __umm_realloc_fl(p,s,f,l) umm_realloc(p,s)
27+
#define __umm_free_fl(p,f,l) umm_free(p)
3728

3829
#undef realloc
3930
#undef free
4031

41-
#else // ! UMM_POISON_CHECK
32+
#else // ! UMM_POISON_CHECK && ! DEBUG_ESP_OOM
4233
#define __umm_malloc(s) malloc(s)
4334
#define __umm_calloc(n,s) calloc(n,s)
4435
#define __umm_realloc_fl(p,s,f,l) realloc(p,s)
4536
#define __umm_free_fl(p,f,l) free(p)
37+
#endif
4638

47-
#define POISON_CHECK__ABORT() do {} while(0)
48-
#define POISON_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)
49-
#endif // UMM_POISON_CHECK
39+
40+
#if defined(UMM_POISON_CHECK)
41+
#define POISON_CHECK__ABORT() \
42+
do { \
43+
if ( ! POISON_CHECK() ) \
44+
abort(); \
45+
} while(0)
46+
47+
#define POISON_CHECK__PANIC_FL(file, line) \
48+
do { \
49+
if ( ! POISON_CHECK() ) \
50+
__panic_func(file, line, ""); \
51+
} while(0)
52+
53+
#else // No full heap poison checking.
54+
#define POISON_CHECK__ABORT() do {} while(0)
55+
#define POISON_CHECK__PANIC_FL(file, line) do { (void)file; (void)line; } while(0)
56+
#endif
5057

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

112-
113-
#define PTR_CHECK__LOG_LAST_FAIL(p, s, a) \
114-
if(0 != (s) && 0 == p)\
115-
{\
116-
umm_last_fail_alloc_addr = a;\
117-
umm_last_fail_alloc_size = s;\
118-
}
119-
120119
#ifdef DEBUG_ESP_OOM
121120
#undef malloc
122121
#undef calloc
@@ -128,6 +127,8 @@ static const char oom_fmt_2[] PROGMEM STORE_ATTR = ":%d\n";
128127

129128
void ICACHE_RAM_ATTR print_loc(size_t size, const char* file, int line)
130129
{
130+
(void)size;
131+
(void)line;
131132
if (system_get_os_print()) {
132133
DBGLOG_FUNCTION_P(oom_fmt_1, (int)size);
133134
DBGLOG_FUNCTION_P(file);

cores/esp8266/umm_malloc/isr_safe_printf.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#include <string.h>
6262
#include <pgmspace.h>
6363
#include <core_esp8266_features.h>
64-
64+
#include "umm_malloc_cfg.h"
6565
extern "C" {
6666

6767
#if defined(DEBUG_ESP_PORT) || defined(DEBUG_ESP_OOM) || defined(UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE)

cores/esp8266/umm_malloc/umm_malloc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ void *umm_realloc( void *ptr, size_t size ) {
836836
} else if ((blockSize + nextBlockSize) >= blocks) { // 3
837837
DBGLOG_DEBUG( "realloc using next block - %d\n", blocks );
838838
umm_assimilate_up( c );
839-
STATS__FREE_BLOCKS_UPDATE(-nextBlockSize);
839+
STATS__FREE_BLOCKS_UPDATE( - nextBlockSize );
840840
blockSize += nextBlockSize;
841841
} else { // 4
842842
DBGLOG_DEBUG( "realloc a completely new block %d\n", blocks );

cores/esp8266/umm_malloc/umm_malloc_cfg.h

-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ int _isr_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)
551551
#define DBGLOG_FUNCTION(fmt, ...) printf(PSTR(fmt), ##__VA_ARGS__)
552552
#define DBGLOG_FUNCTION_P(fmt, ...) printf_P(fmt, ##__VA_ARGS__)
553553
#endif
554-
555554
//C What about printing from umm_info - does it need to be ISR safe
556555

557556
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)