5
5
6
6
#include < stdlib.h>
7
7
#include " umm_malloc/umm_malloc.h"
8
+
9
+ // Need FORCE_ALWAYS_INLINE to put HeapSelect class constructor/deconstructor in IRAM
10
+ #define FORCE_ALWAYS_INLINE_HEAP_SELECT
11
+ #include " umm_malloc/umm_heap_select.h"
12
+
8
13
#include < c_types.h>
9
14
#include < sys/reent.h>
10
15
#include < user_interface.h>
@@ -16,6 +21,7 @@ extern "C" {
16
21
#define UMM_CALLOC (n,s ) umm_poison_calloc(n,s)
17
22
#define UMM_REALLOC_FL (p,s,f,l ) umm_poison_realloc_fl(p,s,f,l)
18
23
#define UMM_FREE_FL (p,f,l ) umm_poison_free_fl(p,f,l)
24
+ #define STATIC_ALWAYS_INLINE
19
25
20
26
#undef realloc
21
27
#undef free
@@ -25,6 +31,7 @@ extern "C" {
25
31
#define UMM_CALLOC (n,s ) umm_calloc(n,s)
26
32
#define UMM_REALLOC_FL (p,s,f,l ) umm_realloc(p,s)
27
33
#define UMM_FREE_FL (p,f,l ) umm_free(p)
34
+ #define STATIC_ALWAYS_INLINE
28
35
29
36
#undef realloc
30
37
#undef free
@@ -34,6 +41,10 @@ extern "C" {
34
41
#define UMM_CALLOC (n,s ) calloc(n,s)
35
42
#define UMM_REALLOC_FL (p,s,f,l ) realloc(p,s)
36
43
#define UMM_FREE_FL (p,f,l ) free(p)
44
+
45
+ // STATIC_ALWAYS_INLINE only applys to the non-debug build path,
46
+ // it must not be enabled on the debug build path.
47
+ #define STATIC_ALWAYS_INLINE static ALWAYS_INLINE
37
48
#endif
38
49
39
50
@@ -259,8 +270,8 @@ void ICACHE_RAM_ATTR free(void* p)
259
270
}
260
271
#endif
261
272
262
-
263
- void * ICACHE_RAM_ATTR pvPortMalloc (size_t size, const char * file, int line)
273
+ STATIC_ALWAYS_INLINE
274
+ void * ICACHE_RAM_ATTR heap_pvPortMalloc (size_t size, const char * file, int line)
264
275
{
265
276
INTEGRITY_CHECK__PANIC_FL (file, line);
266
277
POISON_CHECK__PANIC_FL (file, line);
@@ -270,7 +281,8 @@ void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
270
281
return ret;
271
282
}
272
283
273
- void * ICACHE_RAM_ATTR pvPortCalloc (size_t count, size_t size, const char * file, int line)
284
+ STATIC_ALWAYS_INLINE
285
+ void * ICACHE_RAM_ATTR heap_pvPortCalloc (size_t count, size_t size, const char * file, int line)
274
286
{
275
287
INTEGRITY_CHECK__PANIC_FL (file, line);
276
288
POISON_CHECK__PANIC_FL (file, line);
@@ -280,7 +292,8 @@ void* ICACHE_RAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file,
280
292
return ret;
281
293
}
282
294
283
- void * ICACHE_RAM_ATTR pvPortRealloc (void *ptr, size_t size, const char * file, int line)
295
+ STATIC_ALWAYS_INLINE
296
+ void * ICACHE_RAM_ATTR heap_pvPortRealloc (void *ptr, size_t size, const char * file, int line)
284
297
{
285
298
INTEGRITY_CHECK__PANIC_FL (file, line);
286
299
void * ret = UMM_REALLOC_FL (ptr, size, file, line);
@@ -290,7 +303,8 @@ void* ICACHE_RAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, in
290
303
return ret;
291
304
}
292
305
293
- void * ICACHE_RAM_ATTR pvPortZalloc (size_t size, const char * file, int line)
306
+ STATIC_ALWAYS_INLINE
307
+ void * ICACHE_RAM_ATTR heap_pvPortZalloc (size_t size, const char * file, int line)
294
308
{
295
309
INTEGRITY_CHECK__PANIC_FL (file, line);
296
310
POISON_CHECK__PANIC_FL (file, line);
@@ -300,7 +314,8 @@ void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
300
314
return ret;
301
315
}
302
316
303
- void ICACHE_RAM_ATTR vPortFree (void *ptr, const char * file, int line)
317
+ STATIC_ALWAYS_INLINE
318
+ void ICACHE_RAM_ATTR heap_vPortFree (void *ptr, const char * file, int line)
304
319
{
305
320
INTEGRITY_CHECK__PANIC_FL (file, line);
306
321
UMM_FREE_FL (ptr, file, line);
@@ -314,7 +329,47 @@ size_t ICACHE_RAM_ATTR xPortWantedSizeAlign(size_t size)
314
329
315
330
void system_show_malloc (void )
316
331
{
332
+ HeapSelectDram ephemeral;
317
333
umm_info (NULL , true );
318
334
}
319
335
336
+ /*
337
+ NONOS SDK and lwIP do not handle IRAM heap well. Since they also use portable
338
+ malloc calls pvPortMalloc, ... we can leverage that for this solution.
339
+ Force pvPortMalloc, ... APIs to serve DRAM only.
340
+ */
341
+ void * ICACHE_RAM_ATTR pvPortMalloc (size_t size, const char * file, int line)
342
+ {
343
+ HeapSelectDram ephemeral;
344
+ return heap_pvPortMalloc (size, file, line);;
345
+ }
346
+
347
+ void * ICACHE_RAM_ATTR pvPortCalloc (size_t count, size_t size, const char * file, int line)
348
+ {
349
+ HeapSelectDram ephemeral;
350
+ return heap_pvPortCalloc (count, size, file, line);
351
+ }
352
+
353
+ void * ICACHE_RAM_ATTR pvPortRealloc (void *ptr, size_t size, const char * file, int line)
354
+ {
355
+ HeapSelectDram ephemeral;
356
+ return heap_pvPortRealloc (ptr, size, file, line);
357
+ }
358
+
359
+ void * ICACHE_RAM_ATTR pvPortZalloc (size_t size, const char * file, int line)
360
+ {
361
+ HeapSelectDram ephemeral;
362
+ return heap_pvPortZalloc (size, file, line);
363
+ }
364
+
365
+ void ICACHE_RAM_ATTR vPortFree (void *ptr, const char * file, int line)
366
+ {
367
+ #if defined(DEBUG_ESP_OOM) || defined(UMM_POISON_CHECK) || defined(UMM_POISON_CHECK_LITE) || defined(UMM_INTEGRITY_CHECK)
368
+ // This is only needed for debug checks to ensure they are performed in
369
+ // correct context. umm_malloc free internally determines the correct heap.
370
+ HeapSelectDram ephemeral;
371
+ #endif
372
+ return heap_vPortFree (ptr, file, line);
373
+ }
374
+
320
375
};
0 commit comments