@@ -207,26 +207,46 @@ extern "C" void * __wrap__memalign_r(struct _reent * r, size_t alignment, size_t
207
207
208
208
209
209
/* *****************************************************************************/
210
- /* ARMCC memory allocation wrappers */
210
+ /* ARMCC / IAR memory allocation wrappers */
211
211
/* *****************************************************************************/
212
212
213
- #elif defined(TOOLCHAIN_ARM) // #if defined(TOOLCHAIN_GCC)
213
+ #elif defined(TOOLCHAIN_ARM) || defined(__ICCARM__)
214
+
215
+ #if defined(TOOLCHAIN_ARM)
216
+ #define SUPER_MALLOC $Super$$malloc
217
+ #define SUB_MALLOC $Sub$$malloc
218
+ #define SUPER_REALLOC $Super$$realloc
219
+ #define SUB_REALLOC $Sub$$realloc
220
+ #define SUPER_CALLOC $Super$$calloc
221
+ #define SUB_CALLOC $Sub$$calloc
222
+ #define SUPER_FREE $Super$$free
223
+ #define SUB_FREE $Sub$$free
224
+ #elif defined(__ICCARM__)
225
+ #define SUPER_MALLOC $Super$$__iar_dlmalloc
226
+ #define SUB_MALLOC $Sub$$__iar_dlmalloc
227
+ #define SUPER_REALLOC $Super$$__iar_dlrealloc
228
+ #define SUB_REALLOC $Sub$$__iar_dlrealloc
229
+ #define SUPER_CALLOC $Super$$__iar_dlcalloc
230
+ #define SUB_CALLOC $Sub$$__iar_dlcalloc
231
+ #define SUPER_FREE $Super$$__iar_dlfree
232
+ #define SUB_FREE $Sub$$__iar_dlfree
233
+ #endif
214
234
215
235
/* Enable hooking of memory function only if tracing is also enabled */
216
236
#if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
217
237
218
238
extern " C" {
219
- void *$Super$$malloc (size_t size);
220
- void *$Super$$realloc (void *ptr, size_t size);
221
- void *$Super$$calloc (size_t nmemb, size_t size);
222
- void $Super$$free (void *ptr);
239
+ void *SUPER_MALLOC (size_t size);
240
+ void *SUPER_REALLOC (void *ptr, size_t size);
241
+ void *SUPER_CALLOC (size_t nmemb, size_t size);
242
+ void SUPER_FREE (void *ptr);
223
243
}
224
244
225
- extern " C" void * $Sub$$malloc (size_t size) {
245
+ extern " C" void * SUB_MALLOC (size_t size) {
226
246
void *ptr = NULL ;
227
247
#ifdef MBED_HEAP_STATS_ENABLED
228
248
malloc_stats_mutex->lock ();
229
- alloc_info_t *alloc_info = (alloc_info_t *)$Super$$ malloc (size + sizeof (alloc_info_t ));
249
+ alloc_info_t *alloc_info = (alloc_info_t *)SUPER_MALLOC (size + sizeof (alloc_info_t ));
230
250
if (alloc_info != NULL ) {
231
251
alloc_info->size = size;
232
252
ptr = (void *)(alloc_info + 1 );
@@ -241,7 +261,7 @@ extern "C" void* $Sub$$malloc(size_t size) {
241
261
}
242
262
malloc_stats_mutex->unlock ();
243
263
#else // #ifdef MBED_HEAP_STATS_ENABLED
244
- ptr = $Super$$ malloc (size);
264
+ ptr = SUPER_MALLOC (size);
245
265
#endif // #ifdef MBED_HEAP_STATS_ENABLED
246
266
#ifdef MBED_MEM_TRACING_ENABLED
247
267
mem_trace_mutex->lock ();
@@ -251,7 +271,7 @@ extern "C" void* $Sub$$malloc(size_t size) {
251
271
return ptr;
252
272
}
253
273
254
- extern " C" void * $Sub$$realloc (void *ptr, size_t size) {
274
+ extern " C" void * SUB_REALLOC (void *ptr, size_t size) {
255
275
void *new_ptr = NULL ;
256
276
#ifdef MBED_HEAP_STATS_ENABLED
257
277
// Note - no lock needed since malloc and free are thread safe
@@ -276,7 +296,7 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
276
296
free (ptr);
277
297
}
278
298
#else // #ifdef MBED_HEAP_STATS_ENABLED
279
- new_ptr = $Super$$ realloc (ptr, size);
299
+ new_ptr = SUPER_REALLOC (ptr, size);
280
300
#endif // #ifdef MBED_HEAP_STATS_ENABLED
281
301
#ifdef MBED_MEM_TRACING_ENABLED
282
302
mem_trace_mutex->lock ();
@@ -286,7 +306,7 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
286
306
return new_ptr;
287
307
}
288
308
289
- extern " C" void *$Sub$$calloc (size_t nmemb, size_t size) {
309
+ extern " C" void *SUB_CALLOC (size_t nmemb, size_t size) {
290
310
void *ptr = NULL ;
291
311
#ifdef MBED_HEAP_STATS_ENABLED
292
312
// Note - no lock needed since malloc is thread safe
@@ -295,7 +315,7 @@ extern "C" void *$Sub$$calloc(size_t nmemb, size_t size) {
295
315
memset (ptr, 0 , nmemb * size);
296
316
}
297
317
#else // #ifdef MBED_HEAP_STATS_ENABLED
298
- ptr = $Super$$ calloc (nmemb, size);
318
+ ptr = SUPER_CALLOC (nmemb, size);
299
319
#endif // #ifdef MBED_HEAP_STATS_ENABLED
300
320
#ifdef MBED_MEM_TRACING_ENABLED
301
321
mem_trace_mutex->lock ();
@@ -305,7 +325,7 @@ extern "C" void *$Sub$$calloc(size_t nmemb, size_t size) {
305
325
return ptr;
306
326
}
307
327
308
- extern " C" void $Sub$$free (void *ptr) {
328
+ extern " C" void SUB_FREE (void *ptr) {
309
329
#ifdef MBED_HEAP_STATS_ENABLED
310
330
malloc_stats_mutex->lock ();
311
331
alloc_info_t *alloc_info = NULL ;
@@ -314,10 +334,10 @@ extern "C" void $Sub$$free(void *ptr) {
314
334
heap_stats.current_size -= alloc_info->size ;
315
335
heap_stats.alloc_cnt -= 1 ;
316
336
}
317
- $Super$$ free ((void *)alloc_info);
337
+ SUPER_FREE ((void *)alloc_info);
318
338
malloc_stats_mutex->unlock ();
319
339
#else // #ifdef MBED_HEAP_STATS_ENABLED
320
- $Super$$ free (ptr);
340
+ SUPER_FREE (ptr);
321
341
#endif // #ifdef MBED_HEAP_STATS_ENABLED
322
342
#ifdef MBED_MEM_TRACING_ENABLED
323
343
mem_trace_mutex->lock ();
@@ -332,15 +352,14 @@ extern "C" void $Sub$$free(void *ptr) {
332
352
/* Allocation wrappers for other toolchains are not supported yet */
333
353
/* *****************************************************************************/
334
354
335
- #else // #if defined(TOOLCHAIN_GCC)
355
+ #else
336
356
337
357
#ifdef MBED_MEM_TRACING_ENABLED
338
- #warning Memory tracing is not supported with the current toolchain.
358
+ #error Memory tracing is not supported with the current toolchain.
339
359
#endif
340
360
341
361
#ifdef MBED_HEAP_STATS_ENABLED
342
- #warning Heap statistics are not supported with the current toolchain.
362
+ #error Heap statistics are not supported with the current toolchain.
343
363
#endif
344
364
345
365
#endif // #if defined(TOOLCHAIN_GCC)
346
-
0 commit comments