Skip to content

Commit a716193

Browse files
committed
missed items
1 parent 6088147 commit a716193

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

cores/esp8266/heap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ void* _heap_abi_malloc(size_t size, bool unhandled, const void* caller)
609609
#else
610610
void* ret = UMM_MALLOC(size);
611611
// minimum OOM check
612-
bool ok = OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, file, line, caller)
612+
bool ok = OOM_CHECK__LOG_LAST_FAIL_LITE_FL(ret, size, file, line, caller);
613613
#endif
614614
if (!ok && unhandled) {
615615
__unhandled_exception(PSTR("OOM"));

cores/esp8266/heap_cb.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#ifndef HEAP_CB_H
2+
#define HEAP_CB_H
3+
// Experimental debug macros
4+
/*
5+
* HEAP_DEBUG_PROBE_PSFLC_CB - A debug build option. User-defined "C" function
6+
* callback for Heap related failures. It can range from a simple breakpoint to
7+
* a complicated backtrace or other supplemental information. The callback
8+
* context is very restrictive: no Heap calls, no PROGMEM, IRAM code only, no
9+
* flash strings, and limited to ROM-based printf functions (like
10+
* ets_uart_printf(...)).
11+
*
12+
* Example:
13+
* extern "C" void my_user_bp(const char* f, int l, const void* c) {
14+
* (void)f; (void)l; (void)c;
15+
* __asm__ __volatile__("break 1, 0;" ::: "memory");
16+
* }
17+
*
18+
* -DHEAP_DEBUG_PROBE_PSFLC_CB='my_user_bp'
19+
*/
20+
enum heap_api_cb_id {
21+
heap_oom_cb_id = 0,
22+
heap_malloc_cb_id = 1,
23+
heap_calloc_cb_id,
24+
heap_realloc_in_cb_id,
25+
heap_realloc_out_cb_id,
26+
heap_free_cb_id,
27+
heap_abi_malloc_cb_id,
28+
heap_abi_delete_cb_id,
29+
heap_poison_cb_id,
30+
heap_poison_lite_cb_id,
31+
heap_poison_lite_neighbor_cb_id,
32+
heap_poison_lite_addr_cb_id,
33+
heap_integrity_cb_id
34+
};
35+
36+
#if defined(_HEAP_DEBUG_PROBE_PSFLC_CB)
37+
// Set a callback macro
38+
// #define _HEAP_DEBUG_PROBE_PSFLC_CB(id, ptr, size, file, line, caller) ...
39+
40+
#elif defined(HEAP_DEBUG_PROBE_PSFLC_CB)
41+
// Set a callback function
42+
extern "C" void *HEAP_DEBUG_PROBE_PSFLC_CB(heap_api_cb_id id, void *ptr, size_t size, const char* file, int line, const void *caller);
43+
#define _HEAP_DEBUG_PROBE_PSFLC_CB HEAP_DEBUG_PROBE_PSFLC_CB
44+
45+
#else
46+
#define _HEAP_DEBUG_PROBE_PSFLC_CB(i, p, s, f, l, c) ({ (void)i; (void)s; (void)f; (void)l; (void)c; p; })
47+
#endif
48+
49+
50+
#if defined(_HEAP_DEBUG_PROBE_ADD_OVERHEAD)
51+
// Set allocation size adjustment macro
52+
// #define _HEAP_DEBUG_PROBE_ADD_OVERHEAD(id, size) ...
53+
54+
#elif defined(HEAP_DEBUG_PROBE_ADD_OVERHEAD)
55+
// Set allocation size adjustment function
56+
extern "C" size_t HEAP_DEBUG_PROBE_ADD_OVERHEAD(heap_api_cb_id id, size_t size);
57+
#define _HEAP_DEBUG_PROBE_ADD_OVERHEAD HEAP_DEBUG_PROBE_ADD_OVERHEAD
58+
59+
#else
60+
#define _HEAP_DEBUG_PROBE_ADD_OVERHEAD(id, size) (size);
61+
#endif
62+
63+
64+
// #define VOID_PLUS(p, i) ((void*)umm_uadd_sat(((uintptr_t)(p)) + (i) ))
65+
66+
#endif
67+
68+
#if defined(HEAP_DEBUG_PROBE_PSFLC_CB_EXAMPLE) && defined(HEAP_DEBUG_PROBE_PSFLC_CB)
69+
extern "C" {
70+
void *HEAP_DEBUG_PROBE_PSFLC_CB(heap_api_cb_id id, void *ptr, size_t size, const char* file, int line, const void *caller)
71+
{
72+
switch (id) {
73+
// Heap API events for tracking
74+
case heap_malloc_cb_id:
75+
break;
76+
77+
case heap_calloc_cb_id:
78+
break;
79+
80+
case heap_realloc_in_cb_id:
81+
break;
82+
83+
case heap_realloc_out_cb_id:
84+
break;
85+
86+
case heap_free_cb_id:
87+
break;
88+
89+
case heap_abi_malloc_cb_id:
90+
break;
91+
92+
case heap_abi_delete_cb_id:
93+
break;
94+
95+
// Failed Heap events
96+
case heap_poison_cb_id:
97+
break;
98+
99+
case heap_poison_lite_cb_id:
100+
break;
101+
102+
case heap_integrity_cb_id:
103+
break;
104+
105+
case heap_oom_cb_id:
106+
break;
107+
}
108+
return ptr;
109+
}
110+
111+
extern "C" size_t umm_uadd_sat(const size_t a, const size_t b);
112+
const size_t extra_space = 4;
113+
size_t HEAP_DEBUG_PROBE_ADD_OVERHEAD(heap_api_cb_id id, size_t size) {
114+
return umm_uadd_sat(size, extra_space);
115+
}
116+
117+
}
118+
#endif

0 commit comments

Comments
 (0)