Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include <stdlib.h>
#include <sys/reent.h>
#include <errno.h>
#include <malloc.h>
#include "esp_heap_caps.h"
malloc(size_t)
calloc(size_t, size_t)
realloc(void *, size_t)
free(void *)
_malloc_r(struct _reent *, size_t)
_free_r(struct _reent *, void *)
_realloc_r(struct _reent *, void *, size_t)
_calloc_r(struct _reent *, size_t, size_t)
memalign(size_t, size_t)
aligned_alloc(size_t, size_t)
posix_memalign(void **, size_t, size_t)
newlib_include_heap_impl()
malloc_trim(size_t)
malloc_usable_size(void *)
malloc_stats()
mallopt(int, int)
mallinfo()
valloc(size_t)
pvalloc(size_t)
cfree(void *)
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/newlib/heap.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include <stdlib.h> #include <sys/reent.h> #include <errno.h> #include <malloc.h> #include "esp_heap_caps.h"6 includes /* These contain the business logic for the malloc() and realloc() implementation. Because of heap tracing wrapping reasons, we do not want these to be a public api, however, so they're not defined publicly. *//* ... */ extern void *heap_caps_malloc_default(size_t size); extern void *heap_caps_realloc_default(void *ptr, size_t size); extern void *heap_caps_aligned_alloc_default(size_t alignment, size_t size); void* malloc(size_t size) { return heap_caps_malloc_default(size); }{ ... } void* calloc(size_t n, size_t size) { return _calloc_r(_REENT, n, size); }{ ... } void* realloc(void* ptr, size_t size) { return heap_caps_realloc_default(ptr, size); }{ ... } void free(void *ptr) { heap_caps_free(ptr); }{ ... } void* _malloc_r(struct _reent *r, size_t size) { return heap_caps_malloc_default(size); }{ ... } void _free_r(struct _reent *r, void* ptr) { heap_caps_free(ptr); }{ ... } void* _realloc_r(struct _reent *r, void* ptr, size_t size) { return heap_caps_realloc_default(ptr, size); }{ ... } void* _calloc_r(struct _reent *r, size_t nmemb, size_t size) { void *result; size_t size_bytes; if (__builtin_mul_overflow(nmemb, size, &size_bytes)) { return NULL; }{...} result = heap_caps_malloc_default(size_bytes); if (result != NULL) { bzero(result, size_bytes); }{...} return result; }{ ... } void* memalign(size_t alignment, size_t n) { return heap_caps_aligned_alloc_default(alignment, n); }{ ... } void* aligned_alloc(size_t alignment, size_t n) { return heap_caps_aligned_alloc_default(alignment, n); }{ ... } int posix_memalign(void **out_ptr, size_t alignment, size_t size) { if (size == 0) { /* returning NULL for zero size is allowed, don't treat this as an error */ *out_ptr = NULL; return 0; }{...} void *result = heap_caps_aligned_alloc_default(alignment, size); if (result != NULL) { /* Modify output pointer only on success */ *out_ptr = result; return 0; }{...} /* Note: error returned, not set via errno! */ return ENOMEM; }{ ... } /* No-op function, used to force linking this file, instead of the heap implementation from newlib. *//* ... */ void newlib_include_heap_impl(void) { }{ ... } /* The following functions are implemented by newlib's heap allocator, but aren't available in the heap component. Define them as non-functional stubs here, so that the application can not cause the newlib heap implementation to be linked in *//* ... */ int malloc_trim(size_t pad) { return 0; // indicates failure }{ ... } size_t malloc_usable_size(void* p) { return 0; }{ ... } void malloc_stats(void) { }{ ... } int mallopt(int parameter_number, int parameter_value) { return 0; // indicates failure }{ ... } struct mallinfo mallinfo(void) { struct mallinfo dummy = {0}; return dummy; }{...} void* valloc(size_t n) __attribute__((alias("malloc"))); void* pvalloc(size_t n) __attribute__((alias("malloc"))); void cfree(void* p) __attribute__((alias("free")));
Details