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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* Configuration for umm_malloc - DO NOT EDIT THIS FILE BY HAND!
*
* NOTE WELL: Your project MUST have a umm_malloc_cfgport.h - even if
* it's empty!!!
*
* Refer to the notes below for details on the umm_malloc configuration
* options.
*/
/*
* There are a number of defines you can set at compile time that affect how
* the memory allocator will operate.
*
* You should NOT edit this file, it may be changed from time to time in
* the upstream project. Instead, you can do one of the following (in order
* of priority
*
* 1. Pass in the override values on the command line using -D UMM_xxx
* 2. Pass in the filename holding override values using -D UMM_CFGFILE
* 3. Set up defaults in a file called umm_malloc_cfgport.h
*
* NOTE WELL: For the command line -D options to take highest priority, your
* project level override file must check that the UMM_xxx
* value is not already defined before overriding
*
* Unless otherwise noted, the default state of these values is #undef-ined!
*
* As this is the top level configuration file, it is responsible for making
* sure that the configuration makes sense. For example the UMM_BLOCK_BODY_SIZE
* is a minimum of 8 and a multiple of 4.
*
* UMM_BLOCK_BODY_SIZE
*
* Defines the umm_block[].body size - it is 8 by default
*
* This assumes umm_ptr is a pair of uint16_t values
* which is 4 bytes plus the data[] array which is another 4 bytes
* for a total of 8.
*
* NOTE WELL that the umm_block[].body size must be multiple of
* the natural access size of the host machine to ensure
* that accesses are efficient.
*
* We have not verified the checks below for 64 bit machines
* because this library is targeted for 32 bit machines.
*
* UMM_NUM_HEAPS
*
* Set to the maximum number of heaps that can be defined by the
* application - defaults to 1.
*
* UMM_BEST_FIT (default)
*
* Set this if you want to use a best-fit algorithm for allocating new blocks.
* On by default, turned off by UMM_FIRST_FIT
*
* UMM_FIRST_FIT
*
* Set this if you want to use a first-fit algorithm for allocating new blocks.
* Faster than UMM_BEST_FIT but can result in higher fragmentation.
*
* UMM_INFO
*
* Set if you want the ability to calculate metrics on demand
*
* UMM_INLINE_METRICS
*
* Set this if you want to have access to a minimal set of heap metrics that
* can be used to gauge heap health.
* Setting this at compile time will automatically set UMM_INFO.
* Note that enabling this define will add a slight runtime penalty.
*
* UMM_CHECK_INITIALIZED
*
* Set if you want to be able to verify that the heap is intialized
* before any operation - the default is no check. You may set the
* UMM_CHECK_INITIALIZED macro to the following provided macros, or
* write your own handler:
*
* UMM_INIT_IF_UNINITIALIZED
* UMM_HANG_IF_UNINITIALIZED
*
* UMM_INTEGRITY_CHECK
*
* Set if you want to be able to verify that the heap is semantically correct
* before or after any heap operation - all of the block indexes in the heap
* make sense.
* Slows execution dramatically but catches errors really quickly.
*
* UMM_POISON_CHECK
*
* Set if you want to be able to leave a poison buffer around each allocation.
* Note this uses an extra 8 bytes per allocation, but you get the benefit of
* being able to detect if your program is writing past an allocated buffer.
*
* DBGLOG_ENABLE
*
* Set if you want to enable logging - the default is to use printf() but
* if you have any special requirements such as thread safety or a custom
* logging routine - you are free to everride the default
*
* DBGLOG_LEVEL=n
*
* Set n to a value from 0 to 6 depending on how verbose you want the debug
* log to be
*
* UMM_MAX_CRITICAL_DEPTH_CHECK=n
*
* Set this if you want to compile in code to verify that the critical
* section maximum depth is not exceeded. If set, the value must be greater
* than 0.
*
* The critical depth checking is only needed if your target environment
* does not support reading and writing the current interrupt enable state.
*
* Support for this library in a multitasking environment is provided when
* you add bodies to the UMM_CRITICAL_ENTRY and UMM_CRITICAL_EXIT macros
* (see below)
*
* ----------------------------------------------------------------------------
*/
/* A couple of macros to make packing structures less compiler dependent */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
// UMM_INLINE_METRICS
/* -------------------------------------------------------------------------- */
typedef struct UMM_HEAP_INFO_t
UMM_HEAP_INFO;
extern UMM_HEAP_INFO ummHeapInfo;
extern void *;
extern size_t ;
extern size_t ;
extern int ;
extern int ;
/*
* Three macros to make it easier to protect the memory allocator in a
* multitasking system. You should set these macros up to use whatever your
* system uses for this purpose. You can disable interrupts entirely, or just
* disable task switching - it's up to you
*
* If needed, UMM_CRITICAL_DECL can be used to declare or initialize
* synchronization elements before their use. "tag" can be used to add context
* uniqueness to the declaration.
* exp. #define UMM_CRITICAL_DECL(tag) uint32_t _saved_ps_##tag
* Another possible use for "tag", activity identifier when profiling time
* spent in UMM_CRITICAL. The "tag" values used are id_malloc, id_realloc,
* id_free, id_poison, id_integrity, and id_info.
*
* NOTE WELL that these macros MUST be allowed to nest, because umm_free() is
* called from within umm_malloc()
*/
extern int umm_critical_depth;
extern int umm_max_critical_depth;
/*
* Enables heap integrity check before any heap operation. It affects
* performance, but does NOT consume extra memory.
*
* If integrity violation is detected, the message is printed and user-provided
* callback is called: `UMM_HEAP_CORRUPTION_CB()`
*
* Note that not all buffer overruns are detected: each buffer is aligned by
* 4 bytes, so there might be some trailing "extra" bytes which are not checked
* for corruption.
*/
extern bool ;
extern void ;
/*
* Enables heap poisoning: add predefined value (poison) before and after each
* allocation, and check before each heap operation that no poison is
* corrupted.
*
* Other than the poison itself, we need to store exact user-requested length
* for each buffer, so that overrun by just 1 byte will be always noticed.
*
* Customizations:
*
* UMM_POISON_SIZE_BEFORE:
* Number of poison bytes before each block, e.g. 4
* UMM_POISON_SIZE_AFTER:
* Number of poison bytes after each block e.g. 4
* UMM_POISONED_BLOCK_LEN_TYPE
* Type of the exact buffer length, e.g. `uint16_t`
*
* NOTE: each allocated buffer is aligned by 4 bytes. But when poisoning is
* enabled, actual pointer returned to user is shifted by
* `(sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE)`.
*
* It's your responsibility to make resulting pointers aligned appropriately.
*
* If poison corruption is detected, the message is printed and user-provided
* callback is called: `UMM_HEAP_CORRUPTION_CB()`
*/
extern void *;
extern void *;
extern void *;
extern void ;
extern bool ;
/*
* Add blank macros for DBGLOG_xxx() - if you want to override these on
* a per-source module basis, you must define DBGLOG_LEVEL and then
* #include "dbglog.h"
*/
/* _UMM_MALLOC_CFG_H */